Skip to content

Commit

Permalink
[Core] Implemented MarkReadedEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
Linwenxuan04 committed Mar 2, 2024
1 parent 85f412b commit 487d541
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Lagrange.Core/Common/Interface/Api/OperationExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,10 @@ public static Task<bool> Like(this BotContext bot, uint targetUin)

public static Task<string?> UploadLongMessage(this BotContext bot, List<MessageChain> chains)
=> bot.ContextCollection.Business.OperationLogic.UploadLongMessage(chains);

public static Task<bool> MarkAsRead(this BotContext bot, MessageChain targetChain)
{
uint timestamp = (uint)(targetChain.Time - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds;
return bot.ContextCollection.Business.OperationLogic.MarkAsRead(targetChain.GroupUin ?? 0, targetChain.Uid, targetChain.Sequence, timestamp);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,11 @@ public async Task<bool> SetFriendRequest(string targetUid, bool accept)
var results = await Collection.Business.SendEvent(multiMsgUploadEvent);
return results.Count != 0 ? ((MultiMsgUploadEvent)results[0]).ResId : null;
}

public async Task<bool> MarkAsRead(uint groupUin, string? targetUid, uint startSequence, uint time)
{
var markAsReadEvent = MarkReadedEvent.Create(groupUin, targetUid, startSequence, time);
var results = await Collection.Business.SendEvent(markAsReadEvent);
return results.Count != 0 && ((MarkReadedEvent)results[0]).ResultCode == 0;
}
}
27 changes: 27 additions & 0 deletions Lagrange.Core/Internal/Event/Message/MarkReadedEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace Lagrange.Core.Internal.Event.Message;

internal class MarkReadedEvent : ProtocolEvent
{
public uint GroupUin { get; }

public string? TargetUid { get; }

public uint StartSequence { get; }

public uint Time { get; }

private MarkReadedEvent(uint groupUin, string? targetUid, uint startSequence, uint time) : base(true)
{
GroupUin = groupUin;
TargetUid = targetUid;
StartSequence = startSequence;
Time = time;
}

private MarkReadedEvent(int resultCode) : base(resultCode) { }

public static MarkReadedEvent Create(uint groupUin, string? targetUid, uint startSequence, uint time) =>
new(groupUin, targetUid, startSequence, time);

public static MarkReadedEvent Result(int resultCode) => new(resultCode);
}
32 changes: 32 additions & 0 deletions Lagrange.Core/Internal/Packets/Message/SsoReadedReport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using ProtoBuf;

namespace Lagrange.Core.Internal.Packets.Message;

/// <summary>
/// trpc.msg.msg_svc.MsgService.SsoReadedReport
/// </summary>
[ProtoContract]
internal class SsoReadedReport
{
[ProtoMember(1)] public SsoReadedReportGroup? Group { get; set; }

[ProtoMember(2)] public SsoReadedReportC2C? C2C { get; set; }
}

[ProtoContract]
internal class SsoReadedReportC2C
{
[ProtoMember(2)] public string? TargetUid { get; set; }

[ProtoMember(3)] public uint Time { get; set; }

[ProtoMember(4)] public uint StartSequence { get; set; }
}

[ProtoContract]
internal class SsoReadedReportGroup
{
[ProtoMember(1)] public uint GroupUin { get; set; }

[ProtoMember(2)] public uint StartSequence { get; set; }
}
46 changes: 46 additions & 0 deletions Lagrange.Core/Internal/Service/Message/MarkReadedService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Lagrange.Core.Common;
using Lagrange.Core.Internal.Event;
using Lagrange.Core.Internal.Event.Message;
using Lagrange.Core.Internal.Packets.Message;
using Lagrange.Core.Utility.Binary;
using Lagrange.Core.Utility.Extension;

namespace Lagrange.Core.Internal.Service.Message;

[EventSubscribe(typeof(MarkReadedEvent))]
[Service("trpc.msg.msg_svc.MsgService.SsoReadedReport")]
internal class MarkReadedService : BaseService<MarkReadedEvent>
{
protected override bool Build(MarkReadedEvent input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out BinaryPacket output, out List<BinaryPacket>? extraPackets)
{
var packet = input.TargetUid == null ? new SsoReadedReport
{
Group = new SsoReadedReportGroup
{
GroupUin = input.GroupUin,
StartSequence = input.StartSequence
}
} : new SsoReadedReport
{
C2C = new SsoReadedReportC2C
{
TargetUid = input.TargetUid,
Time = input.Time,
StartSequence = input.StartSequence
}
};

output = packet.Serialize();
extraPackets = null;
return true;
}

protected override bool Parse(byte[] input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out MarkReadedEvent output, out List<ProtocolEvent>? extraEvents)
{
output = MarkReadedEvent.Result(0);
extraEvents = null;
return true;
}
}

0 comments on commit 487d541

Please sign in to comment.