feat(protocol): read current group admin settings
Group detail and ext-info can now return the join option, search flags, invite/permission/history bits, and robot-add switch so setters have a matching read path.
This commit is contained in:
@@ -346,6 +346,7 @@ export interface OidbGroupDetailFlags {
|
||||
createTime?: pb<2, bool>;
|
||||
maxMemberCount?: pb<5, bool>;
|
||||
memberCount?: pb<6, bool>;
|
||||
addType?: pb<7, bool>;
|
||||
level?: pb<10, bool>;
|
||||
name?: pb<15, string>;
|
||||
noticePreview?: pb<16, string>;
|
||||
@@ -362,6 +363,8 @@ export interface OidbGroupDetailFlags {
|
||||
privilegeFlag?: pb<99, bool>;
|
||||
/** Current complete groupFlagExt4 bitfield; needed for masked mutations. */
|
||||
groupFlagExt4?: pb<101, bool>;
|
||||
noFingerOpen?: pb<82, bool>;
|
||||
noCodeFingerOpen?: pb<83, bool>;
|
||||
}
|
||||
export interface OidbGroupDetailConfig {
|
||||
uin?: pb<1, uint_64>;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
// encoder emits. Presence of tag 29/30 IS the write signal, including 0.
|
||||
// Response: {1:groupCode, 2:result}.
|
||||
|
||||
import type { pb, pb_optional, int_32, uint_32 } from '@snowluma/proton';
|
||||
import type { pb, pb_optional, pb_repeated, int_32, uint_32, uint_64 } from '@snowluma/proton';
|
||||
|
||||
export interface OidbGroupExtBody {
|
||||
inviteRobotMemberSwitch?: pb_optional<29, uint_32>;
|
||||
@@ -25,3 +25,24 @@ export interface OidbModifyGroupExtResp {
|
||||
groupCode?: pb<1, uint_32>;
|
||||
result?: pb<2, int_32>;
|
||||
}
|
||||
|
||||
// OidbSvcTrpcTcp.0xef0_1 / getGroupExt0xEF0Info.
|
||||
// DoFetchGroupExtList request: {1:groupCodes, 2:GroupExtFilter}.
|
||||
// fillGroupExt0xEF0Filter writes filter tags 29/30 when those bits are set.
|
||||
// Response: repeated item{1:groupCode, 2:resultCode, 3:EXTInfo}.
|
||||
export interface OidbGroupExtFilter {
|
||||
inviteRobotMemberSwitch?: pb<29, uint_32>;
|
||||
inviteRobotMemberExamine?: pb<30, uint_32>;
|
||||
}
|
||||
export interface OidbGetGroupExtReq {
|
||||
groupCodes?: pb_repeated<1, uint_64>;
|
||||
filter?: pb<2, OidbGroupExtFilter>;
|
||||
}
|
||||
export interface OidbGetGroupExtItem {
|
||||
groupCode?: pb<1, uint_64>;
|
||||
resultCode?: pb<2, uint_32>;
|
||||
ext?: pb<3, OidbGroupExtBody>;
|
||||
}
|
||||
export interface OidbGetGroupExtResp {
|
||||
items?: pb_repeated<1, OidbGetGroupExtItem>;
|
||||
}
|
||||
|
||||
@@ -110,6 +110,9 @@ export interface OidbSvcTrpcTcp0x88D_0Results {
|
||||
createTime?: pb<2, uint_64>;
|
||||
maxMemberCount?: pb<5, uint_64>;
|
||||
memberCount?: pb<6, uint_64>;
|
||||
// DecodeSingleGroupDetailInfoByBaseFilter: tag 7 → 60205 addOption.
|
||||
// SET uses a different message domain (0x89A settings tag 16).
|
||||
addType?: pb<7, uint_32>;
|
||||
level?: pb<10, uint_64>;
|
||||
name?: pb<15, string>;
|
||||
noticePreview?: pb<16, string>;
|
||||
@@ -127,6 +130,10 @@ export interface OidbSvcTrpcTcp0x88D_0Results {
|
||||
privilegeFlag?: pb<99, uint_32>;
|
||||
/** Complete groupFlagExt4 bitfield (requested with detail flag tag 101). */
|
||||
groupFlagExt4?: pb<101, uint_32>;
|
||||
// DecodeSingleGroupDetailInfoByBaseFilter: tag 82 → 60282, tag 83 → 60283.
|
||||
// SET counterparts are 0x89A settings 35/36. 0 = that search mode is open.
|
||||
noFingerOpen?: pb<82, uint_32>;
|
||||
noCodeFingerOpen?: pb<83, uint_32>;
|
||||
}
|
||||
export interface OidbSvcTrpcTcp0x88D_0ResponseGroupInfo {
|
||||
uin?: pb<1, uint_64>;
|
||||
|
||||
@@ -33,7 +33,8 @@ export namespace FetchGroupDetail {
|
||||
level: on, name: '', noticePreview: '', uin: on, lastSequence: on,
|
||||
lastMessageTime: on, question: on, answer: '', maxAdminCount: '',
|
||||
// Tag 45 (not Lagrange's 59): official request mask for 60027.
|
||||
shutUpAllTimestamp: on, privilegeFlag: on, groupFlagExt4: on,
|
||||
shutUpAllTimestamp: on, addType: on, privilegeFlag: on, groupFlagExt4: on,
|
||||
noFingerOpen: on, noCodeFingerOpen: on,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
// 0xef0_1 — getGroupExt0xEF0Info. Used to read the current robot-add
|
||||
// switch/examine values that set_group_robot_add_option writes.
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { OidbGetGroupExtReq, OidbGetGroupExtResp } from '@snowluma/proto-defs/oidb-actions/group-ext';
|
||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
|
||||
export interface GroupExtRobotOption {
|
||||
robotMemberSwitch: number;
|
||||
robotMemberExamine: number;
|
||||
}
|
||||
|
||||
export namespace FetchGroupExtInfo {
|
||||
export const command = 0xEF0;
|
||||
export const subCommand = 1;
|
||||
export const uinForm = true;
|
||||
|
||||
export interface Params { groupId: number; }
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbGetGroupExtReq => ({
|
||||
groupCodes: [BigInt(p.groupId)],
|
||||
filter: {
|
||||
inviteRobotMemberSwitch: 1,
|
||||
inviteRobotMemberExamine: 1,
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (_ctx: Deps, body: OidbGetGroupExtResp): GroupExtRobotOption => {
|
||||
const item = body.items?.[0];
|
||||
if (!item) {
|
||||
throw new Error('unable to read group robot-add option');
|
||||
}
|
||||
if (item.resultCode && item.resultCode !== 0) {
|
||||
throw new Error(`unable to read group robot-add option: result=${item.resultCode}`);
|
||||
}
|
||||
return {
|
||||
robotMemberSwitch: item.ext?.inviteRobotMemberSwitch ?? 0,
|
||||
robotMemberExamine: item.ext?.inviteRobotMemberExamine ?? 0,
|
||||
};
|
||||
};
|
||||
|
||||
export const encode = (env: OidbBase<OidbGetGroupExtReq>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbGetGroupExtReq>>(env);
|
||||
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbGetGroupExtResp> =>
|
||||
protobuf_decode<OidbBase<OidbGetGroupExtResp>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps, params: Params): Promise<GroupExtRobotOption> =>
|
||||
invokeOidb(deps, FetchGroupExtInfo, params);
|
||||
}
|
||||
@@ -39,6 +39,15 @@ export function mergeMemberInvitePrivilegeFlag(
|
||||
return Number((current & ~mask) | (requested & mask));
|
||||
}
|
||||
|
||||
export function decodeMemberInvitePolicy(privilegeFlag: number): GroupMemberInvitePolicy {
|
||||
assertUint32(privilegeFlag, 'privilege flag');
|
||||
const bits = privilegeFlag & MEMBER_INVITE_PRIVILEGE_MASK;
|
||||
if ((bits & 0x04000000) !== 0) return 'disabled';
|
||||
if ((bits & 0x02000000) !== 0) return 'no_approval_under_100';
|
||||
if ((bits & 0x00100000) !== 0) return 'no_approval';
|
||||
return 'require_approval';
|
||||
}
|
||||
|
||||
export namespace SetMemberInvitePolicy {
|
||||
export const command = 0x89A;
|
||||
export const subCommand = 0;
|
||||
|
||||
@@ -32,6 +32,22 @@ export function mergeGroupMemberPermission(
|
||||
return Number(allow ? current & ~mask : current | mask);
|
||||
}
|
||||
|
||||
export function decodeGroupMemberPermissions(privilegeFlag: number): {
|
||||
allowMemberUploadAlbum: boolean;
|
||||
allowMemberTemporarySession: boolean;
|
||||
allowMemberCreateGroup: boolean;
|
||||
} {
|
||||
assertUint32(privilegeFlag, 'privilege flag');
|
||||
return {
|
||||
allowMemberUploadAlbum:
|
||||
(privilegeFlag & GROUP_MEMBER_PERMISSION_MASKS.upload_album) === 0,
|
||||
allowMemberTemporarySession:
|
||||
(privilegeFlag & GROUP_MEMBER_PERMISSION_MASKS.temporary_session) === 0,
|
||||
allowMemberCreateGroup:
|
||||
(privilegeFlag & GROUP_MEMBER_PERMISSION_MASKS.create_group) === 0,
|
||||
};
|
||||
}
|
||||
|
||||
export namespace SetMemberPermission {
|
||||
export const command = 0x89A;
|
||||
export const subCommand = 0;
|
||||
|
||||
@@ -22,6 +22,11 @@ export function mergeGroupHistoryVisibility(currentGroupFlagExt4: number, visibl
|
||||
return Number(visible ? current | mask : current & ~mask);
|
||||
}
|
||||
|
||||
export function decodeGroupHistoryVisibility(groupFlagExt4: number): boolean {
|
||||
assertUint32(groupFlagExt4, 'group history flag');
|
||||
return (groupFlagExt4 & GROUP_HISTORY_VISIBILITY_MASK) !== 0;
|
||||
}
|
||||
|
||||
export namespace SetNewMemberHistoryVisibility {
|
||||
export const command = 0x89A;
|
||||
export const subCommand = 0;
|
||||
|
||||
@@ -60,6 +60,9 @@ describe('FetchGroupDetail namespace', () => {
|
||||
.toBe(true);
|
||||
expect(out.config?.flags?.privilegeFlag).toBe(true);
|
||||
expect(out.config?.flags?.groupFlagExt4).toBe(true);
|
||||
expect(out.config?.flags?.addType).toBe(true);
|
||||
expect(out.config?.flags?.noFingerOpen).toBe(true);
|
||||
expect(out.config?.flags?.noCodeFingerOpen).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -182,5 +185,29 @@ describe('FetchGroupDetail namespace', () => {
|
||||
const out = await FetchGroupDetail.invoke(sender, { groupUin: 601692726 });
|
||||
expect(out.groupInfo?.results?.groupFlagExt4).toBe(0x80000005);
|
||||
});
|
||||
|
||||
it('decodes add-option and search flags from the detail response', async () => {
|
||||
const responseData = Buffer.from(protobuf_encode<OidbBase<OidbSvcTrpcTcp0x88D_0Response>>({
|
||||
body: {
|
||||
groupInfo: {
|
||||
uin: 601692726n,
|
||||
results: { addType: 2, noFingerOpen: 1, noCodeFingerOpen: 0 },
|
||||
},
|
||||
},
|
||||
}));
|
||||
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?.addType).toBe(2);
|
||||
expect(out.groupInfo?.results?.noFingerOpen).toBe(1);
|
||||
expect(out.groupInfo?.results?.noCodeFingerOpen ?? 0).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { OidbGetGroupExtReq, OidbGetGroupExtResp } from '@snowluma/proto-defs/oidb-actions/group-ext';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
import { FetchGroupExtInfo } from '../../../src/oidb-services/group-admin/get-group-ext-info';
|
||||
import { env, v, m } from '../_pb-oracle';
|
||||
|
||||
function makeSender(body?: OidbGetGroupExtResp) {
|
||||
const responseData = body !== undefined
|
||||
? Buffer.from(protobuf_encode<OidbBase<OidbGetGroupExtResp>>({ body }))
|
||||
: Buffer.alloc(0);
|
||||
const result: SendPacketResult = {
|
||||
success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData,
|
||||
};
|
||||
return { sendRawPacket: vi.fn(async () => result) };
|
||||
}
|
||||
|
||||
describe('FetchGroupExtInfo namespace', () => {
|
||||
it('declares command 0xEF0 sub 1, uin form', () => {
|
||||
expect(FetchGroupExtInfo.command).toBe(0xEF0);
|
||||
expect(FetchGroupExtInfo.subCommand).toBe(1);
|
||||
expect(FetchGroupExtInfo.uinForm).toBe(true);
|
||||
});
|
||||
|
||||
it('byte-oracle: routes to 0xef0_1 and locks {1:groupCode, 2:{29:1,30:1}}', async () => {
|
||||
const sender = makeSender({
|
||||
items: [{ groupCode: 12345n, ext: { inviteRobotMemberSwitch: 1, inviteRobotMemberExamine: 2 } }],
|
||||
});
|
||||
await FetchGroupExtInfo.invoke(sender, { groupId: 12345 });
|
||||
|
||||
const [cmd, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
expect(cmd).toBe('OidbSvcTrpcTcp.0xef0_1');
|
||||
const filter = [...v(29, 1), ...v(30, 1)];
|
||||
const body = [...v(1, 12345), ...m(2, filter)];
|
||||
expect(Buffer.from(bytes).toString('hex')).toBe(env(0xEF0, 1, body, true));
|
||||
const envelope = protobuf_decode<OidbBase<OidbGetGroupExtReq>>(bytes);
|
||||
expect(envelope.reserved).toBe(1);
|
||||
expect(envelope.body?.groupCodes).toEqual([12345n]);
|
||||
});
|
||||
|
||||
it('returns robot-add switch/examine from the first item', async () => {
|
||||
const sender = makeSender({
|
||||
items: [{
|
||||
groupCode: 12345n,
|
||||
ext: { inviteRobotMemberSwitch: 1, inviteRobotMemberExamine: 2 },
|
||||
}],
|
||||
});
|
||||
await expect(FetchGroupExtInfo.invoke(sender, { groupId: 12345 })).resolves.toEqual({
|
||||
robotMemberSwitch: 1,
|
||||
robotMemberExamine: 2,
|
||||
});
|
||||
});
|
||||
|
||||
it('treats omitted zeros as 0', async () => {
|
||||
const sender = makeSender({ items: [{ groupCode: 12345n, ext: {} }] });
|
||||
await expect(FetchGroupExtInfo.invoke(sender, { groupId: 12345 })).resolves.toEqual({
|
||||
robotMemberSwitch: 0,
|
||||
robotMemberExamine: 0,
|
||||
});
|
||||
});
|
||||
|
||||
it('throws when the list is empty', async () => {
|
||||
const sender = makeSender({ items: [] });
|
||||
await expect(FetchGroupExtInfo.invoke(sender, { groupId: 12345 }))
|
||||
.rejects.toThrow(/unable to read group robot-add option/);
|
||||
});
|
||||
|
||||
it('throws on a non-zero item result', async () => {
|
||||
const sender = makeSender({
|
||||
items: [{ groupCode: 12345n, resultCode: 5, ext: { inviteRobotMemberSwitch: 1 } }],
|
||||
});
|
||||
await expect(FetchGroupExtInfo.invoke(sender, { groupId: 12345 }))
|
||||
.rejects.toThrow(/result=5/);
|
||||
});
|
||||
});
|
||||
@@ -6,6 +6,7 @@ import type { Oidb0x89a_0InvitePolicy } from '@snowluma/proto-defs/oidb-actions/
|
||||
|
||||
import {
|
||||
MEMBER_INVITE_PRIVILEGE_MASK,
|
||||
decodeMemberInvitePolicy,
|
||||
mergeMemberInvitePrivilegeFlag,
|
||||
SetMemberInvitePolicy,
|
||||
type GroupMemberInvitePolicy,
|
||||
@@ -55,6 +56,27 @@ describe('SetMemberInvitePolicy namespace', () => {
|
||||
.toBe(0xE1000001);
|
||||
});
|
||||
|
||||
it.each<[number, GroupMemberInvitePolicy]>([
|
||||
[0x04000000, 'disabled'],
|
||||
[0, 'require_approval'],
|
||||
[0x00100000, 'no_approval'],
|
||||
[0x02000000, 'no_approval_under_100'],
|
||||
[0x80100001, 'no_approval'],
|
||||
[0x84000001, 'disabled'],
|
||||
])('decodes privilege %# as %s', (privilegeFlag, policy) => {
|
||||
expect(decodeMemberInvitePolicy(privilegeFlag)).toBe(policy);
|
||||
});
|
||||
|
||||
it('round-trips each invite policy through merge then decode', () => {
|
||||
const policies: GroupMemberInvitePolicy[] = [
|
||||
'disabled', 'require_approval', 'no_approval', 'no_approval_under_100',
|
||||
];
|
||||
for (const policy of policies) {
|
||||
expect(decodeMemberInvitePolicy(mergeMemberInvitePrivilegeFlag(0x80000001, policy)))
|
||||
.toBe(policy);
|
||||
}
|
||||
});
|
||||
|
||||
it('keeps explicit zero fields on the wire', async () => {
|
||||
const sender = makeSender();
|
||||
await SetMemberInvitePolicy.invoke(sender, {
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { Oidb0x89a_0MemberPermission } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
|
||||
import {
|
||||
decodeGroupMemberPermissions,
|
||||
GROUP_MEMBER_PERMISSION_MASKS,
|
||||
mergeGroupMemberPermission,
|
||||
SetMemberPermission,
|
||||
@@ -74,6 +75,36 @@ describe('SetMemberPermission namespace', () => {
|
||||
.toBe(0xF0008000);
|
||||
});
|
||||
|
||||
it('treats permission bits as deny flags when decoding', () => {
|
||||
expect(decodeGroupMemberPermissions(0)).toEqual({
|
||||
allowMemberUploadAlbum: true,
|
||||
allowMemberTemporarySession: true,
|
||||
allowMemberCreateGroup: true,
|
||||
});
|
||||
expect(decodeGroupMemberPermissions(0x80018001)).toEqual({
|
||||
allowMemberUploadAlbum: false,
|
||||
allowMemberTemporarySession: false,
|
||||
allowMemberCreateGroup: false,
|
||||
});
|
||||
expect(decodeGroupMemberPermissions(0x80000000)).toEqual({
|
||||
allowMemberUploadAlbum: true,
|
||||
allowMemberTemporarySession: true,
|
||||
allowMemberCreateGroup: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('round-trips each permission through merge then decode', () => {
|
||||
let flag = 0x80000000;
|
||||
flag = mergeGroupMemberPermission(flag, 'upload_album', false);
|
||||
flag = mergeGroupMemberPermission(flag, 'temporary_session', true);
|
||||
flag = mergeGroupMemberPermission(flag, 'create_group', false);
|
||||
expect(decodeGroupMemberPermissions(flag)).toEqual({
|
||||
allowMemberUploadAlbum: false,
|
||||
allowMemberTemporarySession: true,
|
||||
allowMemberCreateGroup: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('keeps explicit zero fields on the wire', async () => {
|
||||
const sender = makeSender();
|
||||
await SetMemberPermission.invoke(sender, {
|
||||
|
||||
+12
@@ -5,6 +5,7 @@ import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { Oidb0x89a_0HistoryVisibility } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
|
||||
import {
|
||||
decodeGroupHistoryVisibility,
|
||||
GROUP_HISTORY_VISIBILITY_MASK,
|
||||
mergeGroupHistoryVisibility,
|
||||
SetNewMemberHistoryVisibility,
|
||||
@@ -52,6 +53,17 @@ describe('SetNewMemberHistoryVisibility namespace', () => {
|
||||
expect(mergeGroupHistoryVisibility(0xF0000005, false)).toBe(0xF0000001);
|
||||
});
|
||||
|
||||
it('decodes the history-visibility bit', () => {
|
||||
expect(decodeGroupHistoryVisibility(0x80000001)).toBe(false);
|
||||
expect(decodeGroupHistoryVisibility(0x80000005)).toBe(true);
|
||||
expect(decodeGroupHistoryVisibility(0)).toBe(false);
|
||||
});
|
||||
|
||||
it('round-trips history visibility through merge then decode', () => {
|
||||
expect(decodeGroupHistoryVisibility(mergeGroupHistoryVisibility(0x80000001, true))).toBe(true);
|
||||
expect(decodeGroupHistoryVisibility(mergeGroupHistoryVisibility(0x80000005, false))).toBe(false);
|
||||
});
|
||||
|
||||
it('keeps an explicit zero value on the wire', async () => {
|
||||
const sender = makeSender();
|
||||
await SetNewMemberHistoryVisibility.invoke(sender, {
|
||||
|
||||
Reference in New Issue
Block a user