refactor(identity): consolidate UID resolution behind IdentityService

Pull the cache→DB→network-fetch fallback cascade for UIN→UID translation
into a single async `resolveUid` on IdentityService, and drop the
duplicated `resolveUserUid` helper that used to live in bridge-oidb. Bridge
injects itself as the IdentityFetcher post-construction so the network
fallback runs through the same OIDB profile fetch the helper used.

Each action module's `resolveUserUid(bridge, uin, groupId?)` call becomes
`bridge.resolveUserUid(uin, groupId?)` — same signature on Bridge, but
internally it now goes through `identity.resolveUid` so future changes
(retry, coalescing, alternative resolvers) only need to land in one place.

This is part 1 of the IdentityService deepening (RoadMap item 1). The
QQInfo bypass in msg-push-handler and the broader QQInfo absorption land
in the follow-up commit.
This commit is contained in:
DrSmoothl committed 2026-05-15 00:32:59 +08:00
1 parent 2e4dd9b01e
commit 030336a25c
20 files changed
+157 -75

No files matched your search

+1 -23
View File
@@ -1,4 +1,4 @@
// OIDB protocol helpers -- encode requests, send+check, send+decode, UID resolution.
// OIDB protocol helpers -- encode requests, send+check, send+decode.
import type { Bridge } from './bridge';
import type { ProtoSchema } from '../protobuf/decode';
@@ -67,25 +67,3 @@ export async function sendOidbAndDecode<T>(
return (resp as any).body as T;
}
/**
* Resolve a UIN to a UID string, using cache or fetching as needed.
* Mirrors C++ resolve_user_uid_for_action.
*/
export async function resolveUserUid(bridge: Bridge, uin: number, groupId?: number): Promise<string> {
// Try group member first
if (groupId !== undefined) {
const uid = bridge.identity.findUidByUin(uin, groupId);
if (uid) return uid;
// Try fetching member list
try { await bridge.fetchGroupMemberList(groupId); } catch { /* ignore */ }
const uid2 = bridge.identity.findUidByUin(uin, groupId);
if (uid2) return uid2;
}
// Try cached
const uid = bridge.identity.findUidByUin(uin);
if (uid) return uid;
// Fetch profile
const profile = await bridge.fetchUserProfile(uin);
if (profile.uid) return profile.uid;
throw new Error(`failed to resolve UID for UIN ${uin}`);
}