refactor(protocol): keep Decoder a pure parse of MsgPush events
Decoder used to write Identity: decodeGroupAdmin patched member roles and decodeFriendMessage stashed invite-card msgseq. That split observation with IncomingPacketPipeline.rememberEventIdentity and put pending-application state on Identity. Decoder now only returns events. Invite-card groupUin/msgseq ride on FriendMessage; the live pipeline writes them to ContactsApi through an optional port. Role self-heal for #93 stays in rememberEventIdentity. History and forward decode do not write. Identity no longer stores invite-card sequences. Live #93 and #125 behavior is unchanged.
This commit is contained in:
12 files changed
+148
-79
No files matched your search
@@ -28,16 +28,11 @@ export const decodeFriendMessage: MsgPushDecoder = (ctx) => {
|
||||
const sentBySelf = ctx.fromUin > 0 && ctx.fromUin === ctx.selfUin;
|
||||
const peerUin = sentBySelf ? (ctx.responseHead?.toUin ?? 0) : ctx.fromUin;
|
||||
const sequenceAuthoritative = ctx.head.ntMsgSeq > 0;
|
||||
// Stash the approval msgseq from a live private group-invite card so a later
|
||||
// `set_group_add_request` can approve a bot self-invite (issue #125).
|
||||
// Historical decode is intentionally read-only: replaying an older card here
|
||||
// could overwrite the sequence observed from a newer live invite.
|
||||
if (!ctx.isHistorical) {
|
||||
for (const el of elements) {
|
||||
if (el.type === 'json' && typeof el.text === 'string') {
|
||||
const card = parseGroupInviteCard(el.text);
|
||||
if (card) ctx.identity.rememberGroupInviteCardSequence(card.groupUin, card.sequence);
|
||||
}
|
||||
let inviteCard: { groupUin: number; sequence: number } | null = null;
|
||||
for (const el of elements) {
|
||||
if (el.type === 'json' && typeof el.text === 'string') {
|
||||
inviteCard = parseGroupInviteCard(el.text);
|
||||
if (inviteCard) break;
|
||||
}
|
||||
}
|
||||
const ev: FriendMessage = {
|
||||
@@ -54,6 +49,10 @@ export const decodeFriendMessage: MsgPushDecoder = (ctx) => {
|
||||
msgId: ctx.head.msgId & 0x7FFFFFFF,
|
||||
elements,
|
||||
senderNick: '',
|
||||
...(inviteCard ? {
|
||||
inviteCardGroupUin: inviteCard.groupUin,
|
||||
inviteCardSequence: inviteCard.sequence,
|
||||
} : {}),
|
||||
};
|
||||
if (ctx.responseHead?.forward?.friendName) {
|
||||
ev.senderNick = ctx.responseHead.forward.friendName;
|
||||
|
||||
@@ -21,21 +21,6 @@ export const decodeGroupAdmin: MsgPushDecoder = (ctx) => {
|
||||
const set = !!enableUid;
|
||||
const userUin = resolveUidToUin(ctx.identity, groupId, adminUid);
|
||||
|
||||
// Keep the in-memory member cache in step with the promotion/demotion.
|
||||
// `get_group_member_info` serves straight from this cache on its
|
||||
// default (no_cache=false) path — and we deliberately *don't*
|
||||
// force-refresh there, because clients like OlivaDice/MaiBot query it
|
||||
// once per inbound message and a per-message OIDB refetch trips
|
||||
// Tencent risk-control (see the ContactsApi member-list cache). So if
|
||||
// we don't patch the role here, a freshly-promoted admin keeps reading
|
||||
// back as `member` until the member-list TTL lapses, and permission
|
||||
// gates reject their commands (#93). Only touch a member we already
|
||||
// know, and never downgrade the owner.
|
||||
const cached = ctx.identity.findGroupMember(groupId, userUin);
|
||||
if (cached && cached.role !== 'owner') {
|
||||
ctx.identity.updateGroupMember(groupId, { ...cached, role: set ? 'admin' : 'member' });
|
||||
}
|
||||
|
||||
const ev: GroupAdminEvent = {
|
||||
kind: 'group_admin',
|
||||
time: ctx.head.timestamp,
|
||||
|
||||
Reference in new issue
Block a user