fix(protocol): treat history visibility replies as an on/off flag

The group-detail reply reports whether new members can see history as
a simple yes/no value. The write still flips that setting; the read
no longer expects a multi-bit field.
This commit is contained in:
DrSmoothl committed 2026-08-17 19:40:22 +08:00
1 parent b63c3c370b
commit cc517080be
4 files changed
+22 -22

No files matched your search

+1 -1
View File
@@ -365,7 +365,7 @@ export interface OidbGroupDetailFlags {
shutUpAllTimestamp?: pb<45, bool>; shutUpAllTimestamp?: pb<45, bool>;
/** Current complete app privilege bitfield; needed for masked mutations. */ /** Current complete app privilege bitfield; needed for masked mutations. */
privilegeFlag?: pb<99, bool>; privilegeFlag?: pb<99, bool>;
/** Current complete groupFlagExt4 bitfield; needed for masked mutations. */ /** Request the new-member history-visible switch. */
groupFlagExt4?: pb<101, bool>; groupFlagExt4?: pb<101, bool>;
noFingerOpen?: pb<82, bool>; noFingerOpen?: pb<82, bool>;
noCodeFingerOpen?: pb<83, bool>; noCodeFingerOpen?: pb<83, bool>;
+1 -1
View File
@@ -128,7 +128,7 @@ export interface OidbSvcTrpcTcp0x88D_0Results {
shutUpAllTimestamp?: pb<45, uint_32>; shutUpAllTimestamp?: pb<45, uint_32>;
/** Complete app privilege bitfield (requested with detail flag tag 99). */ /** Complete app privilege bitfield (requested with detail flag tag 99). */
privilegeFlag?: pb<99, uint_32>; privilegeFlag?: pb<99, uint_32>;
/** Complete groupFlagExt4 bitfield (requested with detail flag tag 101). */ /** New-member history-visible switch (0/1; omitted means hidden). */
groupFlagExt4?: pb<101, uint_32>; groupFlagExt4?: pb<101, uint_32>;
// DecodeSingleGroupDetailInfoByBaseFilter: tag 82 → 60282, tag 83 → 60283. // DecodeSingleGroupDetailInfoByBaseFilter: tag 82 → 60282, tag 83 → 60283.
// SET counterparts are 0x89A settings 35/36. 0 = that search mode is open. // SET counterparts are 0x89A settings 35/36. 0 = that search mode is open.
@@ -1,6 +1,7 @@
// 0x89A_0 — control whether newly joined members may browse group history. // 0x89A_0 — control whether newly joined members may browse group history.
// QQ sends the complete current groupFlagExt4 value with a mutation mask, so // Mutation writes the extended-flag value plus a one-bit mask. The matching
// callers must read the flag before invoking this namespace. // group-detail reply is a 0/1 switch (omitted means hidden), not the full
// extended-flag bitfield.
import { protobuf_decode, protobuf_encode } from '@snowluma/proton'; import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase, OidbEmpty } from '@snowluma/proto-defs/oidb'; import type { OidbBase, OidbEmpty } from '@snowluma/proto-defs/oidb';
@@ -24,7 +25,8 @@ export function mergeGroupHistoryVisibility(currentGroupFlagExt4: number, visibl
export function decodeGroupHistoryVisibility(groupFlagExt4: number): boolean { export function decodeGroupHistoryVisibility(groupFlagExt4: number): boolean {
assertUint32(groupFlagExt4, 'group history flag'); assertUint32(groupFlagExt4, 'group history flag');
return (groupFlagExt4 & GROUP_HISTORY_VISIBILITY_MASK) !== 0; // Detail replies use 0/1. The mutation bitfield still uses bit 2.
return groupFlagExt4 === 1 || (groupFlagExt4 & GROUP_HISTORY_VISIBILITY_MASK) !== 0;
} }
export namespace SetNewMemberHistoryVisibility { export namespace SetNewMemberHistoryVisibility {
@@ -33,7 +35,6 @@ export namespace SetNewMemberHistoryVisibility {
export interface Params { export interface Params {
groupId: number; groupId: number;
currentGroupFlagExt4: number;
visible: boolean; visible: boolean;
} }
@@ -42,7 +43,7 @@ export namespace SetNewMemberHistoryVisibility {
export const serialize = (_ctx: Deps, p: Params): Oidb0x89a_0HistoryVisibility => ({ export const serialize = (_ctx: Deps, p: Params): Oidb0x89a_0HistoryVisibility => ({
groupUin: BigInt(p.groupId), groupUin: BigInt(p.groupId),
settings: { settings: {
groupFlagExt4: mergeGroupHistoryVisibility(p.currentGroupFlagExt4, p.visible), groupFlagExt4: p.visible ? GROUP_HISTORY_VISIBILITY_MASK : 0,
groupFlagExt4Mask: GROUP_HISTORY_VISIBILITY_MASK, groupFlagExt4Mask: GROUP_HISTORY_VISIBILITY_MASK,
}, },
}); });
@@ -24,14 +24,13 @@ function makeSender() {
describe('SetNewMemberHistoryVisibility namespace', () => { describe('SetNewMemberHistoryVisibility namespace', () => {
it.each([ it.each([
[true, 0x80000001, 0x80000005], [true, GROUP_HISTORY_VISIBILITY_MASK],
[false, 0x80000005, 0x80000001], [false, 0],
])('writes visible=%s without changing unrelated bits', async (visible, current, expected) => { ])('writes visible=%s as the mutation bit only', async (visible, expected) => {
const sender = makeSender(); const sender = makeSender();
await SetNewMemberHistoryVisibility.invoke(sender, { await SetNewMemberHistoryVisibility.invoke(sender, {
groupId: 12345, groupId: 12345,
currentGroupFlagExt4: current,
visible, visible,
}); });
@@ -53,10 +52,12 @@ describe('SetNewMemberHistoryVisibility namespace', () => {
expect(mergeGroupHistoryVisibility(0xF0000005, false)).toBe(0xF0000001); expect(mergeGroupHistoryVisibility(0xF0000005, false)).toBe(0xF0000001);
}); });
it('decodes the history-visibility bit', () => { it('decodes the history-visibility switch from a 0/1 reply or the mutation bit', () => {
expect(decodeGroupHistoryVisibility(0)).toBe(false);
expect(decodeGroupHistoryVisibility(1)).toBe(true);
expect(decodeGroupHistoryVisibility(GROUP_HISTORY_VISIBILITY_MASK)).toBe(true);
expect(decodeGroupHistoryVisibility(0x80000001)).toBe(false); expect(decodeGroupHistoryVisibility(0x80000001)).toBe(false);
expect(decodeGroupHistoryVisibility(0x80000005)).toBe(true); expect(decodeGroupHistoryVisibility(0x80000005)).toBe(true);
expect(decodeGroupHistoryVisibility(0)).toBe(false);
}); });
it('round-trips history visibility through merge then decode', () => { it('round-trips history visibility through merge then decode', () => {
@@ -64,11 +65,15 @@ describe('SetNewMemberHistoryVisibility namespace', () => {
expect(decodeGroupHistoryVisibility(mergeGroupHistoryVisibility(0x80000005, false))).toBe(false); expect(decodeGroupHistoryVisibility(mergeGroupHistoryVisibility(0x80000005, false))).toBe(false);
}); });
it('does not treat a 0/1 detail reply as a missing mutation bit (#387)', () => {
expect(decodeGroupHistoryVisibility(1)).toBe(true);
expect(decodeGroupHistoryVisibility(mergeGroupHistoryVisibility(0, true))).toBe(true);
});
it('keeps an explicit zero value on the wire', async () => { it('keeps an explicit zero value on the wire', async () => {
const sender = makeSender(); const sender = makeSender();
await SetNewMemberHistoryVisibility.invoke(sender, { await SetNewMemberHistoryVisibility.invoke(sender, {
groupId: 1, groupId: 1,
currentGroupFlagExt4: GROUP_HISTORY_VISIBILITY_MASK,
visible: false, visible: false,
}); });
@@ -79,13 +84,7 @@ describe('SetNewMemberHistoryVisibility namespace', () => {
expect(envelope.body?.settings?.groupFlagExt4Mask).toBe(GROUP_HISTORY_VISIBILITY_MASK); expect(envelope.body?.settings?.groupFlagExt4Mask).toBe(GROUP_HISTORY_VISIBILITY_MASK);
}); });
it('rejects an invalid current flag before sending', async () => { it('rejects an invalid current flag when merging', () => {
const sender = makeSender(); expect(() => mergeGroupHistoryVisibility(-1, true)).toThrow(/unsigned 32-bit/);
await expect(SetNewMemberHistoryVisibility.invoke(sender, {
groupId: 1,
currentGroupFlagExt4: -1,
visible: true,
})).rejects.toThrow(/unsigned 32-bit/);
expect(sender.sendRawPacket).not.toHaveBeenCalled();
}); });
}); });