10 files changed
+305
-1
No files matched your search
@@ -17,6 +17,11 @@ import {
|
||||
SetMemberInvitePolicy,
|
||||
type GroupMemberInvitePolicy,
|
||||
} from '@snowluma/protocol/oidb-services/group-admin/set-member-invite-policy';
|
||||
import {
|
||||
GROUP_HISTORY_VISIBILITY_MASK,
|
||||
mergeGroupHistoryVisibility,
|
||||
SetNewMemberHistoryVisibility,
|
||||
} from '@snowluma/protocol/oidb-services/group-admin/set-new-member-history-visibility';
|
||||
import { SetSearch } from '@snowluma/protocol/oidb-services/group-admin/set-search';
|
||||
import { SetSpecialTitle } from '@snowluma/protocol/oidb-services/group-admin/set-special-title';
|
||||
import { ModifyGroupExtInfo } from '@snowluma/protocol/oidb-services/group-admin/modify-group-ext-info';
|
||||
@@ -72,6 +77,32 @@ export class GroupAdminApi {
|
||||
return privilegeFlag;
|
||||
}
|
||||
|
||||
async setNewMemberHistoryVisibility(groupId: number, visible: boolean): Promise<void> {
|
||||
const currentGroupFlagExt4 = await this.fetchGroupFlagExt4(groupId, 'before update');
|
||||
const expectedGroupFlagExt4 = mergeGroupHistoryVisibility(currentGroupFlagExt4, visible);
|
||||
|
||||
await SetNewMemberHistoryVisibility.invoke(this.ctx, {
|
||||
groupId,
|
||||
currentGroupFlagExt4,
|
||||
visible,
|
||||
});
|
||||
|
||||
const actualGroupFlagExt4 = await this.fetchGroupFlagExt4(groupId, 'after update');
|
||||
const mask = BigInt(GROUP_HISTORY_VISIBILITY_MASK);
|
||||
if ((BigInt(actualGroupFlagExt4) & mask) !== (BigInt(expectedGroupFlagExt4) & mask)) {
|
||||
throw new Error(`new-member history visibility was not applied for group ${groupId}`);
|
||||
}
|
||||
}
|
||||
|
||||
private async fetchGroupFlagExt4(groupId: number, phase: string): Promise<number> {
|
||||
const detail = await FetchGroupDetail.invoke(this.ctx, { groupUin: groupId });
|
||||
const groupFlagExt4 = detail.groupInfo?.results?.groupFlagExt4;
|
||||
if (typeof groupFlagExt4 !== 'number') {
|
||||
throw new Error(`unable to read new-member history visibility ${phase} for group ${groupId}`);
|
||||
}
|
||||
return groupFlagExt4;
|
||||
}
|
||||
|
||||
setAddRequest(
|
||||
groupId: number, sequence: number, eventType: number,
|
||||
approve: boolean, reason = '', filtered = false,
|
||||
|
||||
@@ -7,6 +7,7 @@ import type {
|
||||
Oidb0x89a_0AddOption,
|
||||
Oidb0x89a_0Search,
|
||||
Oidb0x89a_0InvitePolicy,
|
||||
Oidb0x89a_0HistoryVisibility,
|
||||
Oidb0xf16Req,
|
||||
OidbGroupRequestAction,
|
||||
OidbKickMember,
|
||||
@@ -43,6 +44,17 @@ function packPrivilegeFlag(privilegeFlag?: number) {
|
||||
}));
|
||||
}
|
||||
|
||||
function packGroupFlagExt4(groupFlagExt4?: number) {
|
||||
return packResponse(protobuf_encode<OidbBase<OidbSvcTrpcTcp0x88D_0Response>>({
|
||||
body: {
|
||||
groupInfo: {
|
||||
uin: 12345n,
|
||||
results: groupFlagExt4 === undefined ? {} : { groupFlagExt4 },
|
||||
},
|
||||
},
|
||||
}));
|
||||
}
|
||||
|
||||
describe('apis/group-admin', () => {
|
||||
it('muteMember resolves UID and dispatches 0x1253_1', async () => {
|
||||
const bridge = mockBridge();
|
||||
@@ -274,6 +286,55 @@ describe('apis/group-admin', () => {
|
||||
expect(bridge.sendRawPacket).toHaveBeenCalledTimes(3);
|
||||
});
|
||||
|
||||
it('setNewMemberHistoryVisibility reads, merges, writes, and verifies the extended flag (#336)', async () => {
|
||||
const bridge = mockBridge();
|
||||
bridge.sendRawPacket
|
||||
.mockResolvedValueOnce(packGroupFlagExt4(0x80000001))
|
||||
.mockResolvedValueOnce(packResponse(Buffer.alloc(0)))
|
||||
.mockResolvedValueOnce(packGroupFlagExt4(0x80000005));
|
||||
|
||||
await new GroupAdminApi(bridge as any).setNewMemberHistoryVisibility(12345, true);
|
||||
|
||||
expect(bridge.sendRawPacket.mock.calls.map((call) => call[0])).toEqual([
|
||||
'OidbSvcTrpcTcp.0x88d_0',
|
||||
'OidbSvcTrpcTcp.0x89a_0',
|
||||
'OidbSvcTrpcTcp.0x88d_0',
|
||||
]);
|
||||
const envelope = protobuf_decode<OidbBase<Oidb0x89a_0HistoryVisibility>>(
|
||||
bridge.sendRawPacket.mock.calls[1]![1],
|
||||
);
|
||||
expect(envelope.body).toMatchObject({
|
||||
groupUin: 12345n,
|
||||
settings: {
|
||||
groupFlagExt4: 0x80000005,
|
||||
groupFlagExt4Mask: 0x4,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('setNewMemberHistoryVisibility fails before mutation when the current flag is absent', async () => {
|
||||
const bridge = mockBridge();
|
||||
bridge.sendRawPacket.mockResolvedValueOnce(packGroupFlagExt4());
|
||||
|
||||
await expect(
|
||||
new GroupAdminApi(bridge as any).setNewMemberHistoryVisibility(12345, true),
|
||||
).rejects.toThrow(/unable to read new-member history visibility before update/);
|
||||
expect(bridge.sendRawPacket).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it('setNewMemberHistoryVisibility rejects an ack when read-back does not match', async () => {
|
||||
const bridge = mockBridge();
|
||||
bridge.sendRawPacket
|
||||
.mockResolvedValueOnce(packGroupFlagExt4(0x80000001))
|
||||
.mockResolvedValueOnce(packResponse(Buffer.alloc(0)))
|
||||
.mockResolvedValueOnce(packGroupFlagExt4(0x80000001));
|
||||
|
||||
await expect(
|
||||
new GroupAdminApi(bridge as any).setNewMemberHistoryVisibility(12345, true),
|
||||
).rejects.toThrow(/was not applied/);
|
||||
expect(bridge.sendRawPacket).toHaveBeenCalledTimes(3);
|
||||
});
|
||||
|
||||
it('getAtAllRemain decodes the response and converts BigInts', async () => {
|
||||
const bridge = mockBridge();
|
||||
bridge.sendRawPacket.mockResolvedValueOnce(packResponse(
|
||||
|
||||
Reference in new issue
Block a user