refactor(protocol): own inbound UID-to-UIN resolution in Identity
Inbound person lookup used to be split across decoders, the packet pipeline, and Bridge closures. Missing identities were filled from unrelated packet headers, and "who is this person" was coupled to roster refresh and pending-request enrichment. Identity now owns both directions of resolution. The hot path stays synchronous and emits unresolved events on a miss. Only the paths that already waited before dispatch perform a network lookup, and that lookup is a profile fetch by UID rather than a member-list refresh. Pending-request comments and approval flags stay outside Identity. Decoders no longer invent a UIN from a group routing header. Private chat routing still uses a hop's own wire UIN when the hop is named that way. Inbound misses stay availability-first: they do not throw and do not mark Identity degraded.
This commit is contained in:
16 files changed
+334
-187
No files matched your search
@@ -44,6 +44,8 @@ interface PendingIdentityWrite {
|
||||
*/
|
||||
export interface IdentityFetcher {
|
||||
fetchProfile(uin: number): Promise<UserProfileInfo>;
|
||||
/** Inbound UID→UIN network hop. Must not be used to refresh a group roster. */
|
||||
fetchProfileByUid?(uid: string): Promise<UserProfileInfo>;
|
||||
fetchGroupMemberList?(groupId: number): Promise<unknown>;
|
||||
}
|
||||
|
||||
@@ -431,10 +433,36 @@ export class IdentityService {
|
||||
throw new Error(`failed to resolve UID for UIN ${normalized}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inbound UID→UIN. Sync cache/DB (including a numeric UID) first; on miss,
|
||||
* `fetchProfileByUid`. Returns null when still unknown. Never throws for a
|
||||
* miss, a fetcher error, or a missing fetcher — inbound events still emit.
|
||||
* Does not pull a group member list; that remains a roster side-effect.
|
||||
*/
|
||||
async resolveUin(uid: string, groupId?: number): Promise<number | null> {
|
||||
const cached = this.findUinByUid(uid, groupId);
|
||||
if (cached !== null) return cached;
|
||||
|
||||
const normalized = normalizeUid(uid);
|
||||
if (!normalized || !this.fetcher?.fetchProfileByUid) return null;
|
||||
|
||||
try {
|
||||
const profile = await this.fetcher.fetchProfileByUid(normalized);
|
||||
const uin = normalizeUin(profile.uin);
|
||||
if (uin !== null) return uin;
|
||||
} catch {
|
||||
// Fall through: a fetcher that remembered then threw still counts as a hit.
|
||||
}
|
||||
return this.findUinByUid(normalized, groupId);
|
||||
}
|
||||
|
||||
findUinByUid(uid: string, groupId?: number): number | null {
|
||||
const normalized = normalizeUid(uid);
|
||||
if (!normalized) return null;
|
||||
|
||||
const numeric = numericUidAsUin(normalized);
|
||||
if (numeric !== null) return numeric;
|
||||
|
||||
if (groupId !== undefined) {
|
||||
const member = this.findGroupMemberByUid(groupId, normalized);
|
||||
if (member) return member.uin;
|
||||
@@ -1303,6 +1331,12 @@ function normalizeUid(uid: unknown): string {
|
||||
return typeof uid === 'string' ? uid.trim() : '';
|
||||
}
|
||||
|
||||
/** A UID that is itself a decimal UIN. Protocol fact, not a packet-header guess. */
|
||||
function numericUidAsUin(uid: string): number | null {
|
||||
if (!/^\d+$/.test(uid)) return null;
|
||||
return normalizeUin(uid);
|
||||
}
|
||||
|
||||
function normalizeUin(uin: unknown): number | null {
|
||||
if (typeof uin === 'number' && Number.isFinite(uin)) {
|
||||
const n = Math.trunc(uin);
|
||||
|
||||
@@ -22,8 +22,7 @@ import type { PttTransPush } from '@snowluma/proto-defs/ptt-trans';
|
||||
import type { MsgPushContext } from '../context';
|
||||
import { Event0x210SubType } from '../enums';
|
||||
import {
|
||||
buildTemplateMap, findTemplateValue,
|
||||
parseU64OrZero,
|
||||
buildTemplateMap, c2cRoutingUin, findTemplateValue,
|
||||
resolveUidToUin,
|
||||
} from '../helpers';
|
||||
import type { MsgPushDecoder } from '../registry';
|
||||
@@ -177,7 +176,7 @@ function decodeFriendRequest(ctx: MsgPushContext): QQEventVariant[] {
|
||||
kind: 'friend_request',
|
||||
time: ctx.head.timestamp,
|
||||
selfUin: ctx.selfUin,
|
||||
fromUin: resolveUidToUin(ctx.identity, 0, sourceUid, ctx.fromUin),
|
||||
fromUin: resolveUidToUin(ctx.identity, 0, sourceUid),
|
||||
fromUid: sourceUid,
|
||||
message: request.info.message ?? '',
|
||||
flag: sourceUid,
|
||||
@@ -199,7 +198,7 @@ function decodeFriendRecall(ctx: MsgPushContext): QQEventVariant[] {
|
||||
kind: 'friend_recall',
|
||||
time: recall.info.time ?? ctx.head.timestamp,
|
||||
selfUin: ctx.selfUin,
|
||||
userUin: resolveUidToUin(ctx.identity, 0, peerUid, ctx.fromUin),
|
||||
userUin: resolveUidToUin(ctx.identity, 0, peerUid),
|
||||
msgSeq: recall.info.clientSequence ?? 0,
|
||||
clientSeq: recall.info.clientSequence ?? 0,
|
||||
recalledBySelf: isSelfRecall,
|
||||
@@ -211,7 +210,7 @@ function decodeNewFriend(ctx: MsgPushContext): QQEventVariant[] {
|
||||
const nf = protobuf_decode<NewFriend>(ctx.content);
|
||||
if (!nf?.info) return [];
|
||||
const newFriendUid = nf.info.uid ?? '';
|
||||
const newFriendUin = resolveUidToUin(ctx.identity, 0, newFriendUid, ctx.fromUin);
|
||||
const newFriendUin = c2cRoutingUin(ctx.identity, newFriendUid, ctx.fromUin);
|
||||
if (newFriendUin <= 0) return []; // can't surface a `user_id`-less friend_add to OneBot
|
||||
const ev: FriendAddEvent = {
|
||||
kind: 'friend_add',
|
||||
@@ -240,7 +239,7 @@ function decodeInputStatus(ctx: MsgPushContext): QQEventVariant[] {
|
||||
kind: 'friend_input_status',
|
||||
time: ctx.head.timestamp,
|
||||
selfUin: ctx.selfUin,
|
||||
userUin: resolveUidToUin(ctx.identity, 0, fromUid, ctx.fromUin),
|
||||
userUin: resolveUidToUin(ctx.identity, 0, fromUid),
|
||||
userUid: fromUid,
|
||||
eventType,
|
||||
statusText: inputStatusText(eventType),
|
||||
@@ -285,16 +284,15 @@ function decodeFriendPoke(ctx: MsgPushContext): QQEventVariant[] {
|
||||
const templates = buildTemplateMap(grayTip.msgTemplParam ?? []);
|
||||
const actor = findTemplateValue(templates, 'uin_str1');
|
||||
const target = findTemplateValue(templates, 'uin_str2');
|
||||
const senderUin = resolveUidToUin(ctx.identity, 0, actor, parseU64OrZero(actor));
|
||||
const routeFromUin = resolveUidToUin(ctx.identity, 0, ctx.fromUid, ctx.fromUin);
|
||||
const senderUin = resolveUidToUin(ctx.identity, 0, actor);
|
||||
const routeFromUin = c2cRoutingUin(ctx.identity, ctx.fromUid, ctx.fromUin);
|
||||
// The gray-tip template only identifies the two poke endpoints. The C2C
|
||||
// routing head owns the conversation peer: outbound notices use `to`,
|
||||
// while inbound notices use `from`, just like ordinary friend messages.
|
||||
const sentBySelf = routeFromUin > 0 && routeFromUin === ctx.selfUin;
|
||||
const peerUin = sentBySelf
|
||||
? resolveUidToUin(
|
||||
? c2cRoutingUin(
|
||||
ctx.identity,
|
||||
0,
|
||||
ctx.responseHead?.toUid ?? '',
|
||||
ctx.responseHead?.toUin ?? 0,
|
||||
)
|
||||
@@ -311,7 +309,7 @@ function decodeFriendPoke(ctx: MsgPushContext): QQEventVariant[] {
|
||||
selfUin: ctx.selfUin,
|
||||
peerUin,
|
||||
senderUin,
|
||||
targetUin: resolveUidToUin(ctx.identity, 0, target, parseU64OrZero(target)),
|
||||
targetUin: resolveUidToUin(ctx.identity, 0, target),
|
||||
action: findTemplateValue(templates, 'action_str', 'alt_str1'),
|
||||
suffix: findTemplateValue(templates, 'suffix_str'),
|
||||
actionImgUrl: findTemplateValue(templates, 'action_img_url'),
|
||||
|
||||
@@ -21,7 +21,6 @@ import type { MsgPushContext } from '../context';
|
||||
import { Event0x2DCSubType } from '../enums';
|
||||
import {
|
||||
buildTemplateMap, findTemplateValue,
|
||||
parseU64OrZero,
|
||||
resolveUidToUin,
|
||||
unwrapGroupNotifyPayload,
|
||||
} from '../helpers';
|
||||
@@ -50,8 +49,8 @@ function decodeGroupMute(ctx: MsgPushContext): QQEventVariant[] {
|
||||
time: mute.data.timestamp ?? ctx.head.timestamp,
|
||||
selfUin: ctx.selfUin,
|
||||
groupId: mute.groupUin ?? 0,
|
||||
operatorUin: resolveUidToUin(ctx.identity, mute.groupUin ?? 0, mute.operatorUid ?? '', ctx.fromUin),
|
||||
userUin: resolveUidToUin(ctx.identity, mute.groupUin ?? 0, mute.data.state.targetUid ?? '', 0),
|
||||
operatorUin: resolveUidToUin(ctx.identity, mute.groupUin ?? 0, mute.operatorUid ?? ''),
|
||||
userUin: resolveUidToUin(ctx.identity, mute.groupUin ?? 0, mute.data.state.targetUid ?? ''),
|
||||
duration: duration === 0xFFFFFFFF ? 0x7FFFFFFF : duration,
|
||||
};
|
||||
return [ev];
|
||||
@@ -69,8 +68,8 @@ function decodeGroupRecall(ctx: MsgPushContext): QQEventVariant[] {
|
||||
selfUin: ctx.selfUin,
|
||||
groupId: notify.groupUin ?? 0,
|
||||
operatorUin: resolveUidToUin(ctx.identity, notify.groupUin ?? 0,
|
||||
notify.recall.operatorUid || notify.operatorUid || '', ctx.fromUin),
|
||||
authorUin: resolveUidToUin(ctx.identity, notify.groupUin ?? 0, recalled.authorUid ?? '', ctx.fromUin),
|
||||
notify.recall.operatorUid || notify.operatorUid || ''),
|
||||
authorUin: resolveUidToUin(ctx.identity, notify.groupUin ?? 0, recalled.authorUid ?? ''),
|
||||
msgSeq: recalled.sequence ?? 0,
|
||||
};
|
||||
return [ev];
|
||||
@@ -89,8 +88,8 @@ function decodeGroupGreyTip(ctx: MsgPushContext): QQEventVariant[] {
|
||||
time: ctx.head.timestamp,
|
||||
selfUin: ctx.selfUin,
|
||||
groupId: notify.groupUin ?? 0,
|
||||
userUin: resolveUidToUin(ctx.identity, notify.groupUin ?? 0, actor, parseU64OrZero(actor)),
|
||||
targetUin: resolveUidToUin(ctx.identity, notify.groupUin ?? 0, target, parseU64OrZero(target)),
|
||||
userUin: resolveUidToUin(ctx.identity, notify.groupUin ?? 0, actor),
|
||||
targetUin: resolveUidToUin(ctx.identity, notify.groupUin ?? 0, target),
|
||||
action: findTemplateValue(templates, 'action_str', 'alt_str1'),
|
||||
suffix: findTemplateValue(templates, 'suffix_str'),
|
||||
actionImgUrl: findTemplateValue(templates, 'action_img_url'),
|
||||
@@ -111,7 +110,7 @@ function decodeGroupEssence(ctx: MsgPushContext): QQEventVariant[] {
|
||||
selfUin: ctx.selfUin,
|
||||
groupId: essence.groupUin ?? notify.groupUin ?? 0,
|
||||
senderUin: essence.memberUin ?? 0,
|
||||
operatorUin: essence.operatorUin ?? ctx.fromUin,
|
||||
operatorUin: essence.operatorUin ?? 0,
|
||||
msgSeq: essence.msgSequence ?? essence.msgSequence2 ?? notify.msgSequence ?? 0,
|
||||
random: essence.random ?? 0,
|
||||
set: setFlag === 1,
|
||||
@@ -200,7 +199,7 @@ function decodeGroupName(ctx: MsgPushContext): QQEventVariant[] {
|
||||
// Operator is a group member → resolves from the roster. Fall back to 0
|
||||
// (not ctx.fromUin, which on a 0x2DC push is the group id) so an
|
||||
// unresolved operator never surfaces the group id as user_id.
|
||||
operatorUin: resolveUidToUin(ctx.identity, groupId, notify?.operatorUid ?? '', 0),
|
||||
operatorUin: resolveUidToUin(ctx.identity, groupId, notify?.operatorUid ?? ''),
|
||||
name,
|
||||
};
|
||||
return [ev];
|
||||
@@ -235,7 +234,7 @@ function decodeGroupMsgEmojiLike(ctx: MsgPushContext): QQEventVariant[] {
|
||||
time: ctx.head.timestamp,
|
||||
selfUin: ctx.selfUin,
|
||||
groupId,
|
||||
operatorUin: resolveUidToUin(ctx.identity, groupId, operatorUid, ctx.fromUin),
|
||||
operatorUin: resolveUidToUin(ctx.identity, groupId, operatorUid),
|
||||
operatorUid,
|
||||
msgSeq,
|
||||
emojiId,
|
||||
|
||||
@@ -19,7 +19,7 @@ export const decodeGroupAdmin: MsgPushDecoder = (ctx) => {
|
||||
if (!adminUid) return [];
|
||||
const groupId = admin.groupUin ?? 0;
|
||||
const set = !!enableUid;
|
||||
const userUin = resolveUidToUin(ctx.identity, groupId, adminUid, ctx.fromUin);
|
||||
const userUin = resolveUidToUin(ctx.identity, groupId, adminUid);
|
||||
|
||||
// Keep the in-memory member cache in step with the promotion/demotion.
|
||||
// `get_group_member_info` serves straight from this cache on its
|
||||
|
||||
@@ -15,15 +15,8 @@ export const decodeGroupJoinRequest: MsgPushDecoder = (ctx) => {
|
||||
time: ctx.head.timestamp,
|
||||
selfUin: ctx.selfUin,
|
||||
groupId: join.groupUin ?? 0,
|
||||
// Strangers (not in our cache, not yet group members) won't resolve
|
||||
// here — pass 0 instead of ctx.fromUin (which on a group-scoped push
|
||||
// IS the group's own uin, so falling back to it produces a bogus
|
||||
// `fromUin === groupId` collision). The packet-pipeline's pre-
|
||||
// dispatch hook does an async UID-form FetchUserProfile lookup to
|
||||
// fill in the uin + nickname before the event is emitted — same
|
||||
// shape as Lagrange's flow at
|
||||
// `dev/Lagrange.Core/.../MessagingLogic.cs:215-224`.
|
||||
fromUin: resolveUidToUin(ctx.identity, join.groupUin ?? 0, join.targetUid ?? '', 0),
|
||||
// Strangers stay unresolved here. Pipeline fills UIN via Identity.resolveUin.
|
||||
fromUin: resolveUidToUin(ctx.identity, join.groupUin ?? 0, join.targetUid ?? ''),
|
||||
fromUid: join.targetUid ?? '',
|
||||
subType: 'add',
|
||||
message: '',
|
||||
@@ -41,7 +34,7 @@ export const decodeGroupInvitation: MsgPushDecoder = (ctx) => {
|
||||
time: ctx.head.timestamp,
|
||||
selfUin: ctx.selfUin,
|
||||
groupId: inner.groupUin ?? 0,
|
||||
fromUin: resolveUidToUin(ctx.identity, inner.groupUin ?? 0, inner.invitorUid ?? '', 0),
|
||||
fromUin: resolveUidToUin(ctx.identity, inner.groupUin ?? 0, inner.invitorUid ?? ''),
|
||||
fromUid: inner.invitorUid ?? '',
|
||||
subType: 'invite',
|
||||
message: '',
|
||||
@@ -58,7 +51,7 @@ export const decodeGroupInvite: MsgPushDecoder = (ctx) => {
|
||||
time: ctx.head.timestamp,
|
||||
selfUin: ctx.selfUin,
|
||||
groupId: invite.groupUin ?? 0,
|
||||
fromUin: resolveUidToUin(ctx.identity, invite.groupUin ?? 0, invite.invitorUid ?? '', 0),
|
||||
fromUin: resolveUidToUin(ctx.identity, invite.groupUin ?? 0, invite.invitorUid ?? ''),
|
||||
fromUid: invite.invitorUid ?? '',
|
||||
subType: 'invite',
|
||||
message: '',
|
||||
|
||||
@@ -31,8 +31,8 @@ export const decodeGroupMemberJoin: MsgPushDecoder = (ctx) => {
|
||||
time: ctx.head.timestamp,
|
||||
selfUin: ctx.selfUin,
|
||||
groupId,
|
||||
userUin: resolveUidToUin(ctx.identity, groupId, userUid, 0),
|
||||
operatorUin: resolveUidToUin(ctx.identity, groupId, operatorUid, 0),
|
||||
userUin: resolveUidToUin(ctx.identity, groupId, userUid),
|
||||
operatorUin: resolveUidToUin(ctx.identity, groupId, operatorUid),
|
||||
userUid,
|
||||
operatorUid,
|
||||
joinType: joinTypeFromOperationType(change.decreaseType ?? 0),
|
||||
@@ -66,7 +66,7 @@ export const decodeGroupMemberLeave: MsgPushDecoder = (ctx) => {
|
||||
const dt = change.decreaseType ?? 0;
|
||||
const groupId = change.groupUin ?? 0;
|
||||
const userUid = change.memberUid ?? '';
|
||||
const userUin = resolveUidToUin(ctx.identity, groupId, userUid, 0);
|
||||
const userUin = resolveUidToUin(ctx.identity, groupId, userUid);
|
||||
|
||||
let operatorUid: string;
|
||||
let operatorUin: number;
|
||||
@@ -83,7 +83,7 @@ export const decodeGroupMemberLeave: MsgPushDecoder = (ctx) => {
|
||||
operatorUid = dt === 3
|
||||
? decodeNestedOperatorUid(operatorBytes, 'group member decrease type=3')
|
||||
: decodeGroupChangeOperatorUid(operatorBytes, `group member decrease type=${dt}`);
|
||||
operatorUin = resolveUidToUin(ctx.identity, groupId, operatorUid, 0);
|
||||
operatorUin = resolveUidToUin(ctx.identity, groupId, operatorUid);
|
||||
}
|
||||
const ev: GroupMemberLeave = {
|
||||
kind: 'group_member_leave',
|
||||
@@ -119,7 +119,7 @@ export const decodeGroupSelfJoined: MsgPushDecoder = (ctx) => {
|
||||
groupId,
|
||||
userUin: ctx.selfUin,
|
||||
userUid: ctx.identity.selfUid ?? '',
|
||||
operatorUin: resolveUidToUin(ctx.identity, groupId, operatorUid, 0),
|
||||
operatorUin: resolveUidToUin(ctx.identity, groupId, operatorUid),
|
||||
operatorUid,
|
||||
};
|
||||
return [ev];
|
||||
|
||||
@@ -62,28 +62,27 @@ export function decompressData(
|
||||
return { ok: true, text: Buffer.from(data).toString('utf8'), outputBytes: data.length };
|
||||
}
|
||||
|
||||
export function isNumericUin(value: string): boolean {
|
||||
return value.length > 0 && /^\d+$/.test(value);
|
||||
}
|
||||
|
||||
export function parseU64OrZero(value: string): number {
|
||||
if (!value) return 0;
|
||||
const n = parseInt(value, 10);
|
||||
return isNaN(n) ? 0 : n;
|
||||
}
|
||||
|
||||
// Cascades group-scoped lookup → in-memory map → SQLite.
|
||||
// No network fallback on the parse hot path: missing identities fall back to
|
||||
// `fallback` and downstream events drive a roster refresh asynchronously.
|
||||
export function resolveUidToUin(identity: IdentityService, groupId: number, uid: string, fallback = 0): number {
|
||||
if (!uid) return fallback;
|
||||
if (isNumericUin(uid)) {
|
||||
const n = parseInt(uid, 10);
|
||||
if (!isNaN(n)) return n;
|
||||
}
|
||||
const uin = identity.findUinByUid(uid, groupId || undefined);
|
||||
if (uin !== null) return uin;
|
||||
return fallback;
|
||||
/** Sync Identity lookup. Miss is unresolved (0). Decoder must not invent a UIN. */
|
||||
export function resolveUidToUin(identity: IdentityService, groupId: number, uid: string): number {
|
||||
if (!uid) return 0;
|
||||
return identity.findUinByUid(uid, groupId || undefined) ?? 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* C2C routing hop. Prefer Identity on the hop UID; otherwise use that hop's
|
||||
* own wire UIN. This is not a fallback that assigns an unrelated header UIN
|
||||
* to a different UID.
|
||||
*/
|
||||
export function c2cRoutingUin(identity: IdentityService, uid: string, wireUin: number): number {
|
||||
const resolved = resolveUidToUin(identity, 0, uid);
|
||||
if (resolved > 0) return resolved;
|
||||
return wireUin > 0 ? wireUin : 0;
|
||||
}
|
||||
|
||||
const OPERATOR_BYTES_PREVIEW_LENGTH = 32;
|
||||
|
||||
@@ -46,16 +46,6 @@ export interface PacketPipelineDeps {
|
||||
* and `refreshGroupList` was false).
|
||||
*/
|
||||
refreshMemberCache(groupId: number, refreshGroupList: boolean, forceMemberList: boolean): Promise<boolean>;
|
||||
/**
|
||||
* Resolve a stranger profile by UID — used to fill in the requester's
|
||||
* uin + nickname on group-join-request and friend-request events
|
||||
* where the push only carries a uid. Mirrors Lagrange's
|
||||
* `FetchUserInfoEvent.Create(targetUid)` path
|
||||
* (`dev/Lagrange.Core/.../MessagingLogic.cs:215-224`). Returns null
|
||||
* on lookup failure so the dispatch path can proceed with the bare
|
||||
* uid-only event.
|
||||
*/
|
||||
resolveStrangerProfile(uid: string): Promise<{ uin: number; nickname: string } | null>;
|
||||
/**
|
||||
* Resolve the verify message ("postscript") + server sequence number
|
||||
* for a pending group-join / group-invite. The OIDB push only
|
||||
@@ -459,34 +449,28 @@ export class IncomingPacketPipeline {
|
||||
// Record the requester's identity up-front (synchronously), mirroring the
|
||||
// friend_request path — uid-bearing group_invites take this async branch
|
||||
// and would otherwise never store the inviter's uid↔uin when the uin is
|
||||
// already known (needsProfile=false). uin equal to the group's own uin is
|
||||
// the legacy decoder-pollution signature → pass 0 so the map write is
|
||||
// skipped (rememberUidUin short-circuits on uin <= 0).
|
||||
// already known (needsProfile=false).
|
||||
this.deps.identity.rememberRequestIdentity({
|
||||
groupId: event.groupId,
|
||||
uid,
|
||||
uin: event.fromUin > 0 && event.fromUin !== event.groupId ? event.fromUin : 0,
|
||||
uin: event.fromUin > 0 ? event.fromUin : 0,
|
||||
source: 'group_request',
|
||||
});
|
||||
|
||||
const subType = event.subType === 'invite' ? 'invite' : 'add';
|
||||
// ALWAYS fetch the verify comment (it's never in the push). Resolve
|
||||
// the UID→UIN profile only when the requester isn't already known —
|
||||
// `fromUin === groupId` is the legacy cache-pollution signature
|
||||
// (decoder fell back to the group's own uin) and must force a
|
||||
// re-resolve so the cache self-heals. The two are independent OIDB
|
||||
// calls (0xFE1_2 profile + 0x10C0 request queue); `Promise.allSettled`
|
||||
// so a flake on one path can't kill the other.
|
||||
const needsProfile = event.fromUin <= 0 || (event.groupId > 0 && event.fromUin === event.groupId);
|
||||
// ALWAYS fetch the verify comment (it's never in the push). UID→UIN
|
||||
// waits only when the requester is still unresolved. Comment and
|
||||
// identity are independent; `Promise.allSettled` so a flake on one
|
||||
// path cannot kill the other.
|
||||
const needsProfile = event.fromUin <= 0;
|
||||
const [profileR, requestR] = await Promise.allSettled([
|
||||
needsProfile ? this.deps.resolveStrangerProfile(uid) : Promise.resolve(null),
|
||||
needsProfile ? this.deps.identity.resolveUin(uid, event.groupId) : Promise.resolve(null),
|
||||
this.deps.resolveGroupJoinRequest(event.groupId, uid, subType),
|
||||
]);
|
||||
|
||||
if (needsProfile) {
|
||||
if (profileR.status === 'fulfilled' && profileR.value && profileR.value.uin > 0) {
|
||||
event.fromUin = profileR.value.uin;
|
||||
// uin was unknown/polluted at entry; now resolved → self-heal the map.
|
||||
if (profileR.status === 'fulfilled' && profileR.value !== null && profileR.value > 0) {
|
||||
event.fromUin = profileR.value;
|
||||
this.deps.identity.rememberRequestIdentity({
|
||||
groupId: event.groupId,
|
||||
uid,
|
||||
@@ -560,15 +544,13 @@ export class IncomingPacketPipeline {
|
||||
|
||||
private async prepareGroupMemberJoinIdentity(event: Extract<QQEventVariant, { kind: 'group_member_join' }>): Promise<boolean> {
|
||||
this.resolveMemberIdentityFromCache(event);
|
||||
if (event.userUin > 0 || !event.userUid || event.groupId <= 0) return false;
|
||||
if (event.userUin > 0 || !event.userUid) return false;
|
||||
|
||||
const refreshed = await this.deps.refreshMemberCache(
|
||||
event.groupId,
|
||||
!this.deps.identity.findGroup(event.groupId) || this.isSelfMemberIdentity(event.userUin, event.userUid),
|
||||
true,
|
||||
);
|
||||
const uin = await this.deps.identity.resolveUin(event.userUid, event.groupId);
|
||||
if (uin !== null) event.userUin = uin;
|
||||
this.resolveMemberIdentityFromCache(event);
|
||||
return refreshed;
|
||||
// Roster refresh stays a post-dispatch side-effect, not the UIN hop.
|
||||
return false;
|
||||
}
|
||||
|
||||
private resolveMemberIdentityFromCache(event: GroupMemberIdentityEvent): void {
|
||||
|
||||
Reference in new issue
Block a user