feat(protocol): write join question and answer with add option

Question-and-answer join mode now sends the question and answer;
question-only mode sends the question and clears the answer.
This commit is contained in:
DrSmoothl committed 2026-08-17 19:12:43 +08:00
1 parent b1fa11ca05
commit 3cb3024b39
3 files changed
+85 -10

No files matched your search

@@ -4,22 +4,44 @@
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase, OidbEmpty } from '@snowluma/proto-defs/oidb';
import type { Oidb0x89a_0AddOption } from '@snowluma/proto-defs/oidb-actions/base';
import type {
Oidb0x89a_0AddOption,
Oidb0x89a_0AddOptionSettings,
} from '@snowluma/proto-defs/oidb-actions/base';
import { invokeOidb, type OidbSender } from '../../oidb-service';
/** Official join modes that carry a question. 55 is accepted as an alias of 5. */
export function isQuestionAddType(addType: number): boolean {
return addType === 4 || addType === 5 || addType === 55;
}
export function wireAddType(addType: number): number {
return addType === 55 ? 5 : addType;
}
export namespace SetAddOption {
export const command = 0x89A;
export const subCommand = 0;
export interface Params { groupId: number; addType: number; }
export interface Params {
groupId: number;
addType: number;
groupQuestion?: string;
groupAnswer?: string;
}
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): Oidb0x89a_0AddOption => ({
groupUin: BigInt(p.groupId),
settings: { addType: p.addType },
field12: 0,
});
export const serialize = (_ctx: Deps, p: Params): Oidb0x89a_0AddOption => {
const addType = wireAddType(p.addType);
const settings: Oidb0x89a_0AddOptionSettings = { addType };
if (isQuestionAddType(p.addType)) {
settings.groupQuestion = p.groupQuestion ?? '';
// Type 4 keeps the answer; type 5/55 is question-only and clears it.
settings.groupAnswer = addType === 4 ? (p.groupAnswer ?? '') : '';
}
return { groupUin: BigInt(p.groupId), settings, field12: 0 };
};
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};