Skip to content

[Core] refactor parse MentionEntity#101

Merged
NoirHare merged 1 commit into
mainfrom
redmomn/refactor-mention-parse
Mar 20, 2026
Merged

[Core] refactor parse MentionEntity#101
NoirHare merged 1 commit into
mainfrom
redmomn/refactor-mention-parse

Conversation

@Redmomn
Copy link
Copy Markdown
Contributor

@Redmomn Redmomn commented Mar 20, 2026

No description provided.

Copilot AI review requested due to automatic review settings March 20, 2026 11:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors MentionEntity parsing to extract mention metadata from Text.PbReserve by deserializing TextResvAttr, aligning parsing with how mentions are built elsewhere in the message entity system.

Changes:

  • Removed legacy BinaryPacket-based parsing of Text.Attr6Buf for mentions.
  • Added ProtoHelper.Deserialize<TextResvAttr>(...) parsing from Text.PbReserve to obtain the mentioned member UIN.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +71 to 72
if (target.Text is { Attr6Buf.Length: > 0, PbReserve: { Length: > 0 } reserve })
{
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parse guard requires Attr6Buf.Length > 0, but the new implementation only reads from Text.PbReserve. This will cause MentionEntity.Parse to return null for mentions where PbReserve is populated but Attr6Buf is empty (including elems produced by MentionEntity.Build, which never sets Attr6Buf). Consider keying off PbReserve (and/or TextResvAttr.AtType) instead of Attr6Buf, or support both formats explicitly (old Attr6Buf + new PbReserve).

Copilot uses AI. Check for mistakes.

return new MentionEntity(uin, target.Text.TextMsg);
var attr = ProtoHelper.Deserialize<TextResvAttr>(reserve.Span);
return new MentionEntity((long)attr.AtMemberUin, target.Text.TextMsg);
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TextResvAttr contains AtMemberUid, but Parse currently discards it. Since MentionEntity already has an internal Uid property (and Build writes AtMemberUid), it would be better to populate Uid from attr.AtMemberUid during parsing so downstream logic can use it when UIN is absent/0 (e.g., UID-only mentions).

Suggested change
return new MentionEntity((long)attr.AtMemberUin, target.Text.TextMsg);
return new MentionEntity((long)attr.AtMemberUin, target.Text.TextMsg)
{
Uid = attr.AtMemberUid
};

Copilot uses AI. Check for mistakes.
@NoirHare NoirHare merged commit b733987 into main Mar 20, 2026
16 checks passed
@NoirHare NoirHare deleted the redmomn/refactor-mention-parse branch March 20, 2026 13:20
Bemly pushed a commit to Bemly/CharonAnchor that referenced this pull request May 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants