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.
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import { protobuf_decode } from '@snowluma/proton';
|
|
import type { GroupAdminEvent } from '../../events';
|
|
import type { GroupAdmin } from '@snowluma/proto-defs/notify';
|
|
import { resolveUidToUin } from '../helpers';
|
|
import type { MsgPushDecoder } from '../registry';
|
|
|
|
export const decodeGroupAdmin: MsgPushDecoder = (ctx) => {
|
|
const admin = protobuf_decode<GroupAdmin>(ctx.content);
|
|
if (!admin?.body) return [];
|
|
// proton materializes an *absent* embedded-message field as an empty
|
|
// `{}` rather than leaving it undefined, so the old
|
|
// `extraEnable !== undefined` promote/demote test was always true and
|
|
// every demote got reported as a promotion (with a fallback userUin).
|
|
// The live sub-message is the one that actually carries an `adminUid`
|
|
// — key off that instead.
|
|
const enableUid = admin.body.extraEnable?.adminUid;
|
|
const disableUid = admin.body.extraDisable?.adminUid;
|
|
const adminUid = enableUid || disableUid;
|
|
if (!adminUid) return [];
|
|
const groupId = admin.groupUin ?? 0;
|
|
const set = !!enableUid;
|
|
const userUin = resolveUidToUin(ctx.identity, groupId, adminUid);
|
|
|
|
const ev: GroupAdminEvent = {
|
|
kind: 'group_admin',
|
|
time: ctx.head.timestamp,
|
|
selfUin: ctx.selfUin,
|
|
groupId,
|
|
userUin,
|
|
set,
|
|
};
|
|
return [ev];
|
|
};
|