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(
|
||||
|
||||
@@ -82,6 +82,16 @@ export const actions = [
|
||||
},
|
||||
}),
|
||||
|
||||
groupAction({
|
||||
name: 'set_group_new_member_history_visibility',
|
||||
summary: '设置新成员是否可查看历史消息',
|
||||
params: { visible: f.bool() },
|
||||
run: async (p, ctx) => {
|
||||
await ctx.bridge.apis.groupAdmin.setNewMemberHistoryVisibility(p.group_id, p.visible);
|
||||
return okResponse();
|
||||
},
|
||||
}),
|
||||
|
||||
groupUserAction({
|
||||
name: 'set_group_admin',
|
||||
summary: '设置/取消管理员',
|
||||
|
||||
@@ -1481,6 +1481,34 @@ describe('extended-actions / set_group_member_invite_policy', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('extended-actions / set_group_new_member_history_visibility', () => {
|
||||
it('forwards the normalized group id and visibility to the group-admin API', async () => {
|
||||
const setNewMemberHistoryVisibility = vi.fn(async () => undefined);
|
||||
const bridge = fakeBridge({ apis: { groupAdmin: { setNewMemberHistoryVisibility } } });
|
||||
|
||||
const response = await makeHandler(fakeCtx(bridge)).handle(
|
||||
'set_group_new_member_history_visibility',
|
||||
{ group_id: '12345', visible: false },
|
||||
);
|
||||
|
||||
expect(response).toMatchObject({ status: 'ok', retcode: 0 });
|
||||
expect(setNewMemberHistoryVisibility).toHaveBeenCalledWith(12345, false);
|
||||
});
|
||||
|
||||
it('rejects a missing visibility value before calling the bridge', async () => {
|
||||
const setNewMemberHistoryVisibility = vi.fn();
|
||||
const bridge = fakeBridge({ apis: { groupAdmin: { setNewMemberHistoryVisibility } } });
|
||||
|
||||
const response = await makeHandler(fakeCtx(bridge)).handle(
|
||||
'set_group_new_member_history_visibility',
|
||||
{ group_id: 12345 },
|
||||
);
|
||||
|
||||
expect(response).toMatchObject({ status: 'failed', retcode: 1400 });
|
||||
expect(setNewMemberHistoryVisibility).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Wave 1: get_group_shut_list ───
|
||||
|
||||
describe('extended-actions / get_group_shut_list', () => {
|
||||
|
||||
@@ -70,6 +70,18 @@ export interface Oidb0x89a_0InvitePolicy {
|
||||
settings?: pb<2, Oidb0x89a_0InvitePolicySettings>;
|
||||
field12?: pb<12, uint_32>;
|
||||
}
|
||||
// 0x89A_0 — whether newly joined members may browse group history. Current QQ's
|
||||
// GroupDetailInfoV2 encoder emits groupFlagExt4=42 and its mutation mask=43.
|
||||
export interface Oidb0x89a_0HistoryVisibilitySettings {
|
||||
// Explicit presence is required when clearing the only selected bit.
|
||||
groupFlagExt4?: pb_optional<42, uint_32>;
|
||||
groupFlagExt4Mask?: pb_optional<43, uint_32>;
|
||||
}
|
||||
export interface Oidb0x89a_0HistoryVisibility {
|
||||
groupUin?: pb<1, uint_64>;
|
||||
settings?: pb<2, Oidb0x89a_0HistoryVisibilitySettings>;
|
||||
field12?: pb<12, uint_32>;
|
||||
}
|
||||
export interface OidbKickMember {
|
||||
groupUin?: pb<1, uint_32>;
|
||||
targetUid?: pb<3, string>;
|
||||
@@ -332,6 +344,8 @@ export interface OidbGroupDetailFlags {
|
||||
shutUpAllTimestamp?: pb<59, bool>;
|
||||
/** Current complete app privilege bitfield; needed for masked mutations. */
|
||||
privilegeFlag?: pb<99, bool>;
|
||||
/** Current complete groupFlagExt4 bitfield; needed for masked mutations. */
|
||||
groupFlagExt4?: pb<101, bool>;
|
||||
}
|
||||
export interface OidbGroupDetailConfig {
|
||||
uin?: pb<1, uint_64>;
|
||||
|
||||
@@ -119,6 +119,8 @@ export interface OidbSvcTrpcTcp0x88D_0Results {
|
||||
shutUpAllTimestamp?: pb<59, uint_32>;
|
||||
/** Complete app privilege bitfield (requested with detail flag tag 99). */
|
||||
privilegeFlag?: pb<99, uint_32>;
|
||||
/** Complete groupFlagExt4 bitfield (requested with detail flag tag 101). */
|
||||
groupFlagExt4?: pb<101, uint_32>;
|
||||
}
|
||||
export interface OidbSvcTrpcTcp0x88D_0ResponseGroupInfo {
|
||||
uin?: pb<1, uint_64>;
|
||||
|
||||
@@ -33,7 +33,7 @@ export namespace FetchGroupDetail {
|
||||
ownerUid: on, createTime: on, maxMemberCount: on, memberCount: on,
|
||||
level: on, name: '', noticePreview: '', uin: on, lastSequence: on,
|
||||
lastMessageTime: on, question: on, answer: '', maxAdminCount: '',
|
||||
shutUpAllTimestamp: on, privilegeFlag: on,
|
||||
shutUpAllTimestamp: on, privilegeFlag: on, groupFlagExt4: on,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
// 0x89A_0 — control whether newly joined members may browse group history.
|
||||
// QQ sends the complete current groupFlagExt4 value with a mutation mask, so
|
||||
// callers must read the flag before invoking this namespace.
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase, OidbEmpty } from '@snowluma/proto-defs/oidb';
|
||||
import type { Oidb0x89a_0HistoryVisibility } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
|
||||
export const GROUP_HISTORY_VISIBILITY_MASK = 0x4;
|
||||
|
||||
function assertUint32(value: number, name: string): void {
|
||||
if (!Number.isInteger(value) || value < 0 || value > 0xFFFFFFFF) {
|
||||
throw new Error(`${name} must be an unsigned 32-bit integer`);
|
||||
}
|
||||
}
|
||||
|
||||
export function mergeGroupHistoryVisibility(currentGroupFlagExt4: number, visible: boolean): number {
|
||||
assertUint32(currentGroupFlagExt4, 'current group history flag');
|
||||
const current = BigInt(currentGroupFlagExt4);
|
||||
const mask = BigInt(GROUP_HISTORY_VISIBILITY_MASK);
|
||||
return Number(visible ? current | mask : current & ~mask);
|
||||
}
|
||||
|
||||
export namespace SetNewMemberHistoryVisibility {
|
||||
export const command = 0x89A;
|
||||
export const subCommand = 0;
|
||||
|
||||
export interface Params {
|
||||
groupId: number;
|
||||
currentGroupFlagExt4: number;
|
||||
visible: boolean;
|
||||
}
|
||||
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (_ctx: Deps, p: Params): Oidb0x89a_0HistoryVisibility => ({
|
||||
groupUin: BigInt(p.groupId),
|
||||
settings: {
|
||||
groupFlagExt4: mergeGroupHistoryVisibility(p.currentGroupFlagExt4, p.visible),
|
||||
groupFlagExt4Mask: GROUP_HISTORY_VISIBILITY_MASK,
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
|
||||
|
||||
export const encode = (env: OidbBase<Oidb0x89a_0HistoryVisibility>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<Oidb0x89a_0HistoryVisibility>>(env);
|
||||
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbEmpty> =>
|
||||
protobuf_decode<OidbBase<OidbEmpty>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps, params: Params): Promise<void> =>
|
||||
invokeOidb(deps, SetNewMemberHistoryVisibility, params);
|
||||
}
|
||||
@@ -20,6 +20,7 @@ interface GroupDetailResultsFixture {
|
||||
name?: pb<15, string>;
|
||||
shutUpAllTimestamp?: pb<59, uint_32>;
|
||||
privilegeFlag?: pb<99, uint_32>;
|
||||
groupFlagExt4?: pb<101, uint_32>;
|
||||
}
|
||||
|
||||
interface GroupDetailInfoFixture {
|
||||
@@ -57,6 +58,7 @@ describe('FetchGroupDetail namespace', () => {
|
||||
expect((out.config?.flags as { shutUpAllTimestamp?: boolean })?.shutUpAllTimestamp)
|
||||
.toBe(true);
|
||||
expect(out.config?.flags?.privilegeFlag).toBe(true);
|
||||
expect(out.config?.flags?.groupFlagExt4).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -135,5 +137,27 @@ describe('FetchGroupDetail namespace', () => {
|
||||
const out = await FetchGroupDetail.invoke(sender, { groupUin: 601692726 });
|
||||
expect(out.groupInfo?.results?.privilegeFlag).toBe(0x82100001);
|
||||
});
|
||||
|
||||
it('decodes the complete extended group flag used by history visibility', async () => {
|
||||
const responseData = Buffer.from(protobuf_encode<OidbBase<GroupDetailResponseFixture>>({
|
||||
body: {
|
||||
groupInfo: {
|
||||
uin: 601692726n,
|
||||
results: { groupFlagExt4: 0x80000005 },
|
||||
},
|
||||
},
|
||||
}));
|
||||
const sender = makeSender();
|
||||
sender.sendRawPacket.mockResolvedValue({
|
||||
success: true,
|
||||
gotResponse: true,
|
||||
errorCode: 0,
|
||||
errorMessage: '',
|
||||
responseData,
|
||||
});
|
||||
|
||||
const out = await FetchGroupDetail.invoke(sender, { groupUin: 601692726 });
|
||||
expect(out.groupInfo?.results?.groupFlagExt4).toBe(0x80000005);
|
||||
});
|
||||
});
|
||||
});
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_decode } from '@snowluma/proton';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { Oidb0x89a_0HistoryVisibility } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
|
||||
import {
|
||||
GROUP_HISTORY_VISIBILITY_MASK,
|
||||
mergeGroupHistoryVisibility,
|
||||
SetNewMemberHistoryVisibility,
|
||||
} from '../../../src/oidb-services/group-admin/set-new-member-history-visibility';
|
||||
|
||||
function makeSender() {
|
||||
const result: SendPacketResult = {
|
||||
success: true,
|
||||
gotResponse: true,
|
||||
errorCode: 0,
|
||||
errorMessage: '',
|
||||
responseData: Buffer.alloc(0),
|
||||
};
|
||||
return { sendRawPacket: vi.fn(async () => result) };
|
||||
}
|
||||
|
||||
describe('SetNewMemberHistoryVisibility namespace', () => {
|
||||
it.each([
|
||||
[true, 0x80000001, 0x80000005],
|
||||
[false, 0x80000005, 0x80000001],
|
||||
])('writes visible=%s without changing unrelated bits', async (visible, current, expected) => {
|
||||
const sender = makeSender();
|
||||
|
||||
await SetNewMemberHistoryVisibility.invoke(sender, {
|
||||
groupId: 12345,
|
||||
currentGroupFlagExt4: current,
|
||||
visible,
|
||||
});
|
||||
|
||||
const [command, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
expect(command).toBe('OidbSvcTrpcTcp.0x89a_0');
|
||||
const envelope = protobuf_decode<OidbBase<Oidb0x89a_0HistoryVisibility>>(bytes);
|
||||
expect(envelope.command).toBe(0x89A);
|
||||
expect(envelope.body).toMatchObject({
|
||||
groupUin: 12345n,
|
||||
settings: {
|
||||
groupFlagExt4: expected,
|
||||
groupFlagExt4Mask: GROUP_HISTORY_VISIBILITY_MASK,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('merges only the verified history-visibility bit', () => {
|
||||
expect(mergeGroupHistoryVisibility(0xF0000001, true)).toBe(0xF0000005);
|
||||
expect(mergeGroupHistoryVisibility(0xF0000005, false)).toBe(0xF0000001);
|
||||
});
|
||||
|
||||
it('keeps an explicit zero value on the wire', async () => {
|
||||
const sender = makeSender();
|
||||
await SetNewMemberHistoryVisibility.invoke(sender, {
|
||||
groupId: 1,
|
||||
currentGroupFlagExt4: GROUP_HISTORY_VISIBILITY_MASK,
|
||||
visible: false,
|
||||
});
|
||||
|
||||
const envelope = protobuf_decode<OidbBase<Oidb0x89a_0HistoryVisibility>>(
|
||||
sender.sendRawPacket.mock.calls[0]![1],
|
||||
);
|
||||
expect(envelope.body?.settings?.groupFlagExt4).toBe(0);
|
||||
expect(envelope.body?.settings?.groupFlagExt4Mask).toBe(GROUP_HISTORY_VISIBILITY_MASK);
|
||||
});
|
||||
|
||||
it('rejects an invalid current flag before sending', async () => {
|
||||
const sender = makeSender();
|
||||
await expect(SetNewMemberHistoryVisibility.invoke(sender, {
|
||||
groupId: 1,
|
||||
currentGroupFlagExt4: -1,
|
||||
visible: true,
|
||||
})).rejects.toThrow(/unsigned 32-bit/);
|
||||
expect(sender.sendRawPacket).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user