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

+6 -9
View File
@@ -11,14 +11,13 @@ import { vi } from 'vitest';
import type { SendPacketResult } from '../../src/protocol/packet-sender';
export interface MockBridge {
qqInfo: {
identity: {
uin: string;
selfUid: string;
findGroupMember: ReturnType<typeof vi.fn>;
};
identity: {
nickname: string;
findUidByUin: ReturnType<typeof vi.fn>;
findUinByUid: ReturnType<typeof vi.fn>;
findGroupMember: ReturnType<typeof vi.fn>;
};
sendRawPacket: ReturnType<typeof vi.fn>;
fetchFriendList: ReturnType<typeof vi.fn>;
@@ -36,15 +35,13 @@ export function mockBridge(overrides: Partial<MockBridge> = {}): MockBridge {
responseData: Buffer.alloc(0),
};
return {
qqInfo: {
identity: {
uin: '10001',
selfUid: 'self-uid',
findGroupMember: vi.fn(() => null),
...(overrides.qqInfo ?? {}),
} as MockBridge['qqInfo'],
identity: {
nickname: 'self-nick',
findUidByUin: vi.fn(() => 'cached-uid'),
findUinByUid: vi.fn(() => 0),
findGroupMember: vi.fn(() => null),
...(overrides.identity ?? {}),
} as MockBridge['identity'],
sendRawPacket: vi.fn(async () => defaultResp),
@@ -100,7 +100,14 @@ describe('actions/group-file', () => {
it('uploadPrivateFile resolves both target + self UID before OIDB call', async () => {
const bridge = mockBridge({
qqInfo: { uin: '10001', selfUid: '', findGroupMember: vi.fn(() => null) },
identity: {
uin: '10001',
selfUid: '',
nickname: 'self-nick',
findUidByUin: vi.fn(() => 'cached-uid'),
findUinByUid: vi.fn(() => 0),
findGroupMember: vi.fn(() => null),
},
});
vi.mocked(bridge.resolveUserUid)
.mockResolvedValueOnce('target-uid') // target user