fix(message): preserve passive temporary session context
Keep passive replies associated with the correct conversation when the same contact is shared across groups. Active temporary conversations remain unsupported. Fixes #308
This commit is contained in:
2 files changed
+99
-4
No files matched your search
@@ -18,11 +18,8 @@ export interface ResponseGrp {
|
||||
groupName?: pb<7, string>;
|
||||
}
|
||||
|
||||
// ResponseHead field 7 is multi-purpose: a forward message carries
|
||||
// `friendName` (field 6); a group temp-session push carries the source group
|
||||
// (field 4). Subfields don't collide, so one interface covers both.
|
||||
export interface ResponseForward {
|
||||
tempGroupUin?: pb<4, uint_32>;
|
||||
tempGroupUin?: pb<5, uint_32>;
|
||||
friendName?: pb<6, string>;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
import type { PacketInfo } from '@snowluma/common/protocol-types';
|
||||
import {
|
||||
protobuf_encode,
|
||||
type pb,
|
||||
type pb_repeated,
|
||||
type string,
|
||||
type uint_32,
|
||||
} from '@snowluma/proton';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import type { IdentityService } from '../../src/identity-service';
|
||||
import { parseMsgPush } from '../../src/msg-push';
|
||||
|
||||
interface TextFixture {
|
||||
str?: pb<1, string>;
|
||||
}
|
||||
|
||||
interface ElemFixture {
|
||||
text?: pb<1, TextFixture>;
|
||||
}
|
||||
|
||||
interface RichTextFixture {
|
||||
elems?: pb_repeated<2, ElemFixture>;
|
||||
}
|
||||
|
||||
interface MessageBodyFixture {
|
||||
richText?: pb<1, RichTextFixture>;
|
||||
}
|
||||
|
||||
interface TempSessionFixture {
|
||||
previousGroup?: pb<4, uint_32>;
|
||||
sourceGroup?: pb<5, uint_32>;
|
||||
}
|
||||
|
||||
interface ResponseHeadFixture {
|
||||
fromUin?: pb<1, uint_32>;
|
||||
fromUid?: pb<2, string>;
|
||||
tempSession?: pb<7, TempSessionFixture>;
|
||||
}
|
||||
|
||||
interface ContentHeadFixture {
|
||||
msgType?: pb<1, uint_32>;
|
||||
sequence?: pb<5, uint_32>;
|
||||
timestamp?: pb<6, uint_32>;
|
||||
ntMsgSeq?: pb<11, uint_32>;
|
||||
}
|
||||
|
||||
interface PushBodyFixture {
|
||||
responseHead?: pb<1, ResponseHeadFixture>;
|
||||
contentHead?: pb<2, ContentHeadFixture>;
|
||||
body?: pb<3, MessageBodyFixture>;
|
||||
}
|
||||
|
||||
interface PushFixture {
|
||||
message?: pb<1, PushBodyFixture>;
|
||||
}
|
||||
|
||||
const identity = { findFriend: () => undefined } as unknown as IdentityService;
|
||||
|
||||
function tempMessagePacket(previousGroup: number, sourceGroup: number): PacketInfo {
|
||||
return {
|
||||
pid: 1,
|
||||
uin: '2000000001',
|
||||
serviceCmd: 'trpc.msg.olpush.OlPushService.MsgPush',
|
||||
seqId: 1,
|
||||
retCode: 0,
|
||||
fromClient: false,
|
||||
body: protobuf_encode<PushFixture>({
|
||||
message: {
|
||||
responseHead: {
|
||||
fromUin: 10001,
|
||||
fromUid: 'u_peer',
|
||||
tempSession: { previousGroup, sourceGroup },
|
||||
},
|
||||
contentHead: {
|
||||
msgType: 141,
|
||||
sequence: 7,
|
||||
timestamp: 1_710_000_000,
|
||||
ntMsgSeq: 8,
|
||||
},
|
||||
body: { richText: { elems: [{ text: { str: 'hello' } }] } },
|
||||
},
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
describe('parseMsgPush — temporary-session source (#308)', () => {
|
||||
it('keeps a passive reply bound to the group that opened the current session', () => {
|
||||
const events = parseMsgPush(tempMessagePacket(11111, 22222), identity);
|
||||
|
||||
expect(events).toMatchObject([{
|
||||
kind: 'temp_message',
|
||||
senderUin: 10001,
|
||||
groupId: 22222,
|
||||
elements: [{ type: 'text', text: 'hello' }],
|
||||
}]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user