refactor(identity): absorb QQInfo into IdentityService

QQInfo's in-memory state (self identity, friends, group rosters,
profile cache) and read methods (findFriend / findGroup /
findGroupMember / findUserProfile / nickname / uin / selfProfile) now
live directly on IdentityService. The QQInfo class is gone; its
interfaces stay in `qq-info.ts` as plain types shared across the
remember*/find* surface.

This eliminates a long-standing duplication: every observation used to
maintain both QQInfo's in-memory structures and IdentityService's
SQLite mirror in parallel, with the uidByUin/uinByUid Maps tracked
separately. With one Module owning all three layers, every remember*
hydrates one set of structures and `loadSnapshot` repopulates the
in-memory uid↔uin index from SQLite on startup — closing the cold-cache
gap that previously forced findUidByUin to fall through to a SQLite
query after every restart.

Knock-on changes:
  - `Bridge` no longer holds a QQInfo; constructor takes an
    `IdentityService`. The CmdParser signature on the cmd dispatch
    table now passes `IdentityService` to parsers.
  - `msg-push-handler.ts` drops its private `resolveUidToUin(qqInfo, …)`
    helper that bypassed IdentityService's cascade — the parser hot
    path now reads through `identity.findUinByUid(uid, groupId)` and
    benefits from the O(1) `uinByUid` map even on freshly-loaded
    sessions.
  - `BridgeManager`'s session-started callback drops the QQInfo
    parameter; OneBotInstance no longer carries a `qqInfo` field and
    exposes a `nickname` getter for the WebUI listing.
  - `contact-actions` and the per-theme bridge action files stop
    importing QQInfo; they read everything via `bridge.identity.*`.
This commit is contained in:
DrSmoothl committed 2026-05-15 00:44:01 +08:00
1 parent 030336a25c
commit ac10c663f1
27 files changed
+363 -428

No files matched your search

+4 -4
View File
@@ -29,7 +29,7 @@ async function buildForwardPushBody(
bridge: Bridge,
node: ForwardNodePayload,
): Promise<Record<string, unknown>> {
const fromUin = node.userUin > 0 ? node.userUin : toInt(bridge.qqInfo.uin);
const fromUin = node.userUin > 0 ? node.userUin : toInt(bridge.identity.uin);
if (fromUin <= 0) throw new Error('forward node user uin is invalid');
const nickname = node.nickname.trim() || String(fromUin);
@@ -41,7 +41,7 @@ async function buildForwardPushBody(
return {
responseHead: {
fromUin,
toUid: bridge.qqInfo.selfUid ?? '',
toUid: bridge.identity.selfUid ?? '',
forward: {
friendName: nickname,
},
@@ -173,14 +173,14 @@ export async function fetchForwardNodes(bridge: Bridge, resId: string): Promise<
const wrapped = protoEncode({ message: msgBody }, PushMsgSchema);
const pkt: PacketInfo = {
pid: 0,
uin: bridge.qqInfo.uin,
uin: bridge.identity.uin,
serviceCmd: 'trpc.msg.olpush.OlPushService.MsgPush',
seqId: 0,
retCode: 0,
fromClient: false,
body: wrapped,
};
const events = parseMsgPush(pkt, bridge.qqInfo);
const events = parseMsgPush(pkt, bridge.identity);
const event = events.find(e =>
e.kind === 'friend_message' || e.kind === 'group_message' || e.kind === 'temp_message');
if (!event) continue;
@@ -123,7 +123,7 @@ export async function getGroupAtAllRemain(
basic1: 1,
basic2: 2,
basic3: 1,
uin: BigInt(bridge.qqInfo.uin),
uin: BigInt(bridge.identity.uin),
groupId: BigInt(groupId),
type: 0,
};
@@ -327,7 +327,7 @@ export async function uploadGroupFile(
if (!fileId) throw new Error('group file upload response missing file_id');
if (!upload.boolFileExist && uploadFile) {
const senderUin = toInt(bridge.qqInfo.uin);
const senderUin = toInt(bridge.identity.uin);
if (senderUin <= 0) throw new Error('invalid self uin for group file upload');
const uploadHost = (typeof upload.uploadIp === 'string' && upload.uploadIp)
@@ -369,16 +369,16 @@ export async function uploadPrivateFile(
if (!loaded.bytes.length) throw new Error('private file is empty');
const targetUid = await bridge.resolveUserUid(userId);
let selfUid = bridge.qqInfo.selfUid;
let selfUid = bridge.identity.selfUid;
if (!selfUid) {
const selfUin = toInt(bridge.qqInfo.uin);
const selfUin = toInt(bridge.identity.uin);
if (selfUin > 0) {
selfUid = await bridge.resolveUserUid(selfUin);
}
}
if (!selfUid) throw new Error('self uid is unavailable');
const senderUin = toInt(bridge.qqInfo.uin);
const senderUin = toInt(bridge.identity.uin);
if (senderUin <= 0) throw new Error('invalid self uin for private file upload');
const fileName = normalizeUploadFileName(name, loaded.fileName);
@@ -489,7 +489,7 @@ export async function fetchGroupFiles(bridge: Bridge, groupId: number, folderId
if (type === 1 && item?.fileInfo) {
const file = item.fileInfo;
const uploader = toInt(file.uploaderUin);
const cached = bridge.qqInfo.findGroupMember(groupId, uploader);
const cached = bridge.identity.findGroupMember(groupId, uploader);
files.push({
fileId: typeof file.fileId === 'string' ? file.fileId : '',
fileName: typeof file.fileName === 'string' ? file.fileName : '',
@@ -508,7 +508,7 @@ export async function fetchGroupFiles(bridge: Bridge, groupId: number, folderId
} else if (type === 2 && item?.folderInfo) {
const folder = item.folderInfo;
const creator = toInt(folder.creatorUin);
const cached = bridge.qqInfo.findGroupMember(groupId, creator);
const cached = bridge.identity.findGroupMember(groupId, creator);
folders.push({
folderId: typeof folder.folderId === 'string' ? folder.folderId : '',
folderName: typeof folder.folderName === 'string' ? folder.folderName : '',
+1 -1
View File
@@ -155,7 +155,7 @@ export async function sendGroupSign(
) {
const req = {
signInInfo: {
uin: String(bridge.qqInfo.uin),
uin: String(bridge.identity.uin),
groupId: String(groupId),
version: '9.0.90',
},
+5 -5
View File
@@ -60,7 +60,7 @@ export async function setProfile(
nickname?: string,
personalNote?: string,
): Promise<void> {
const uin = BigInt(bridge.qqInfo.uin);
const uin = BigInt(bridge.identity.uin);
const stringProfiles: any[] = [];
const intProfiles: any[] = [];
@@ -96,7 +96,7 @@ export async function setSelfLongNick(
longNick: string,
) {
const req = {
uin: BigInt(bridge.qqInfo.uin),
uin: BigInt(bridge.identity.uin),
profile: {
tag: 102,
value: String(longNick),
@@ -220,7 +220,7 @@ export async function getUnidirectionalFriendList(
bridge: Bridge,
) {
const reqObj = {
uint64_uin: String(bridge.qqInfo.uin),
uint64_uin: String(bridge.identity.uin),
uint64_top: 0,
uint32_req_num: 99,
bytes_cookies: '',
@@ -251,7 +251,7 @@ export async function getUnidirectionalFriendList(
export async function fetchCustomFace(bridge: Bridge, count: number = 10): Promise<string[]> {
const req = {
inner: { field1: 1, osVersion: '10.0.26200', qqVersion: '9.9.28-46928' },
uin: BigInt(bridge.qqInfo.uin),
uin: BigInt(bridge.identity.uin),
field3: 1,
field6: 1,
};
@@ -265,5 +265,5 @@ export async function fetchCustomFace(bridge: Bridge, count: number = 10): Promi
throw new Error(`fetch custom face error: ${(resp as any)?.message || 'unknown'}`);
}
const faceIds = (resp as any).item?.faceIds || [];
return faceIds.slice(0, count).map((id: string) => `https://p.qpic.cn/qq_expression/${bridge.qqInfo.uin}/${id}/0`);
return faceIds.slice(0, count).map((id: string) => `https://p.qpic.cn/qq_expression/${bridge.identity.uin}/${id}/0`);
}
+5 -4
View File
@@ -36,14 +36,15 @@ export function ensureRetCodeZero(operation: string, code: unknown, msg: unknown
}
/**
* Look up the bot's own UID. Cached on QQInfo when warmed up, but
* forward/profile actions need a fast path before warmup completes.
* Look up the bot's own UID. Cached on Identity once warmup populates
* `selfProfile`; forward/profile actions need this fast path before
* warmup completes.
*/
export async function resolveSelfUid(bridge: Bridge): Promise<string> {
let selfUid = bridge.qqInfo.selfUid;
let selfUid = bridge.identity.selfUid;
if (selfUid) return selfUid;
const selfUin = toInt(bridge.qqInfo.uin);
const selfUin = toInt(bridge.identity.uin);
if (selfUin <= 0) {
throw new Error('self uid is unavailable');
}