fix(protocol): decode nested group operators

Recognize both raw UTF-8 UIDs and nested OperatorInfo envelopes in GroupChange pushes while keeping self-kick and voluntary-leave semantics explicit.\n\nFixes #253.
This commit is contained in:
DrSmoothl committed 2026-07-20 14:08:50 +08:00
1 parent ae6093cf23
commit 2dbd321ef0
3 files changed
+56 -5

No files matched your search

@@ -1,7 +1,11 @@
import { protobuf_decode } from '@snowluma/proton';
import type { GroupMemberJoin, GroupMemberLeave } from '../../events';
import type { GroupChange, SelfJoinInGroup } from '@snowluma/proto-defs/notify';
import { decodeNestedOperatorUid, decodeRawOperatorUid, resolveUidToUin } from '../helpers';
import {
decodeGroupChangeOperatorUid,
decodeNestedOperatorUid,
resolveUidToUin,
} from '../helpers';
import type { MsgPushDecoder } from '../registry';
function joinTypeFromOperationType(raw: number): NonNullable<GroupMemberJoin['joinType']> {
@@ -18,7 +22,7 @@ export const decodeGroupMemberJoin: MsgPushDecoder = (ctx) => {
if (!change) return [];
const groupId = change.groupUin ?? 0;
const userUid = change.memberUid ?? '';
const operatorUid = decodeRawOperatorUid(
const operatorUid = decodeGroupChangeOperatorUid(
change.operatorBytes ?? new Uint8Array(0),
'group member increase',
);
@@ -74,11 +78,11 @@ export const decodeGroupMemberLeave: MsgPushDecoder = (ctx) => {
operatorUin = userUin;
} else {
const operatorBytes = change.operatorBytes ?? new Uint8Array(0);
// QQ sends the operator as a raw UTF-8 UID for normal member changes.
// Only the bot-self-kicked variant (decreaseType=3) wraps it in OperatorInfo.
// Self-kick always uses OperatorInfo. Ordinary removals vary between a raw
// UTF-8 UID and the same envelope, so discriminate by its field-1 wire tag.
operatorUid = dt === 3
? decodeNestedOperatorUid(operatorBytes, 'group member decrease type=3')
: decodeRawOperatorUid(operatorBytes, `group member decrease type=${dt}`);
: decodeGroupChangeOperatorUid(operatorBytes, `group member decrease type=${dt}`);
operatorUin = resolveUidToUin(ctx.identity, groupId, operatorUid, 0);
}
const ev: GroupMemberLeave = {
@@ -139,6 +139,15 @@ export function decodeNestedOperatorUid(bytes: Uint8Array, context: string): str
return assertOperatorUid(uid, context, bytes);
}
const OPERATOR_INFO_FIELD_TAG = 0x0a;
export function decodeGroupChangeOperatorUid(bytes: Uint8Array, context: string): string {
if (!bytes || bytes.length === 0) return '';
return bytes[0] === OPERATOR_INFO_FIELD_TAG
? decodeNestedOperatorUid(bytes, context)
: decodeRawOperatorUid(bytes, context);
}
export function buildTemplateMap(params: Array<{ name?: string; value?: string }>): Map<string, string> {
const map = new Map<string, string>();
for (const p of params) {