fix(core): restore group remarks in queries

Request and retain the group remark information needed by group list and group detail queries while preserving the existing safeguards for large rosters.

Synchronize confirmed group remark changes with the local identity roster and persistent cache. Remote failures leave local state untouched, and missing roster entries remain observable without creating phantom groups.

Add regression coverage for query mapping, request scope, persistence, failed updates, unknown groups, and closed identity stores.

Fixes #304
This commit is contained in:
DrSmoothl committed 2026-08-01 21:11:02 +08:00
1 parent 6372e1479c
commit fb4d7716a1
10 files changed
+173 -10

No files matched your search

@@ -5,8 +5,9 @@
// per-group fields to include. Asking for everything blows the
// named-pipe write buffer on accounts with ~200+ groups (see #42),
// so we keep `config1.*` mostly on but turn off the costly
// `field5002`/`field5003` and entire `config2` block that never map
// back to a decoded field anyway.
// `field5002`/`field5003` and the unused `config2` fields. `config2.remark`
// is the bot-local group remark returned as `customInfo.remark`, so it is the
// sole optional field enabled in that block.
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase, OidbSvcTrpcTcp0xFE5_2Response } from '@snowluma/proto-defs/oidb';
@@ -37,7 +38,7 @@ export namespace FetchGroupList {
field32: allTrue, field5001: allTrue, field5002: false, field5003: false,
},
config2: {
field1: false, field2: false, field3: false, field4: false,
field1: false, field2: false, remark: true, field4: false,
field5: false, field6: false, field7: false, field8: false,
},
config3: { field5: allTrue, field6: allTrue },
@@ -2,16 +2,20 @@
// the bot sees this — the group's actual name is untouched).
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import { createLogger } from '@snowluma/common/logger';
import type { OidbBase, OidbEmpty } from '@snowluma/proto-defs/oidb';
import type { Oidb0xf16Req } from '@snowluma/proto-defs/oidb-actions/base';
import { invokeOidb, type OidbSender } from '../../oidb-service';
import type { BridgeContext } from '../../bridge-context';
const log = createLogger('Bridge.GroupAdmin');
export namespace SetGroupRemark {
export const command = 0xF16;
export const subCommand = 1;
export interface Params { groupId: number; remark: string; }
export type Deps = OidbSender;
export type Deps = OidbSender & Pick<BridgeContext, 'identity'>;
export const serialize = (_ctx: Deps, p: Params): Oidb0xf16Req => ({
inner: { groupId: BigInt(p.groupId), remark: p.remark },
@@ -24,6 +28,28 @@ export namespace SetGroupRemark {
export const decode = (bytes: Uint8Array): OidbBase<OidbEmpty> =>
protobuf_decode<OidbBase<OidbEmpty>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<void> =>
invokeOidb(deps, SetGroupRemark, params);
export const invoke = async (deps: Deps, params: Params): Promise<void> => {
await invokeOidb(deps, SetGroupRemark, params);
// QQ has already accepted the mutation. Keep the local roster coherent,
// but never turn a local-cache problem into a false remote failure that
// encourages callers to repeat the mutation.
try {
const updated = deps.identity.updateGroupRemark(params.groupId, params.remark);
if (!updated) {
log.warn(
'local group roster did not contain server-confirmed remark target: uin=%s group=%d',
deps.identity.uin,
params.groupId,
);
}
} catch (error: unknown) {
log.error(
'local identity synchronization failed after confirmed group remark update: uin=%s group=%d: %s',
deps.identity.uin,
params.groupId,
error instanceof Error ? error.message : String(error),
);
}
};
}