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:
20 files changed
+157
-75
No files matched your search
@@ -5,7 +5,6 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
vi.mock('../../src/bridge/bridge-oidb', () => ({
|
||||
sendOidbAndCheck: vi.fn(async () => undefined),
|
||||
sendOidbAndDecode: vi.fn(async () => ({})),
|
||||
resolveUserUid: vi.fn(async () => 'resolved-uid'),
|
||||
makeOidbRequest: vi.fn(() => new Uint8Array(0)),
|
||||
}));
|
||||
|
||||
@@ -17,13 +16,12 @@ describe('actions/group-admin', () => {
|
||||
beforeEach(() => {
|
||||
vi.mocked(oidb.sendOidbAndCheck).mockClear();
|
||||
vi.mocked(oidb.sendOidbAndDecode).mockClear();
|
||||
vi.mocked(oidb.resolveUserUid).mockClear();
|
||||
});
|
||||
|
||||
it('muteGroupMember resolves UID and dispatches 0x1253_1', async () => {
|
||||
const bridge = mockBridge();
|
||||
await admin.muteGroupMember(bridge as any, 12345, 67890, 600);
|
||||
expect(oidb.resolveUserUid).toHaveBeenCalledWith(bridge, 67890, 12345);
|
||||
expect(bridge.resolveUserUid).toHaveBeenCalledWith(67890, 12345);
|
||||
expect(oidb.sendOidbAndCheck).toHaveBeenCalledOnce();
|
||||
const args = vi.mocked(oidb.sendOidbAndCheck).mock.calls[0]!;
|
||||
expect(args[1]).toBe('OidbSvcTrpcTcp.0x1253_1');
|
||||
@@ -53,7 +51,7 @@ describe('actions/group-admin', () => {
|
||||
it('kickGroupMember resolves UID per-group and forwards reject + reason', async () => {
|
||||
const bridge = mockBridge();
|
||||
await admin.kickGroupMember(bridge as any, 12345, 67890, true, 'bad behaviour');
|
||||
expect(oidb.resolveUserUid).toHaveBeenCalledWith(bridge, 67890, 12345);
|
||||
expect(bridge.resolveUserUid).toHaveBeenCalledWith(67890, 12345);
|
||||
expect(vi.mocked(oidb.sendOidbAndCheck).mock.calls[0]![4]).toMatchObject({
|
||||
groupUin: 12345,
|
||||
targetUid: 'resolved-uid',
|
||||
@@ -64,12 +62,12 @@ describe('actions/group-admin', () => {
|
||||
|
||||
it('kickGroupMembers resolves each UID in parallel', async () => {
|
||||
const bridge = mockBridge();
|
||||
vi.mocked(oidb.resolveUserUid)
|
||||
vi.mocked(bridge.resolveUserUid)
|
||||
.mockResolvedValueOnce('uid-a')
|
||||
.mockResolvedValueOnce('uid-b');
|
||||
|
||||
await admin.kickGroupMembers(bridge as any, 12345, [11, 22], false);
|
||||
expect(oidb.resolveUserUid).toHaveBeenCalledTimes(2);
|
||||
expect(bridge.resolveUserUid).toHaveBeenCalledTimes(2);
|
||||
const payload: any = vi.mocked(oidb.sendOidbAndCheck).mock.calls[0]![4];
|
||||
expect(payload.targetUids).toEqual(['uid-a', 'uid-b']);
|
||||
expect(payload.rejectAddRequest).toBe(0);
|
||||
|
||||
Reference in new issue
Block a user