fix(core): restore group remarks in queries
Request and retain the group remark information needed by group list and group detail queries while preserving the existing safeguards for large rosters. Synchronize confirmed group remark changes with the local identity roster and persistent cache. Remote failures leave local state untouched, and missing roster entries remain observable without creating phantom groups. Add regression coverage for query mapping, request scope, persistence, failed updates, unknown groups, and closed identity stores. Fixes #304
This commit is contained in:
10 files changed
+173
-10
No files matched your search
@@ -129,6 +129,7 @@ export interface MockBridge {
|
||||
findUinByUid: ReturnType<typeof vi.fn>;
|
||||
findGroupMember: ReturnType<typeof vi.fn>;
|
||||
updateFriendRemark: ReturnType<typeof vi.fn>;
|
||||
updateGroupRemark: ReturnType<typeof vi.fn>;
|
||||
forgetGroup: ReturnType<typeof vi.fn>;
|
||||
};
|
||||
events: { emit: ReturnType<typeof vi.fn> };
|
||||
@@ -162,6 +163,7 @@ export function mockBridge(overrides: Partial<MockBridge> = {}): MockBridge {
|
||||
findUinByUid: vi.fn(() => 0),
|
||||
findGroupMember: vi.fn(() => null),
|
||||
updateFriendRemark: vi.fn(() => true),
|
||||
updateGroupRemark: vi.fn(() => true),
|
||||
forgetGroup: vi.fn(),
|
||||
...(overrides.identity ?? {}),
|
||||
} as MockBridge['identity'],
|
||||
|
||||
@@ -8,6 +8,7 @@ import type {
|
||||
OidbFriendCategory,
|
||||
OidbRobotUinRangeResponse,
|
||||
OidbSvcTrpcTcp0xFD4_1Response,
|
||||
OidbSvcTrpcTcp0xFE5_2Response,
|
||||
OidbSvcTrpcTcp0xFE7_3Response,
|
||||
} from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
@@ -86,6 +87,18 @@ function memberListPacket(body: OidbSvcTrpcTcp0xFE7_3Response): SendPacketResult
|
||||
};
|
||||
}
|
||||
|
||||
function groupListPacket(body: OidbSvcTrpcTcp0xFE5_2Response): SendPacketResult {
|
||||
return {
|
||||
success: true,
|
||||
gotResponse: true,
|
||||
errorCode: 0,
|
||||
errorMessage: '',
|
||||
responseData: Buffer.from(
|
||||
protobuf_encode<OidbBase<OidbSvcTrpcTcp0xFE5_2Response>>({ body }),
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
function apiForPages(pages: OidbSvcTrpcTcp0xFD4_1Response[]) {
|
||||
let index = 0;
|
||||
const sendRawPacket = vi.fn(async (
|
||||
@@ -131,6 +144,34 @@ function apiForCategoryChange(roster: OidbSvcTrpcTcp0xFD4_1Response) {
|
||||
return { api, sendRawPacket };
|
||||
}
|
||||
|
||||
describe('apis/contacts / group roster', () => {
|
||||
it('maps QQ group remarks into the returned and remembered roster', async () => {
|
||||
const rememberGroups = vi.fn();
|
||||
const sendRawPacket = vi.fn(async () => groupListPacket({
|
||||
groups: [{
|
||||
groupUin: 123456789,
|
||||
info: { groupName: 'Project', memberCount: 42, memberMax: 500 },
|
||||
customInfo: { remark: ' My Project ' },
|
||||
}],
|
||||
}));
|
||||
const api = new ContactsApi({
|
||||
sendRawPacket,
|
||||
identity: { rememberGroups },
|
||||
} as any);
|
||||
|
||||
const groups = await api.fetchGroupList();
|
||||
|
||||
expect(groups).toEqual([expect.objectContaining({
|
||||
groupId: 123456789,
|
||||
groupName: 'Project',
|
||||
remark: ' My Project ',
|
||||
memberCount: 42,
|
||||
memberMax: 500,
|
||||
})]);
|
||||
expect(rememberGroups).toHaveBeenCalledWith(groups);
|
||||
});
|
||||
});
|
||||
|
||||
describe('apis/contacts / categorized friend roster', () => {
|
||||
it('keeps fetchFriendList flat while traversing cookie pages', async () => {
|
||||
const cookie = Uint8Array.from([0x01]);
|
||||
|
||||
@@ -329,6 +329,7 @@ describe('apis/group-file', () => {
|
||||
findUinByUid: vi.fn(() => 0),
|
||||
findGroupMember: vi.fn(() => null),
|
||||
updateFriendRemark: vi.fn(() => true),
|
||||
updateGroupRemark: vi.fn(() => true),
|
||||
forgetGroup: vi.fn(),
|
||||
},
|
||||
});
|
||||
|
||||
@@ -238,6 +238,37 @@ describe('IdentityService', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('keeps exact group remark updates after reopening the persistent cache', () => {
|
||||
const dbPath = tempDbPath('update-group-remark');
|
||||
const remark = ' project group ';
|
||||
|
||||
{
|
||||
const identity = new IdentityService(SELF_UIN, dbPath);
|
||||
identity.rememberGroups([{ ...makeGroup(), remark: 'old-remark' }]);
|
||||
|
||||
expect(identity.updateGroupRemark(GROUP_ID, remark)).toBe(true);
|
||||
expect(identity.findGroup(GROUP_ID)?.remark).toBe(remark);
|
||||
identity.close();
|
||||
}
|
||||
|
||||
{
|
||||
const identity = new IdentityService(SELF_UIN, dbPath);
|
||||
expect(identity.findGroup(GROUP_ID)?.remark).toBe(remark);
|
||||
identity.close();
|
||||
}
|
||||
});
|
||||
|
||||
it('does not invent a group while applying a remark update', () => {
|
||||
const identity = IdentityService.memory(SELF_UIN);
|
||||
identity.rememberGroups([makeGroup()]);
|
||||
|
||||
expect(identity.updateGroupRemark(987654321, 'unknown')).toBe(false);
|
||||
expect(identity.groups).toHaveLength(1);
|
||||
expect(identity.findGroup(GROUP_ID)?.remark).toBe('');
|
||||
expect(identity.findGroup(987654321)).toBeNull();
|
||||
identity.close();
|
||||
});
|
||||
|
||||
it.each([
|
||||
['empty', ''],
|
||||
['whitespace-only', ' '],
|
||||
@@ -749,6 +780,7 @@ describe('IdentityService', () => {
|
||||
['nickname', () => { identity.nickname = 'after-close'; }],
|
||||
['self profile', () => identity.setSelfProfile(profile)],
|
||||
['group member update', () => identity.updateGroupMember(GROUP_ID, { ...member, card: 'after-close' })],
|
||||
['group remark update', () => identity.updateGroupRemark(GROUP_ID, 'after-close')],
|
||||
['friends', () => identity.rememberFriends([{ uin: 22222, uid: 'u_friend', nickname: '', remark: '' }])],
|
||||
['groups', () => identity.rememberGroups([])],
|
||||
['forget group', () => identity.forgetGroup(GROUP_ID)],
|
||||
|
||||
Reference in new issue
Block a user