fix(protocol): report incoming group invitations (#612)
Surface group invitations when the inviter is outside the friend list so clients can respond to them.
This commit is contained in:
4 files changed
+284
-8
No files matched your search
@@ -21,7 +21,9 @@ export const decodeGroupJoinRequest: MsgPushDecoder = (ctx) => {
|
||||
fromUid: join.targetUid ?? '',
|
||||
subType: 'add',
|
||||
message: '',
|
||||
flag: '',
|
||||
// Legacy flag: the approval path can resolve it from the request inbox
|
||||
// even when the pipeline cannot find a pending request to enrich from.
|
||||
flag: `add:${join.groupUin ?? 0}:${join.targetUid ?? ''}`,
|
||||
};
|
||||
return [ev];
|
||||
};
|
||||
@@ -45,7 +47,11 @@ export const decodeGroupInvitation: MsgPushDecoder = (ctx) => {
|
||||
invitedUid: inner.targetUid ?? '',
|
||||
subType: 'invite',
|
||||
message: '',
|
||||
flag: '',
|
||||
// Self-invite notices never carry the approval msgseq, and they are
|
||||
// absent from the UIN-based request inbox -- but the UID-based one used
|
||||
// by `set_group_add_request` legacy parsing does return them. Ship the
|
||||
// legacy flag so the event stays actionable (#125).
|
||||
flag: `invite:${inner.groupUin ?? 0}:${inner.invitorUid ?? ''}`,
|
||||
};
|
||||
return [ev];
|
||||
};
|
||||
@@ -67,7 +73,8 @@ export const decodeGroupInvite: MsgPushDecoder = (ctx) => {
|
||||
invitedUin: ctx.selfUin,
|
||||
subType: 'invite',
|
||||
message: '',
|
||||
flag: '',
|
||||
// See decodeGroupInvitation: keep the event actionable without the card.
|
||||
flag: `invite:${invite.groupUin ?? 0}:${invite.invitorUid ?? ''}`,
|
||||
};
|
||||
return [ev];
|
||||
};
|
||||
@@ -6,6 +6,14 @@ import type { QQEventVariant } from './events';
|
||||
import type { IdentityService } from './identity-service';
|
||||
import { formatGroupRequestFlag, type GroupRequestInfo } from './qq-info';
|
||||
|
||||
/**
|
||||
* How long a dispatched invitation stays remembered so the MSF notice and the
|
||||
* private `qun.invite` card of the SAME invitation do not both dispatch.
|
||||
* Both packets come from one server-side action, so the window only bounds how
|
||||
* long the marker lives -- matching itself is exact (group + inviter UID).
|
||||
*/
|
||||
const INVITE_PAIR_WINDOW_MS = 3_000;
|
||||
|
||||
const moduleLog = createLogger('Bridge');
|
||||
const moduleEventLog = createLogger('Event');
|
||||
const modulePacketLog = createLogger('Protocol.Packet');
|
||||
@@ -62,6 +70,15 @@ export class IncomingPacketPipeline {
|
||||
private readonly log: Logger;
|
||||
private readonly eventLog: Logger;
|
||||
private readonly packetLog: Logger;
|
||||
/**
|
||||
* One invitation can arrive as an MSF notice AND as a private card. The card
|
||||
* is the richer source (it carries the approval msgseq), so either one may
|
||||
* dispatch -- but never both. Two independent markers keep that mutual: a
|
||||
* notice suppresses the card that follows it, a card suppresses the notice.
|
||||
* Cards never suppress each other (a new msgseq is a new invitation).
|
||||
*/
|
||||
private readonly noticeDispatched_ = new Map<string, number>();
|
||||
private readonly cardDispatched_ = new Map<string, number>();
|
||||
|
||||
constructor(private readonly deps: PacketPipelineDeps) {
|
||||
// Tag every line we emit with this Bridge's UIN so per-account file
|
||||
@@ -390,6 +407,16 @@ export class IncomingPacketPipeline {
|
||||
return false;
|
||||
}
|
||||
|
||||
// The msgseq is cached above either way. Skip the duplicate event only when
|
||||
// the notice already delivered this same invitation -- a card with a new
|
||||
// sequence is a genuinely new invitation and must always dispatch.
|
||||
if (this.dispatchedRecently_(this.noticeDispatched_, groupId, event.senderUid ?? '')) {
|
||||
this.log.debug('invitation already dispatched from the notice: group=%d', groupId);
|
||||
return false;
|
||||
}
|
||||
|
||||
this.rememberDispatched_(this.cardDispatched_, groupId, event.senderUid ?? '');
|
||||
|
||||
this.finishDispatch({
|
||||
kind: 'group_invite',
|
||||
time: event.time,
|
||||
@@ -405,6 +432,27 @@ export class IncomingPacketPipeline {
|
||||
return true;
|
||||
}
|
||||
|
||||
private dispatchedRecently_(
|
||||
marker: Map<string, number>,
|
||||
groupId: number,
|
||||
inviterUid: string,
|
||||
): boolean {
|
||||
const key = `${groupId}:${inviterUid}`;
|
||||
const at = marker.get(key);
|
||||
if (at === undefined) return false;
|
||||
if (Date.now() - at < INVITE_PAIR_WINDOW_MS) return true;
|
||||
marker.delete(key);
|
||||
return false;
|
||||
}
|
||||
|
||||
private rememberDispatched_(
|
||||
marker: Map<string, number>,
|
||||
groupId: number,
|
||||
inviterUid: string,
|
||||
): void {
|
||||
marker.set(`${groupId}:${inviterUid}`, Date.now());
|
||||
}
|
||||
|
||||
private emit(event: QQEventVariant): void {
|
||||
// Fire-and-forget: errors inside subscribers are surfaced via the bus's
|
||||
// own onError hook so one bad listener never blocks the others.
|
||||
@@ -502,12 +550,36 @@ export class IncomingPacketPipeline {
|
||||
pkt: PacketInfo,
|
||||
event: Extract<QQEventVariant, { kind: 'group_invite' }>,
|
||||
): Promise<number> {
|
||||
// Self-invite notices omit the approval msgseq; the private card owns this event.
|
||||
// A self-invite never appears in the UIN-based request inbox, so there is
|
||||
// nothing to enrich from and querying it only wastes a round trip. The
|
||||
// private card carries the approval msgseq, but it only arrives for some
|
||||
// inviters -- when it does not, the notice is the only chance to surface
|
||||
// the invitation at all. Dispatch it with the decoder-provided legacy flag,
|
||||
// and let the card win when both arrive (see `dispatchedInvites_`).
|
||||
if (
|
||||
event.subType === 'invite' &&
|
||||
this.isSelfMemberIdentity(event.invitedUin ?? 0, event.invitedUid)
|
||||
) {
|
||||
return 0;
|
||||
if (!event.flag) {
|
||||
this.log.warn('self invitation without a flag: group=%d', event.groupId);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (this.dispatchedRecently_(this.cardDispatched_, event.groupId, event.fromUid ?? '')) {
|
||||
this.log.debug(
|
||||
'self invitation already dispatched from the card: group=%d',
|
||||
event.groupId,
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
|
||||
this.rememberDispatched_(this.noticeDispatched_, event.groupId, event.fromUid ?? '');
|
||||
|
||||
try {
|
||||
return this.dispatchEvent(pkt, event, 'sync');
|
||||
} catch (error) {
|
||||
throw new EnrichedDispatchError(error);
|
||||
}
|
||||
}
|
||||
|
||||
const uid = event.fromUid;
|
||||
|
||||
Reference in new issue
Block a user