fix(forward): preserve group merged-forward sender nickname (#201)
get_forward_msg returned empty sender.nickname/card for group merged-forward nodes. The reporter blamed a mis-parsed group_id + a failing member-list enrichment (0xfe7_3 0x899_AUTHORITY_FAIL on a placeholder source group), but on-target capture shows the sender display name IS in the payload: a merged-forward node leaves `grp.memberName` null and instead carries the sender name in `grp.groupName` (field 4) — QQ repurposes the group-name slot per node. parseMsgPush only reads memberName (correct for live messages), so the name was dropped and the code fell through to the member-list enrichment, which can't resolve a group the bot isn't in. Fix: in the forward-node decode, fall back to `grp.groupName` for the sender nickname (scoped to the forward path — live-message decoding is untouched). This also makes the AUTHORITY_FAIL enrichment fetch unnecessary for the common case. Verified on a real forward (fromUin 1787882683 ↔ grp.groupName "墨梓柒"): nickname now populated, no member-list call. group_id stays the payload's value (genuinely a placeholder/source group, not a mis-parse).
This commit is contained in:
2 files changed
+43
-2
No files matched your search
@@ -716,9 +716,17 @@ export class ForwardApi {
|
||||
if (!event) continue;
|
||||
|
||||
if (event.kind === 'group_message') {
|
||||
// [#201] A merged-forward node leaves `grp.memberName` empty and instead
|
||||
// carries the sender's display name in `grp.groupName` (field 4) — QQ
|
||||
// repurposes the group-name slot per node. parseMsgPush only reads
|
||||
// memberName (correct for live messages), so fall back to groupName here.
|
||||
// This makes the placeholder-source-group member-list enrichment (which
|
||||
// 0x899-AUTHORITY_FAILs) unnecessary for the common case. Verified on
|
||||
// real forwards: fromUin 1787882683 ↔ grp.groupName "墨梓柒".
|
||||
const fwdName = (msgBody.responseHead?.grp?.groupName ?? '').trim();
|
||||
out.push({
|
||||
userUin: event.senderUin,
|
||||
nickname: event.senderCard || event.senderNick,
|
||||
nickname: event.senderCard || event.senderNick || fwdName,
|
||||
elements: event.elements,
|
||||
time: event.time,
|
||||
msgId: event.msgId,
|
||||
|
||||
@@ -14,8 +14,10 @@ vi.mock('@snowluma/protocol/element-builder', () => ({
|
||||
buildSendElems: vi.fn(async () => []),
|
||||
}));
|
||||
|
||||
import { gzipSync } from 'zlib';
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import type { SendLongMsgResp } from '@snowluma/proto-defs/longmsg';
|
||||
import type { SendLongMsgResp, LongMsgResult, RecvLongMsgResp } from '@snowluma/proto-defs/longmsg';
|
||||
import type { PushMsgBody } from '@snowluma/proto-defs/message';
|
||||
import { ForwardApi } from '../../src/bridge/apis/forward';
|
||||
import { mockBridge } from './_helpers';
|
||||
|
||||
@@ -30,6 +32,16 @@ function uploadResponseWithResId(resId: string) {
|
||||
};
|
||||
}
|
||||
|
||||
/** Build an SsoRecvLongMsg response wrapping the given forward nodes. */
|
||||
function recvLongMsgResp(bodies: PushMsgBody[]) {
|
||||
const longMsg: LongMsgResult = {
|
||||
action: [{ actionCommand: 'MultiMsg', actionData: { msgBody: bodies } }],
|
||||
};
|
||||
const gz = gzipSync(Buffer.from(protobuf_encode<LongMsgResult>(longMsg)));
|
||||
const resp = protobuf_encode<RecvLongMsgResp>({ result: { payload: new Uint8Array(gz) } });
|
||||
return { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: Buffer.from(resp) };
|
||||
}
|
||||
|
||||
describe('actions/forward', () => {
|
||||
it('uploadForwardNodes rejects empty arrays', async () => {
|
||||
const bridge = mockBridge();
|
||||
@@ -94,6 +106,27 @@ describe('actions/forward', () => {
|
||||
expect(sendRawPacket).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('[#201] fills a group forward node nickname from grp.groupName when memberName is empty', async () => {
|
||||
// Real merged-forward nodes leave grp.memberName null and carry the sender
|
||||
// display name in grp.groupName (field 4). Verified on-target: fromUin
|
||||
// 1787882683 ↔ grp.groupName "墨梓柒", memberName null. Before the fix the
|
||||
// node nickname came back "" and enrichSenders 0x899-AUTHORITY_FAIL'd on the
|
||||
// placeholder source group.
|
||||
const node: PushMsgBody = {
|
||||
responseHead: { fromUin: 1787882683, fromUid: 'u_x', grp: { groupUin: 284840486, groupName: '墨梓柒' } },
|
||||
contentHead: { msgType: 82, sequence: 1, timestamp: 100 }, // 82 = PkgType.GroupMessage
|
||||
body: { richText: { elems: [{ text: { str: 'hi' } }] } },
|
||||
};
|
||||
const bridge = mockBridge({ sendRawPacket: vi.fn(async () => recvLongMsgResp([node])) as any });
|
||||
const nodes = await new ForwardApi(bridge as any).fetch('res-201');
|
||||
expect(nodes).toHaveLength(1);
|
||||
expect(nodes[0]!.userUin).toBe(1787882683);
|
||||
expect(nodes[0]!.nickname).toBe('墨梓柒'); // was '' before the fix
|
||||
expect(nodes[0]!.groupId).toBe(284840486);
|
||||
// The nickname is present, so no group-member-list enrichment fetch fires.
|
||||
expect(bridge.sendRawPacket).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('fetchForwardNodes throws on transport failure when nothing is cached', async () => {
|
||||
const bridge = mockBridge({
|
||||
sendRawPacket: vi.fn(async () => ({
|
||||
|
||||
Reference in new issue
Block a user