Skip to content

Commit

Permalink
[All] fix error message id (#614)
Browse files Browse the repository at this point in the history
* [All] fix error message id

* Fix annotation errors

---------

Co-authored-by: DarkCWK <[email protected]>
  • Loading branch information
DarkRRb and DarkRRb authored Sep 28, 2024
1 parent ccbea41 commit d39c1bf
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 138 deletions.
14 changes: 7 additions & 7 deletions Lagrange.Core/Event/EventArg/FriendRecallEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ namespace Lagrange.Core.Event.EventArg;
public class FriendRecallEvent : EventBase
{
public uint FriendUin { get; }
public uint Sequence { get; }

public uint ClientSequence { get; }

public uint Time { get; }

public uint Random { get; }

public string Tip { get; }

public FriendRecallEvent(uint friendUin, uint sequence, uint time, uint random, string tip)
public FriendRecallEvent(uint friendUin, uint clientSequence, uint time, uint random, string tip)
{
FriendUin = friendUin;
Sequence = sequence;
ClientSequence = clientSequence;
Time = time;
Random = random;
Tip = tip;

EventMessage = $"{nameof(FriendRecallEvent)}: {FriendUin} | ({Sequence} | {Time} | {Random} | {Tip})";
EventMessage = $"{nameof(FriendRecallEvent)}: {FriendUin} | ({ClientSequence} | {Time} | {Random} | {Tip})";
}
}
246 changes: 126 additions & 120 deletions Lagrange.Core/Internal/Context/Logic/Implementation/MessagingLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public override async Task Incoming(ProtocolEvent e)
case FriendSysRecallEvent recall:
{
uint fromUin = await Collection.Business.CachingLogic.ResolveUin(null, recall.FromUid) ?? 0;
var recallArgs = new FriendRecallEvent(fromUin, recall.Sequence, recall.Time, recall.Random, recall.Tip);
var recallArgs = new FriendRecallEvent(fromUin, recall.ClientSequence, recall.Time, recall.Random, recall.Tip);
Collection.Invoker.PostEvent(recallArgs);
break;
}
Expand Down Expand Up @@ -259,161 +259,167 @@ public override async Task Outgoing(ProtocolEvent e)

private async Task ResolveIncomingChain(MessageChain chain)
{
foreach (var entity in chain) switch (entity)
foreach (var entity in chain)
{
case FileEntity { FileHash: not null, FileUuid: not null } file: // private
switch (entity)
{
var @event = FileDownloadEvent.Create(file.FileUuid, file.FileHash, chain.Uid, chain.SelfUid);
var results = await Collection.Business.SendEvent(@event);
if (results.Count != 0)
case FileEntity { FileHash: not null, FileUuid: not null } file: // private
{
var result = (FileDownloadEvent)results[0];
file.FileUrl = result.FileUrl;
}
var @event = FileDownloadEvent.Create(file.FileUuid, file.FileHash, chain.Uid, chain.SelfUid);
var results = await Collection.Business.SendEvent(@event);
if (results.Count != 0)
{
var result = (FileDownloadEvent)results[0];
file.FileUrl = result.FileUrl;
}

break;
}
case FileEntity { FileId: not null } file when chain.GroupUin is not null: // group
{
var @event = GroupFSDownloadEvent.Create(chain.GroupUin.Value, file.FileId);
var results = await Collection.Business.SendEvent(@event);
if (results.Count != 0)
{
var result = (GroupFSDownloadEvent)results[0];
file.FileUrl = result.FileUrl;
break;
}
case FileEntity { FileId: not null } file when chain.GroupUin is not null: // group
{
var @event = GroupFSDownloadEvent.Create(chain.GroupUin.Value, file.FileId);
var results = await Collection.Business.SendEvent(@event);
if (results.Count != 0)
{
var result = (GroupFSDownloadEvent)results[0];
file.FileUrl = result.FileUrl;
}

break;
}
case MultiMsgEntity { ResId: not null } multi:
{
var @event = MultiMsgDownloadEvent.Create(chain.Uid ?? "", multi.ResId);
var results = await Collection.Business.SendEvent(@event);
if (results.Count != 0)
break;
}
case MultiMsgEntity { ResId: not null } multi:
{
var result = (MultiMsgDownloadEvent)results[0];
multi.Chains.AddRange((IEnumerable<MessageChain>?)result.Chains ?? Array.Empty<MessageChain>());
var @event = MultiMsgDownloadEvent.Create(chain.Uid ?? "", multi.ResId);
var results = await Collection.Business.SendEvent(@event);
if (results.Count != 0)
{
var result = (MultiMsgDownloadEvent)results[0];
multi.Chains.AddRange((IEnumerable<MessageChain>?)result.Chains ?? Array.Empty<MessageChain>());
}

break;
}
case RecordEntity { MsgInfo: not null } record:
{
var @event = chain.IsGroup
? RecordGroupDownloadEvent.Create(chain.GroupUin ?? 0, record.MsgInfo)
: RecordDownloadEvent.Create(chain.Uid ?? string.Empty, record.MsgInfo);

break;
}
case RecordEntity { MsgInfo: not null } record:
{
var @event = chain.IsGroup
? RecordGroupDownloadEvent.Create(chain.GroupUin ?? 0, record.MsgInfo)
: RecordDownloadEvent.Create(chain.Uid ?? string.Empty, record.MsgInfo);
var results = await Collection.Business.SendEvent(@event);
if (results.Count != 0)
{
var result = (RecordDownloadEvent)results[0];
record.AudioUrl = result.AudioUrl;
}

var results = await Collection.Business.SendEvent(@event);
if (results.Count != 0)
{
var result = (RecordDownloadEvent)results[0];
record.AudioUrl = result.AudioUrl;
break;
}
case RecordEntity { AudioUuid: not null } record:
{
var @event = chain.IsGroup
? RecordGroupDownloadEvent.Create(chain.GroupUin ?? 0, record.AudioUuid)
: RecordDownloadEvent.Create(chain.Uid ?? string.Empty, record.AudioUuid);

break;
}
case RecordEntity { AudioUuid: not null } record:
{
var @event = chain.IsGroup
? RecordGroupDownloadEvent.Create(chain.GroupUin ?? 0, record.AudioUuid)
: RecordDownloadEvent.Create(chain.Uid ?? string.Empty, record.AudioUuid);
var results = await Collection.Business.SendEvent(@event);
if (results.Count != 0)
{
var result = (RecordDownloadEvent)results[0];
record.AudioUrl = result.AudioUrl;
}

var results = await Collection.Business.SendEvent(@event);
if (results.Count != 0)
{
var result = (RecordDownloadEvent)results[0];
record.AudioUrl = result.AudioUrl;
break;
}

break;
}
case VideoEntity { VideoUuid: not null } video:
{
string uid = (chain.IsGroup
? await Collection.Business.CachingLogic.ResolveUid(chain.GroupUin, chain.FriendUin)
: chain.Uid) ?? "";
var @event = VideoDownloadEvent.Create(video.VideoUuid, uid, video.FilePath, "", "", chain.IsGroup);
var results = await Collection.Business.SendEvent(@event);
if (results.Count != 0)
case VideoEntity { VideoUuid: not null } video:
{
var result = (VideoDownloadEvent)results[0];
video.VideoUrl = result.AudioUrl;
string uid = (chain.IsGroup
? await Collection.Business.CachingLogic.ResolveUid(chain.GroupUin, chain.FriendUin)
: chain.Uid) ?? "";
var @event = VideoDownloadEvent.Create(video.VideoUuid, uid, video.FilePath, "", "", chain.IsGroup);
var results = await Collection.Business.SendEvent(@event);
if (results.Count != 0)
{
var result = (VideoDownloadEvent)results[0];
video.VideoUrl = result.AudioUrl;
}

break;
}
case ImageEntity image when !image.ImageUrl.Contains("&rkey=") && image.MsgInfo is not null:
{
var @event = image.IsGroup
? ImageGroupDownloadEvent.Create(image.GroupUin ?? 0, image.MsgInfo)
: ImageDownloadEvent.Create(image.FriendUid ?? string.Empty, image.MsgInfo);

break;
}
case ImageEntity image when !image.ImageUrl.Contains("&rkey=") && image.MsgInfo is not null:
{
var @event = image.IsGroup
? ImageGroupDownloadEvent.Create(image.GroupUin ?? 0, image.MsgInfo)
: ImageDownloadEvent.Create(image.FriendUid ?? string.Empty, image.MsgInfo);
var results = await Collection.Business.SendEvent(@event);
if (results.Count != 0)
{
var result = (ImageDownloadEvent)results[0];
image.ImageUrl = result.ImageUrl;
}

var results = await Collection.Business.SendEvent(@event);
if (results.Count != 0)
{
var result = (ImageDownloadEvent)results[0];
image.ImageUrl = result.ImageUrl;
break;
}

break;
}
}
}

private async Task ResolveOutgoingChain(MessageChain chain)
{
foreach (var entity in chain) switch (entity)
foreach (var entity in chain)
{
case ForwardEntity forward when forward.TargetUin != 0:
switch (entity)
{
var cache = Collection.Business.CachingLogic;
forward.Uid = await cache.ResolveUid(chain.GroupUin, forward.TargetUin) ?? throw new Exception($"Failed to resolve Uid for Uin {forward.TargetUin}");

break;
}
case MentionEntity mention when mention.Uin != 0:
{
var cache = Collection.Business.CachingLogic;
mention.Uid = await cache.ResolveUid(chain.GroupUin, mention.Uin) ?? throw new Exception($"Failed to resolve Uid for Uin {mention.Uin}");

if (chain is { IsGroup: true, GroupUin: not null } && mention.Name is null)
case ForwardEntity forward when forward.TargetUin != 0:
{
var members = await Collection.Business.CachingLogic.GetCachedMembers(chain.GroupUin.Value, false);
var member = members.FirstOrDefault(x => x.Uin == mention.Uin);
if (member != null) mention.Name = $"@{member.MemberCard ?? member.MemberName}";
var cache = Collection.Business.CachingLogic;
forward.Uid = await cache.ResolveUid(chain.GroupUin, forward.TargetUin) ?? throw new Exception($"Failed to resolve Uid for Uin {forward.TargetUin}");

break;
}
else if (chain is { IsGroup: false } && mention.Name is null)
case MentionEntity mention when mention.Uin != 0:
{
var friends = await Collection.Business.CachingLogic.GetCachedFriends(false);
string? friend = friends.FirstOrDefault(x => x.Uin == mention.Uin)?.Nickname;
if (friend != null) mention.Name = $"@{friend}";
}
var cache = Collection.Business.CachingLogic;
mention.Uid = await cache.ResolveUid(chain.GroupUin, mention.Uin) ?? throw new Exception($"Failed to resolve Uid for Uin {mention.Uin}");

break;
}
case MultiMsgEntity { ResId: null } multiMsg:
{
if (chain.GroupUin != null) foreach (var c in multiMsg.Chains) c.GroupUin = chain.GroupUin;
if (chain is { IsGroup: true, GroupUin: not null } && mention.Name is null)
{
var members = await Collection.Business.CachingLogic.GetCachedMembers(chain.GroupUin.Value, false);
var member = members.FirstOrDefault(x => x.Uin == mention.Uin);
if (member != null) mention.Name = $"@{member.MemberCard ?? member.MemberName}";
}
else if (chain is { IsGroup: false } && mention.Name is null)
{
var friends = await Collection.Business.CachingLogic.GetCachedFriends(false);
string? friend = friends.FirstOrDefault(x => x.Uin == mention.Uin)?.Nickname;
if (friend != null) mention.Name = $"@{friend}";
}

var multiMsgEvent = MultiMsgUploadEvent.Create(chain.GroupUin, multiMsg.Chains);
var results = await Collection.Business.SendEvent(multiMsgEvent);
if (results.Count != 0)
break;
}
case MultiMsgEntity { ResId: null } multiMsg:
{
var result = (MultiMsgUploadEvent)results[0];
multiMsg.ResId = result.ResId;
if (chain.GroupUin != null) foreach (var c in multiMsg.Chains) c.GroupUin = chain.GroupUin;

var multiMsgEvent = MultiMsgUploadEvent.Create(chain.GroupUin, multiMsg.Chains);
var results = await Collection.Business.SendEvent(multiMsgEvent);
if (results.Count != 0)
{
var result = (MultiMsgUploadEvent)results[0];
multiMsg.ResId = result.ResId;
}
break;
}
break;
}
case MultiMsgEntity { ResId: not null, Chains.Count: 0 } multiMsg:
{
var @event = MultiMsgDownloadEvent.Create(chain.Uid ?? "", multiMsg.ResId);
var results = await Collection.Business.SendEvent(@event);
if (results.Count != 0)
case MultiMsgEntity { ResId: not null, Chains.Count: 0 } multiMsg:
{
var result = (MultiMsgDownloadEvent)results[0];
multiMsg.Chains.AddRange((IEnumerable<MessageChain>?)result.Chains ?? Array.Empty<MessageChain>());
var @event = MultiMsgDownloadEvent.Create(chain.Uid ?? "", multiMsg.ResId);
var results = await Collection.Business.SendEvent(@event);
if (results.Count != 0)
{
var result = (MultiMsgDownloadEvent)results[0];
multiMsg.Chains.AddRange((IEnumerable<MessageChain>?)result.Chains ?? Array.Empty<MessageChain>());
}
break;
}
break;
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions Lagrange.Core/Internal/Event/Notify/FriendSysRecallEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ internal class FriendSysRecallEvent : ProtocolEvent
{
public string FromUid { get; }

public uint Sequence { get; }
public uint ClientSequence { get; }

public uint Time { get; }

public uint Random { get; }

public string Tip { get; }

private FriendSysRecallEvent(string fromUid, uint sequence, uint time, uint random, string tip) : base(0)
private FriendSysRecallEvent(string fromUid, uint clientSequence, uint time, uint random, string tip) : base(0)
{
FromUid = fromUid;
Sequence = sequence;
ClientSequence = clientSequence;
Time = time;
Random = random;
Tip = tip;
}

public static FriendSysRecallEvent Result(string fromUid, uint sequence, uint time, uint random, string tip)
=> new(fromUid, sequence, time, random, tip);
public static FriendSysRecallEvent Result(string fromUid, uint clientSequence, uint time, uint random, string tip)
=> new(fromUid, clientSequence, time, random, tip);
}
2 changes: 1 addition & 1 deletion Lagrange.Core/Internal/Packets/Message/C2CRecallMsg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal class C2CRecallMsgInfo

[ProtoMember(2)] public uint Random { get; set; }

[ProtoMember(3)] public ulong MessageId { get; set; } // 0x10000000 << 16 | Random
[ProtoMember(3)] public ulong MessageId { get; set; } // 0x1000000 << 32 | Random

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal class FriendRecallInfo

[ProtoMember(2)] public string ToUid { get; set; }

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

[ProtoMember(4)] public ulong NewId { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ private static void ProcessEvent0x210(Span<byte> payload, PushMsg msg, List<Prot
var recall = Serializer.Deserialize<FriendRecall>(content.AsSpan());
var recallEvent = FriendSysRecallEvent.Result(
recall.Info.FromUid,
recall.Info.Sequence,
recall.Info.ClientSequence,
recall.Info.Time,
recall.Info.Random,
recall.Info.TipInfo.Tip ?? ""
Expand Down
Loading

0 comments on commit d39c1bf

Please sign in to comment.