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:
DrSmoothl committed 2026-08-16 18:22:41 +08:00
1 parent fea1996e46
commit 226b48fd7a
12 files changed
+148 -79

No files matched your search

@@ -171,38 +171,38 @@ describe('fetchC2cMessageRange / SsoGetC2cMsg', () => {
)).rejects.toThrow('friend uid mismatch');
});
it('does not replay live-only invite observations from older history', async () => {
const remembered: Array<[number, number]> = [];
const observingIdentity = {
findFriend: () => undefined,
rememberGroupInviteCardSequence: (groupUin: number, sequence: number) => {
remembered.push([groupUin, sequence]);
},
} as unknown as IdentityService;
it('parses invite-card facts on friend messages without writing Identity', async () => {
const live = buildContextFromMessage(
inviteCardMessage(222),
10001,
observingIdentity,
identity,
false,
);
expect(live).not.toBeNull();
decodeFriendMessage(live!);
expect(decodeFriendMessage(live!)).toMatchObject([{
kind: 'friend_message',
inviteCardGroupUin: 12345,
inviteCardSequence: 222,
}]);
const historyResponse = protobuf_encode<SsoGetC2cMsgResponse>({
friendUid: 'u_friend',
messages: [inviteCardMessage(111)],
});
await fetchC2cMessageRange(
const out = await fetchC2cMessageRange(
{ sendRawPacket: async () => okResult(historyResponse) },
observingIdentity,
identity,
10001,
'u_friend',
100,
120,
);
expect(remembered).toEqual([[12345, 222]]);
expect(out).toMatchObject([{
kind: 'friend_message',
inviteCardGroupUin: 12345,
inviteCardSequence: 111,
}]);
});
});