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:
13 files changed
+284
-2
No files matched your search
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user