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
@@ -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,
|
||||
}]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -498,3 +498,41 @@ describe('IncomingPacketPipeline / group_card_change from message traffic', () =
|
||||
expect(captured.some((e) => e.kind === 'group_card_change')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('IncomingPacketPipeline / invite-card pending application', () => {
|
||||
const friendMessage = (
|
||||
card?: { inviteCardGroupUin: number; inviteCardSequence: number },
|
||||
): QQEventVariant => ({
|
||||
kind: 'friend_message',
|
||||
time: 1,
|
||||
selfUin: 10001,
|
||||
senderUin: 222,
|
||||
senderNick: 'Bob',
|
||||
msgSeq: 1,
|
||||
msgId: 1,
|
||||
elements: [],
|
||||
...card,
|
||||
});
|
||||
|
||||
it('remembers parsed invite-card facts through the optional port', () => {
|
||||
const rememberGroupInviteCardSequence = vi.fn();
|
||||
const pipeline = new IncomingPacketPipeline({
|
||||
identity: IdentityService.memory('10001'),
|
||||
events: new BridgeEventBus(),
|
||||
refreshMemberCache: vi.fn(async () => false),
|
||||
resolveGroupJoinRequest: vi.fn(async () => null),
|
||||
rememberGroupInviteCardSequence,
|
||||
});
|
||||
pipeline.registerCmd('test.cmd', () => [
|
||||
friendMessage({ inviteCardGroupUin: 12345, inviteCardSequence: 778899 }),
|
||||
]);
|
||||
pipeline.process({ serviceCmd: 'test.cmd' } as PacketInfo);
|
||||
expect(rememberGroupInviteCardSequence).toHaveBeenCalledWith(12345, 778899);
|
||||
});
|
||||
|
||||
it('does not remember when the port is omitted or the event has no card', () => {
|
||||
const { pipeline } = makePipeline();
|
||||
pipeline.registerCmd('test.cmd', () => [friendMessage()]);
|
||||
expect(() => pipeline.process({ serviceCmd: 'test.cmd' } as PacketInfo)).not.toThrow();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user