fix(core): accept history visibility when the read-back flag matches
Setting new members to see history no longer fails after the server has already applied it. Fixes #387
This commit is contained in:
2 files changed
+50
-30
No files matched your search
@@ -21,8 +21,6 @@ import {
|
|||||||
} from '@snowluma/protocol/oidb-services/group-admin/set-member-invite-policy';
|
} from '@snowluma/protocol/oidb-services/group-admin/set-member-invite-policy';
|
||||||
import {
|
import {
|
||||||
decodeGroupHistoryVisibility,
|
decodeGroupHistoryVisibility,
|
||||||
GROUP_HISTORY_VISIBILITY_MASK,
|
|
||||||
mergeGroupHistoryVisibility,
|
|
||||||
SetNewMemberHistoryVisibility,
|
SetNewMemberHistoryVisibility,
|
||||||
} from '@snowluma/protocol/oidb-services/group-admin/set-new-member-history-visibility';
|
} from '@snowluma/protocol/oidb-services/group-admin/set-new-member-history-visibility';
|
||||||
import {
|
import {
|
||||||
@@ -188,29 +186,21 @@ export class GroupAdminApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async setNewMemberHistoryVisibility(groupId: number, visible: boolean): Promise<void> {
|
async setNewMemberHistoryVisibility(groupId: number, visible: boolean): Promise<void> {
|
||||||
const currentGroupFlagExt4 = await this.fetchGroupFlagExt4(groupId, 'before update');
|
await SetNewMemberHistoryVisibility.invoke(this.ctx, { groupId, visible });
|
||||||
const expectedGroupFlagExt4 = mergeGroupHistoryVisibility(currentGroupFlagExt4, visible);
|
|
||||||
|
|
||||||
await SetNewMemberHistoryVisibility.invoke(this.ctx, {
|
|
||||||
groupId,
|
|
||||||
currentGroupFlagExt4,
|
|
||||||
visible,
|
|
||||||
});
|
|
||||||
|
|
||||||
const actualGroupFlagExt4 = await this.fetchGroupFlagExt4(groupId, 'after update');
|
const actualGroupFlagExt4 = await this.fetchGroupFlagExt4(groupId, 'after update');
|
||||||
const mask = BigInt(GROUP_HISTORY_VISIBILITY_MASK);
|
if (decodeGroupHistoryVisibility(actualGroupFlagExt4) !== visible) {
|
||||||
if ((BigInt(actualGroupFlagExt4) & mask) !== (BigInt(expectedGroupFlagExt4) & mask)) {
|
|
||||||
throw new Error(`new-member history visibility was not applied for group ${groupId}`);
|
throw new Error(`new-member history visibility was not applied for group ${groupId}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async fetchGroupFlagExt4(groupId: number, phase: string): Promise<number> {
|
private async fetchGroupFlagExt4(groupId: number, phase: string): Promise<number> {
|
||||||
const detail = await FetchGroupDetail.invoke(this.ctx, { groupUin: groupId });
|
const detail = await FetchGroupDetail.invoke(this.ctx, { groupUin: groupId });
|
||||||
const groupFlagExt4 = detail.groupInfo?.results?.groupFlagExt4;
|
const results = detail.groupInfo?.results;
|
||||||
if (typeof groupFlagExt4 !== 'number') {
|
if (!results) {
|
||||||
throw new Error(`unable to read new-member history visibility ${phase} for group ${groupId}`);
|
throw new Error(`unable to read new-member history visibility ${phase} for group ${groupId}`);
|
||||||
}
|
}
|
||||||
return groupFlagExt4;
|
return results.groupFlagExt4 ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
setAddRequest(
|
setAddRequest(
|
||||||
|
|||||||
@@ -321,53 +321,83 @@ describe('apis/group-admin', () => {
|
|||||||
expect(bridge.sendRawPacket).toHaveBeenCalledTimes(3);
|
expect(bridge.sendRawPacket).toHaveBeenCalledTimes(3);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('setNewMemberHistoryVisibility reads, merges, writes, and verifies the extended flag (#336)', async () => {
|
it('setNewMemberHistoryVisibility accepts a 0/1 history-visible read-back (#387)', async () => {
|
||||||
const bridge = mockBridge();
|
const bridge = mockBridge();
|
||||||
bridge.sendRawPacket
|
bridge.sendRawPacket
|
||||||
.mockResolvedValueOnce(packGroupFlagExt4(0x80000001))
|
|
||||||
.mockResolvedValueOnce(packResponse(Buffer.alloc(0)))
|
.mockResolvedValueOnce(packResponse(Buffer.alloc(0)))
|
||||||
.mockResolvedValueOnce(packGroupFlagExt4(0x80000005));
|
.mockResolvedValueOnce(packGroupFlagExt4(1));
|
||||||
|
|
||||||
await new GroupAdminApi(bridge as any).setNewMemberHistoryVisibility(12345, true);
|
await new GroupAdminApi(bridge as any).setNewMemberHistoryVisibility(12345, true);
|
||||||
|
|
||||||
expect(bridge.sendRawPacket.mock.calls.map((call) => call[0])).toEqual([
|
expect(bridge.sendRawPacket.mock.calls.map((call) => call[0])).toEqual([
|
||||||
'OidbSvcTrpcTcp.0x88d_0',
|
|
||||||
'OidbSvcTrpcTcp.0x89a_0',
|
'OidbSvcTrpcTcp.0x89a_0',
|
||||||
'OidbSvcTrpcTcp.0x88d_0',
|
'OidbSvcTrpcTcp.0x88d_0',
|
||||||
]);
|
]);
|
||||||
const envelope = protobuf_decode<OidbBase<Oidb0x89a_0HistoryVisibility>>(
|
const envelope = protobuf_decode<OidbBase<Oidb0x89a_0HistoryVisibility>>(
|
||||||
bridge.sendRawPacket.mock.calls[1]![1],
|
bridge.sendRawPacket.mock.calls[0]![1],
|
||||||
);
|
);
|
||||||
expect(envelope.body).toMatchObject({
|
expect(envelope.body).toMatchObject({
|
||||||
groupUin: 12345n,
|
groupUin: 12345n,
|
||||||
settings: {
|
settings: {
|
||||||
groupFlagExt4: 0x80000005,
|
groupFlagExt4: 0x4,
|
||||||
groupFlagExt4Mask: 0x4,
|
groupFlagExt4Mask: 0x4,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('setNewMemberHistoryVisibility fails before mutation when the current flag is absent', async () => {
|
it('setNewMemberHistoryVisibility clears visibility when read-back is the off flag', async () => {
|
||||||
const bridge = mockBridge();
|
const bridge = mockBridge();
|
||||||
bridge.sendRawPacket.mockResolvedValueOnce(packGroupFlagExt4());
|
bridge.sendRawPacket
|
||||||
|
.mockResolvedValueOnce(packResponse(Buffer.alloc(0)))
|
||||||
|
.mockResolvedValueOnce(packGroupFlagExt4(0));
|
||||||
|
|
||||||
|
await new GroupAdminApi(bridge as any).setNewMemberHistoryVisibility(12345, false);
|
||||||
|
|
||||||
|
const envelope = protobuf_decode<OidbBase<Oidb0x89a_0HistoryVisibility>>(
|
||||||
|
bridge.sendRawPacket.mock.calls[0]![1],
|
||||||
|
);
|
||||||
|
expect(envelope.body?.settings).toEqual({
|
||||||
|
groupFlagExt4: 0,
|
||||||
|
groupFlagExt4Mask: 0x4,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('setNewMemberHistoryVisibility treats an omitted history flag as hidden', async () => {
|
||||||
|
const bridge = mockBridge();
|
||||||
|
bridge.sendRawPacket
|
||||||
|
.mockResolvedValueOnce(packResponse(Buffer.alloc(0)))
|
||||||
|
.mockResolvedValueOnce(packGroupFlagExt4());
|
||||||
|
|
||||||
|
await new GroupAdminApi(bridge as any).setNewMemberHistoryVisibility(12345, false);
|
||||||
|
expect(bridge.sendRawPacket).toHaveBeenCalledTimes(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('setNewMemberHistoryVisibility fails when group detail has no results block', async () => {
|
||||||
|
const bridge = mockBridge();
|
||||||
|
bridge.sendRawPacket
|
||||||
|
.mockResolvedValueOnce(packResponse(Buffer.alloc(0)))
|
||||||
|
.mockResolvedValueOnce(packResponse(
|
||||||
|
protobuf_encode<OidbBase<OidbSvcTrpcTcp0x88D_0Response>>({
|
||||||
|
body: { groupInfo: { uin: 12345n } },
|
||||||
|
}),
|
||||||
|
));
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
new GroupAdminApi(bridge as any).setNewMemberHistoryVisibility(12345, true),
|
new GroupAdminApi(bridge as any).setNewMemberHistoryVisibility(12345, true),
|
||||||
).rejects.toThrow(/unable to read new-member history visibility before update/);
|
).rejects.toThrow(/unable to read new-member history visibility after update/);
|
||||||
expect(bridge.sendRawPacket).toHaveBeenCalledOnce();
|
expect(bridge.sendRawPacket).toHaveBeenCalledTimes(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('setNewMemberHistoryVisibility rejects an ack when read-back does not match', async () => {
|
it('setNewMemberHistoryVisibility rejects an ack when read-back stays hidden', async () => {
|
||||||
const bridge = mockBridge();
|
const bridge = mockBridge();
|
||||||
bridge.sendRawPacket
|
bridge.sendRawPacket
|
||||||
.mockResolvedValueOnce(packGroupFlagExt4(0x80000001))
|
|
||||||
.mockResolvedValueOnce(packResponse(Buffer.alloc(0)))
|
.mockResolvedValueOnce(packResponse(Buffer.alloc(0)))
|
||||||
.mockResolvedValueOnce(packGroupFlagExt4(0x80000001));
|
.mockResolvedValueOnce(packGroupFlagExt4(0));
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
new GroupAdminApi(bridge as any).setNewMemberHistoryVisibility(12345, true),
|
new GroupAdminApi(bridge as any).setNewMemberHistoryVisibility(12345, true),
|
||||||
).rejects.toThrow(/was not applied/);
|
).rejects.toThrow(/was not applied/);
|
||||||
expect(bridge.sendRawPacket).toHaveBeenCalledTimes(3);
|
expect(bridge.sendRawPacket).toHaveBeenCalledTimes(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('setMemberPermissions applies supplied switches separately and verifies the combined result (#335)', async () => {
|
it('setMemberPermissions applies supplied switches separately and verifies the combined result (#335)', async () => {
|
||||||
@@ -462,7 +492,7 @@ describe('apis/group-admin', () => {
|
|||||||
question: 'how',
|
question: 'how',
|
||||||
answer: '42',
|
answer: '42',
|
||||||
privilegeFlag: 0x84018001,
|
privilegeFlag: 0x84018001,
|
||||||
groupFlagExt4: 0x80000005,
|
groupFlagExt4: 1,
|
||||||
noFingerOpen: 1,
|
noFingerOpen: 1,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user