refactor(api): move interaction methods to InteractionApi (#6 commit 6/13)

Folds the entire `actions/interaction.ts` (sendPoke / sendLike /
setGroupReaction / getEmojiLikes) plus the lone-survivor
`setGroupEssence` from `actions/group-message.ts` into
`apis/interaction.ts::InteractionApi`. Both action files deleted —
the recall + markRead halves of group-message were already absorbed
into MessageApi back in commit 1.

Skipping the planned standalone GroupMessageApi commit: with only one
method left (`setGroupEssence`), giving it its own Api class would be
pure overhead. Essence is conceptually an "interaction" anyway (mark
a message as essence is parallel to "react with an emoji").

Method renaming (Api namespace already says "interaction"):

  sendPoke              → sendPoke     (no rename — already minimal)
  sendLike              → sendLike
  setGroupReaction      → setReaction
  setGroupEssence       → setEssence
  getEmojiLikes         → getEmojiLikes (no rename — read-side, fine)

Callers updated: `instance-context.ts`, `modules/message-actions.ts`,
`actions/extended.ts`. Tests `interaction.test.ts` rewritten to use
`new InteractionApi(bridge as any).method(...)` and gained a
`setEssence` test. `group-message.test.ts` rewritten to target
MessageApi.recall* / markRead* methods that were already moved.

587/587 tests pass.
This commit is contained in:
DrSmoothl committed 2026-05-20 23:17:51 +08:00
1 parent c92daa56df
commit 73f1cd3c80
11 files changed
+155 -221

No files matched your search

@@ -1,92 +0,0 @@
import { protobuf_encode } from '@snowluma/proton';
import type { Bridge } from '../bridge';
import { makeOidbEnvelope, runOidb } from '../bridge-oidb';
import { OidbBase } from '@snowluma/proto-defs/oidb';
import type { C2CRecallRequest, GroupRecallRequest, OidbEssence, SsoReadedReportReq } from '@snowluma/proto-defs/oidb-actions/base';
export async function recallGroupMessage(bridge: Bridge, groupId: number, sequence: number): Promise<void> {
const request = protobuf_encode<GroupRecallRequest>({
type: 1,
groupUin: groupId,
info: { sequence, random: 0, field3: 0 },
settings: { field1: 0 },
});
const result = await bridge.sendRawPacket('trpc.msg.msg_svc.MsgService.SsoGroupRecallMsg', request);
if (!result.success) throw new Error(result.errorMessage || 'recall group message failed');
}
export async function recallPrivateMessage(
bridge: Bridge, userUin: number, clientSeq: number,
msgSeq: number, random: number, timestamp: number,
): Promise<void> {
const targetUid = await bridge.resolveUserUid(userUin);
const request = protobuf_encode<C2CRecallRequest>({
type: 1,
targetUid,
info: {
clientSequence: clientSeq,
random,
messageId: BigInt((0x01000000 * 0x100000000) + random),
timestamp,
field5: 0,
messageSequence: msgSeq,
},
settings: { field1: false, field2: false },
field6: false,
});
const result = await bridge.sendRawPacket('trpc.msg.msg_svc.MsgService.SsoC2CRecallMsg', request);
if (!result.success) throw new Error(result.errorMessage || 'recall private message failed');
}
export async function markPrivateMessageRead(
bridge: Bridge,
userId: number,
msgSeq: number,
timestamp: number = Math.floor(Date.now() / 1000),
): Promise<void> {
const uid = await bridge.resolveUserUid(userId);
const request = protobuf_encode<SsoReadedReportReq>({
c2cList: [
{
uid,
lastReadTime: BigInt(timestamp),
lastReadSeq: BigInt(msgSeq),
},
],
});
const result = await bridge.sendRawPacket('trpc.msg.msg_svc.MsgService.SsoReadedReport', request);
if (!result.success) {
throw new Error(result.errorMessage || 'mark private message read failed');
}
}
export async function markGroupMessageRead(
bridge: Bridge,
groupId: number,
msgSeq: number,
): Promise<void> {
const request = protobuf_encode<SsoReadedReportReq>({
groupList: [
{
groupUin: BigInt(groupId),
lastReadSeq: BigInt(msgSeq),
},
],
});
const result = await bridge.sendRawPacket('trpc.msg.msg_svc.MsgService.SsoReadedReport', request);
if (!result.success) {
throw new Error(result.errorMessage || 'mark group message read failed');
}
}
export async function setGroupEssence(bridge: Bridge, groupId: number, sequence: number, random: number, enable: boolean): Promise<void> {
const subCmd = enable ? 1 : 2;
const cmd = enable ? 'OidbSvcTrpcTcp.0xeac_1' : 'OidbSvcTrpcTcp.0xeac_2';
const env = makeOidbEnvelope<OidbEssence>(0xEAC, subCmd, { groupUin: groupId, sequence, random });
await runOidb(bridge, cmd, protobuf_encode<OidbBase<OidbEssence>>(env));
}
@@ -1,66 +0,0 @@
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { Bridge } from '../bridge';
import { makeOidbEnvelope, runOidb } from '../bridge-oidb';
import { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
Oidb0x9083Req,
Oidb0x9083Resp,
OidbGroupReaction,
OidbLike,
OidbPoke,
} from '@snowluma/proto-defs/oidb-actions/base';
export async function sendPoke(bridge: Bridge, isGroup: boolean, peerUin: number, targetUin?: number): Promise<void> {
const env = makeOidbEnvelope<OidbPoke>(0xED3, 1, {
uin: targetUin ?? peerUin,
groupUin: isGroup ? peerUin : 0,
friendUin: isGroup ? 0 : peerUin,
ext: 0,
});
await runOidb(bridge, 'OidbSvcTrpcTcp.0xed3_1', protobuf_encode<OidbBase<OidbPoke>>(env));
}
export async function sendLike(bridge: Bridge, userId: number, count: number): Promise<void> {
const env = makeOidbEnvelope<OidbLike>(0x7E5, 104, { targetUin: userId, count });
await runOidb(bridge, 'OidbSvcTrpcTcp.0x7e5_104', protobuf_encode<OidbBase<OidbLike>>(env));
}
export async function setGroupReaction(bridge: Bridge, groupId: number, sequence: number, code: string, isSet: boolean): Promise<void> {
const subCmd = isSet ? 1 : 2;
const cmd = isSet ? 'OidbSvcTrpcTcp.0x9082_1' : 'OidbSvcTrpcTcp.0x9082_2';
// Same heuristic NapCat uses: QQ face ids are 1–3 digits ("76"),
// unicode codepoints are longer ("128516"). Server requires the
// type field to pick the right resolution table; omitting it makes
// unicode reactions silently fail.
const type = code.length > 3 ? 2 : 1;
const env = makeOidbEnvelope<OidbGroupReaction>(0x9082, subCmd, { groupUin: groupId, sequence, code, type });
await runOidb(bridge, cmd, protobuf_encode<OidbBase<OidbGroupReaction>>(env));
}
export async function getEmojiLikes(
bridge: Bridge,
groupId: number,
sequence: number,
emojiId: string,
emojiType: number = 1,
count: number = 10,
cookie: string = '',
): Promise<{ users: Array<{ uin: number }>, cookie: string, isLast: boolean }> {
const req: any = {
groupId: BigInt(groupId),
sequence,
emojiType,
emojiId,
cookie: cookie ? Buffer.from(cookie, 'base64') : new Uint8Array(0),
field7: 0,
count,
field12: 1,
};
const env = makeOidbEnvelope<Oidb0x9083Req>(0x9083, 1, req);
const respBytes = await runOidb(bridge, 'OidbSvcTrpcTcp.0x9083_1', protobuf_encode<OidbBase<Oidb0x9083Req>>(env));
const resp = protobuf_decode<OidbBase<Oidb0x9083Resp>>(respBytes).body;
const uin = resp?.inner?.userInfo?.uin;
const users = uin ? [{ uin: Number(uin) }] : [];
const respCookie = resp?.cookie ? Buffer.from(resp.cookie).toString('base64') : '';
return { users, cookie: respCookie, isLast: !respCookie };
}
+5
View File
@@ -25,6 +25,7 @@ import { ContactsApi } from './contacts';
import { GroupAdminApi } from './group-admin';
import { GroupAlbumApi } from './group-album';
import { GroupFileApi } from './group-file';
import { InteractionApi } from './interaction';
import { MessageApi } from './message';
export interface ApiHub {
@@ -38,6 +39,8 @@ export interface ApiHub {
readonly groupFile: GroupFileApi;
/** Group photo album: list/upload/comment/like/delete + media listing. */
readonly groupAlbum: GroupAlbumApi;
/** Interactive engagement: poke / like / reaction / essence / emoji-like-list. */
readonly interaction: InteractionApi;
// Pending — added as later commits land:
// readonly friend: FriendApi;
// readonly interaction: InteractionApi;
@@ -63,6 +66,7 @@ export function buildApiHub(ctx: BridgeContext): ApiHub {
groupAdmin: new GroupAdminApi(ctx),
groupFile: new GroupFileApi(ctx),
groupAlbum: new GroupAlbumApi(ctx),
interaction: new InteractionApi(ctx),
};
}
@@ -73,4 +77,5 @@ export { ContactsApi } from './contacts';
export { GroupAdminApi } from './group-admin';
export { GroupAlbumApi } from './group-album';
export { GroupFileApi } from './group-file';
export { InteractionApi } from './interaction';
export { MessageApi } from './message';
@@ -0,0 +1,92 @@
// InteractionApi — interactive engagement primitives (poke / like /
// reaction / essence / emoji-like-list). Inlined from
// `actions/interaction.ts` + the lone-survivor `setGroupEssence` from
// `actions/group-message.ts` (both deleted alongside actions/* in
// commit 13). The recall+markRead halves of `group-message.ts` were
// already absorbed into `MessageApi` back in commit 1.
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
Oidb0x9083Req,
Oidb0x9083Resp,
OidbEssence,
OidbGroupReaction,
OidbLike,
OidbPoke,
} from '@snowluma/proto-defs/oidb-actions/base';
import type { BridgeContext } from '../bridge-context';
import type { Bridge } from '../bridge';
import { makeOidbEnvelope, runOidb } from '../bridge-oidb';
function asBridge(ctx: BridgeContext): Bridge { return ctx as unknown as Bridge; }
export class InteractionApi {
constructor(private readonly ctx: BridgeContext) {}
async sendPoke(isGroup: boolean, peerUin: number, targetUin?: number): Promise<void> {
const bridge = asBridge(this.ctx);
const env = makeOidbEnvelope<OidbPoke>(0xED3, 1, {
uin: targetUin ?? peerUin,
groupUin: isGroup ? peerUin : 0,
friendUin: isGroup ? 0 : peerUin,
ext: 0,
});
await runOidb(bridge, 'OidbSvcTrpcTcp.0xed3_1', protobuf_encode<OidbBase<OidbPoke>>(env));
}
async sendLike(userId: number, count: number): Promise<void> {
const bridge = asBridge(this.ctx);
const env = makeOidbEnvelope<OidbLike>(0x7E5, 104, { targetUin: userId, count });
await runOidb(bridge, 'OidbSvcTrpcTcp.0x7e5_104', protobuf_encode<OidbBase<OidbLike>>(env));
}
async setReaction(groupId: number, sequence: number, code: string, isSet: boolean): Promise<void> {
const bridge = asBridge(this.ctx);
const subCmd = isSet ? 1 : 2;
const cmd = isSet ? 'OidbSvcTrpcTcp.0x9082_1' : 'OidbSvcTrpcTcp.0x9082_2';
// Same heuristic NapCat uses: QQ face ids are 1–3 digits ("76"),
// unicode codepoints are longer ("128516"). Server requires the
// type field to pick the right resolution table; omitting it makes
// unicode reactions silently fail.
const type = code.length > 3 ? 2 : 1;
const env = makeOidbEnvelope<OidbGroupReaction>(0x9082, subCmd, { groupUin: groupId, sequence, code, type });
await runOidb(bridge, cmd, protobuf_encode<OidbBase<OidbGroupReaction>>(env));
}
async setEssence(groupId: number, sequence: number, random: number, enable: boolean): Promise<void> {
const bridge = asBridge(this.ctx);
const subCmd = enable ? 1 : 2;
const cmd = enable ? 'OidbSvcTrpcTcp.0xeac_1' : 'OidbSvcTrpcTcp.0xeac_2';
const env = makeOidbEnvelope<OidbEssence>(0xEAC, subCmd, { groupUin: groupId, sequence, random });
await runOidb(bridge, cmd, protobuf_encode<OidbBase<OidbEssence>>(env));
}
async getEmojiLikes(
groupId: number,
sequence: number,
emojiId: string,
emojiType = 1,
count = 10,
cookie = '',
): Promise<{ users: Array<{ uin: number }>; cookie: string; isLast: boolean }> {
const bridge = asBridge(this.ctx);
const req: any = {
groupId: BigInt(groupId),
sequence,
emojiType,
emojiId,
cookie: cookie ? Buffer.from(cookie, 'base64') : new Uint8Array(0),
field7: 0,
count,
field12: 1,
};
const env = makeOidbEnvelope<Oidb0x9083Req>(0x9083, 1, req);
const respBytes = await runOidb(bridge, 'OidbSvcTrpcTcp.0x9083_1', protobuf_encode<OidbBase<Oidb0x9083Req>>(env));
const resp = protobuf_decode<OidbBase<Oidb0x9083Resp>>(respBytes).body;
const uin = resp?.inner?.userInfo?.uin;
const users = uin ? [{ uin: Number(uin) }] : [];
const respCookie = resp?.cookie ? Buffer.from(resp.cookie).toString('base64') : '';
return { users, cookie: respCookie, isLast: !respCookie };
}
}
+3 -6
View File
@@ -44,8 +44,7 @@ export interface BridgeInterface {
// ─── Fetch (contacts / profile / system) — moved to apis.contacts ───
// ─── Group admin (moved to apis.groupAdmin) ───
setGroupReaction(groupId: number, sequence: number, code: string, isSet: boolean): Promise<void>;
setGroupEssence(groupId: number, sequence: number, random: number, enable: boolean): Promise<void>;
// ─── Group reaction / essence (moved to apis.interaction) ───
// ─── Friend ───
setFriendAddRequest(uidOrFlag: string, approve: boolean): Promise<void>;
@@ -71,10 +70,8 @@ export interface BridgeInterface {
// ─── Message ops (moved to apis.message) ───
// ─── Interaction ───
sendPoke(isGroup: boolean, peerUin: number, targetUin?: number): Promise<void>;
sendLike(userId: number, count: number): Promise<void>;
getEmojiLikes(groupId: number, sequence: number, emojiId: string, emojiType?: number, count?: number, cookie?: string): Promise<{ users: Array<{ uin: number }>; cookie: string; isLast: boolean }>;
// ─── Interaction (moved to apis.interaction) ───
// - sendPoke / sendLike / setReaction / setEssence / getEmojiLikes
// ─── Web-backed ───
getGroupHonorInfo(groupId: number, type: WebHonorType | string): Promise<any>;
+7 -16
View File
@@ -38,15 +38,11 @@ import {
// result type still lives here because the OneBot side imports it
// through bridge.ts.
import type { GroupFilesResult } from './apis/group-file';
import {
setGroupEssence as setGroupEssence_,
} from './actions/group-message';
import {
getEmojiLikes as getEmojiLikes_,
sendLike as sendLike_,
sendPoke as sendPoke_,
setGroupReaction as setGroupReaction_,
} from './actions/interaction';
// actions/group-message.ts removed — `setGroupEssence` moved to
// apis/interaction.ts::InteractionApi. The recall/markRead helpers
// were absorbed into MessageApi back in commit 1.
// actions/interaction.ts removed — sendPoke/sendLike/setReaction/
// getEmojiLikes moved to apis/interaction.ts::InteractionApi.
import {
clickInlineKeyboardButton as clickInlineKeyboardButton_,
getMiniAppArk as getMiniAppArk_,
@@ -330,10 +326,8 @@ export class Bridge implements BridgeInterface {
// apis.groupFile (apis/group-file.ts::GroupFileApi).
async uploadForwardNodes(nodes: ForwardNodePayload[], groupId?: number, userId?: number): Promise<string> { return uploadForwardNodes_(this, nodes, groupId, userId); }
async fetchForwardNodes(resId: string): Promise<ForwardNodePayload[]> { return fetchForwardNodes_(this, resId); }
async sendPoke(isGroup: boolean, peerUin: number, targetUin?: number): Promise<void> { return sendPoke_(this, isGroup, peerUin, targetUin); }
async sendLike(userId: number, count: number): Promise<void> { return sendLike_(this, userId, count); }
async setGroupEssence(groupId: number, sequence: number, random: number, enable: boolean): Promise<void> { return setGroupEssence_(this, groupId, sequence, random, enable); }
async setGroupReaction(groupId: number, sequence: number, code: string, isSet: boolean): Promise<void> { return setGroupReaction_(this, groupId, sequence, code, isSet); }
// Interaction methods (sendPoke/sendLike/setReaction/setEssence/
// getEmojiLikes) moved to apis.interaction.
// recall* / markRead* moved to apis/message.ts::MessageApi.
async setFriendRemark(userId: number, remark: string): Promise<void> { return setFriendRemark_(this, userId, remark); }
async getGroupHonorInfo(groupId: number, type: WebHonorType | string): Promise<any> {
@@ -409,9 +403,6 @@ export class Bridge implements BridgeInterface {
async fetchCustomFace(count?: number): Promise<string[]> {
return fetchCustomFace_(this, count);
}
async getEmojiLikes(groupId: number, sequence: number, emojiId: string, emojiType?: number, count?: number, cookie?: string) {
return getEmojiLikes_(this, groupId, sequence, emojiId, emojiType, count, cookie);
}
// --- Tier-2 napcat-parity extras (group todo, stranger status, AI voice) ---
+4 -4
View File
@@ -88,7 +88,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
const userId = asNumber(params.user_id);
const times = asNumber(params.times) || 1;
if (!userId) return failedResponse(RETCODE.BAD_REQUEST, 'user_id is required');
await ctx.bridge.sendLike(userId, times);
await ctx.bridge.apis.interaction.sendLike(userId, times);
return okResponse();
});
@@ -177,7 +177,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
return failedResponse(RETCODE.BAD_REQUEST, 'group_id does not match message session');
}
await ctx.bridge.setGroupReaction(meta.targetId, meta.sequence, code, isSet);
await ctx.bridge.apis.interaction.setReaction(meta.targetId, meta.sequence, code, isSet);
return okResponse();
});
@@ -822,7 +822,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
try {
const meta = ctx.getMessageMeta(messageId);
if (!meta?.isGroup || !meta?.sequence) return failedResponse(RETCODE.BAD_REQUEST, 'message not found or not a group message');
const result = await ctx.bridge.getEmojiLikes(meta.targetId, meta.sequence, emojiId);
const result = await ctx.bridge.apis.interaction.getEmojiLikes(meta.targetId, meta.sequence, emojiId);
return okResponse({ emoji_like_list: result.users.map(u => ({ user_id: String(u.uin), nick_name: '' })) });
} catch (e) {
return failedResponse(RETCODE.ACTION_FAILED, String(e));
@@ -839,7 +839,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
try {
const meta = ctx.getMessageMeta(messageId);
if (!meta?.isGroup || !meta?.sequence) return failedResponse(RETCODE.BAD_REQUEST, 'message not found or not a group message');
const result = await ctx.bridge.getEmojiLikes(meta.targetId, meta.sequence, emojiId, emojiType, count, cookie);
const result = await ctx.bridge.apis.interaction.getEmojiLikes(meta.targetId, meta.sequence, emojiId, emojiType, count, cookie);
return okResponse({
result: 0,
errMsg: '',
+4 -4
View File
@@ -137,8 +137,8 @@ export function buildApiContext(ref: OneBotInstanceContext): ApiActionContext {
handleGroupRequest: (flag, _subType, approve, reason) => handleGroupAddRequest(bridge, flag, approve, reason),
// Pokes — flatten isGroup into the bridge signature.
sendFriendPoke: (userId, targetId) => bridge.sendPoke(false, userId, targetId),
sendGroupPoke: (groupId, userId) => bridge.sendPoke(true, groupId, userId),
sendFriendPoke: (userId, targetId) => bridge.apis.interaction.sendPoke(false, userId, targetId),
sendGroupPoke: (groupId, userId) => bridge.apis.interaction.sendPoke(true, groupId, userId),
// Essence — bake the set/unset boolean.
setEssenceMsg: (messageId) => setEssenceMessage(bridge, messageStore, messageId, true),
@@ -176,7 +176,7 @@ export function buildApiContext(ref: OneBotInstanceContext): ApiActionContext {
// there is no wire path to forward this to; fail loudly instead
// of silently no-op'ing.
if (!meta.isGroup) throw new Error('emoji reactions are not supported on private messages');
await bridge.setGroupReaction(meta.targetId, meta.sequence, emojiId, set);
await bridge.apis.interaction.setReaction(meta.targetId, meta.sequence, emojiId, set);
},
markGroupMsgAsRead: (groupId, sequence) => bridge.apis.message.markGroupRead(groupId, sequence),
markPrivateMsgAsRead: (userId, sequence) => bridge.apis.message.markPrivateRead(userId, sequence),
@@ -201,7 +201,7 @@ export function buildApiContext(ref: OneBotInstanceContext): ApiActionContext {
// Extended
fetchCustomFace: (count) => bridge.fetchCustomFace(count),
getEmojiLikes: (groupId, sequence, emojiId, emojiType, count, cookie) => bridge.getEmojiLikes(groupId, sequence, emojiId, emojiType, count, cookie),
getEmojiLikes: (groupId, sequence, emojiId, emojiType, count, cookie) => bridge.apis.interaction.getEmojiLikes(groupId, sequence, emojiId, emojiType, count, cookie),
// Media lookup.
getImageInfo: (file) => getCachedImageInfo(mediaStore, file),
@@ -85,7 +85,7 @@ export async function setEssenceMessage(
): Promise<void> {
const meta = messageStore.findMeta(messageId);
if (!meta || !meta.isGroup) throw new Error('message not found or not a group message');
await bridge.setGroupEssence(meta.targetId, meta.sequence, meta.random, enable);
await bridge.apis.interaction.setEssence(meta.targetId, meta.sequence, meta.random, enable);
}
export async function sendPrivateMessage(
@@ -1,3 +1,9 @@
// MessageApi recall + markRead coverage. (The send* paths live in their
// own test file because they need element-builder fixtures the recall
// paths don't.) Renamed from the legacy `actions/group-message` shape
// after #6 commit 1 moved the recall + markRead helpers onto MessageApi
// and #6 commit 6 absorbed setEssence into InteractionApi.
import { describe, it, expect, vi, beforeEach } from 'vitest';
vi.mock('../../src/bridge/bridge-oidb', () => ({
@@ -7,25 +13,23 @@ vi.mock('../../src/bridge/bridge-oidb', () => ({
decodeOidbEnv: vi.fn(() => ({ body: {} })),
}));
import * as oidb from '../../src/bridge/bridge-oidb';
import * as msg from '../../src/bridge/actions/group-message';
import { MessageApi } from '../../src/bridge/apis/message';
import { mockBridge } from './_helpers';
describe('actions/group-message', () => {
describe('apis/message — recall + markRead', () => {
beforeEach(() => {
vi.mocked(oidb.runOidb).mockClear();
vi.mocked(oidb.makeOidbEnvelope).mockClear();
// No global mock state to reset — sendRawPacket is per-bridge.
});
it('recallGroupMessage sends to SsoGroupRecallMsg with the group sequence', async () => {
it('recallGroup sends to SsoGroupRecallMsg with the group sequence', async () => {
const bridge = mockBridge();
await msg.recallGroupMessage(bridge as any, 12345, 999);
await new MessageApi(bridge as any).recallGroup(12345, 999);
expect(bridge.sendRawPacket).toHaveBeenCalledOnce();
const [serviceCmd] = bridge.sendRawPacket.mock.calls[0]!;
expect(serviceCmd).toBe('trpc.msg.msg_svc.MsgService.SsoGroupRecallMsg');
});
it('recallGroupMessage throws when sendRawPacket reports failure', async () => {
it('recallGroup throws when sendRawPacket reports failure', async () => {
const bridge = mockBridge({
sendRawPacket: vi.fn(async () => ({
success: false,
@@ -35,22 +39,23 @@ describe('actions/group-message', () => {
responseData: null,
})) as any,
});
await expect(msg.recallGroupMessage(bridge as any, 12345, 999))
await expect(new MessageApi(bridge as any).recallGroup(12345, 999))
.rejects.toThrow(/network down/);
});
it('recallPrivateMessage resolves the target UID before dispatch', async () => {
it('recallPrivate resolves the target UID before dispatch', async () => {
const bridge = mockBridge();
await msg.recallPrivateMessage(bridge as any, 10001, 100, 200, 123, 1700000000);
await new MessageApi(bridge as any).recallPrivate(10001, 100, 200, 123, 1700000000);
expect(bridge.resolveUserUid).toHaveBeenCalledWith(10001);
const [serviceCmd] = bridge.sendRawPacket.mock.calls[0]!;
expect(serviceCmd).toBe('trpc.msg.msg_svc.MsgService.SsoC2CRecallMsg');
});
it('markGroupMessageRead and markPrivateMessageRead both hit SsoReadedReport', async () => {
it('markGroupRead and markPrivateRead both hit SsoReadedReport', async () => {
const bridge = mockBridge();
await msg.markGroupMessageRead(bridge as any, 12345, 50);
await msg.markPrivateMessageRead(bridge as any, 10001, 60);
const api = new MessageApi(bridge as any);
await api.markGroupRead(12345, 50);
await api.markPrivateRead(10001, 60);
expect(bridge.sendRawPacket).toHaveBeenCalledTimes(2);
const cmds = bridge.sendRawPacket.mock.calls.map((c: any) => c[0]);
expect(cmds).toEqual([
@@ -58,12 +63,4 @@ describe('actions/group-message', () => {
'trpc.msg.msg_svc.MsgService.SsoReadedReport',
]);
});
it('setGroupEssence picks _1 for enable and _2 for disable', async () => {
const bridge = mockBridge();
await msg.setGroupEssence(bridge as any, 12345, 5, 7, true);
await msg.setGroupEssence(bridge as any, 12345, 5, 7, false);
const cmds = vi.mocked(oidb.runOidb).mock.calls.map(c => c[1]);
expect(cmds).toEqual(['OidbSvcTrpcTcp.0xeac_1', 'OidbSvcTrpcTcp.0xeac_2']);
});
});
+20 -10
View File
@@ -22,10 +22,10 @@ vi.mock('../../src/bridge/bridge-oidb', async () => {
});
import * as oidb from '../../src/bridge/bridge-oidb';
import * as inter from '../../src/bridge/actions/interaction';
import { InteractionApi } from '../../src/bridge/apis/interaction';
import { mockBridge } from './_helpers';
describe('actions/interaction', () => {
describe('apis/interaction', () => {
beforeEach(() => {
vi.mocked(oidb.runOidb).mockReset();
vi.mocked(oidb.runOidb).mockResolvedValue(new Uint8Array());
@@ -34,35 +34,45 @@ describe('actions/interaction', () => {
it('sendPoke group: groupUin set, friendUin=0', async () => {
const bridge = mockBridge();
await inter.sendPoke(bridge as any, true, 12345, 67890);
await new InteractionApi(bridge as any).sendPoke(true, 12345, 67890);
const body = vi.mocked(oidb.makeOidbEnvelope).mock.calls[0]![2];
expect(body).toMatchObject({ uin: 67890, groupUin: 12345, friendUin: 0 });
});
it('sendPoke friend: friendUin set, groupUin=0, targetUin defaults to peer', async () => {
const bridge = mockBridge();
await inter.sendPoke(bridge as any, false, 67890);
await new InteractionApi(bridge as any).sendPoke(false, 67890);
const body = vi.mocked(oidb.makeOidbEnvelope).mock.calls[0]![2];
expect(body).toMatchObject({ uin: 67890, groupUin: 0, friendUin: 67890 });
});
it('sendLike forwards target + count to 0x7e5_104', async () => {
const bridge = mockBridge();
await inter.sendLike(bridge as any, 10001, 3);
await new InteractionApi(bridge as any).sendLike(10001, 3);
const [, cmd] = vi.mocked(oidb.runOidb).mock.calls[0]!;
expect(cmd).toBe('OidbSvcTrpcTcp.0x7e5_104');
const body = vi.mocked(oidb.makeOidbEnvelope).mock.calls[0]![2];
expect(body).toMatchObject({ targetUin: 10001, count: 3 });
});
it('setGroupReaction picks _1 for set and _2 for unset', async () => {
it('setReaction picks _1 for set and _2 for unset', async () => {
const bridge = mockBridge();
await inter.setGroupReaction(bridge as any, 12345, 99, '128516', true);
await inter.setGroupReaction(bridge as any, 12345, 99, '128516', false);
const api = new InteractionApi(bridge as any);
await api.setReaction(12345, 99, '128516', true);
await api.setReaction(12345, 99, '128516', false);
const cmds = vi.mocked(oidb.runOidb).mock.calls.map(c => c[1]);
expect(cmds).toEqual(['OidbSvcTrpcTcp.0x9082_1', 'OidbSvcTrpcTcp.0x9082_2']);
});
it('setEssence picks _1 for enable and _2 for disable', async () => {
const bridge = mockBridge();
const api = new InteractionApi(bridge as any);
await api.setEssence(12345, 99, 0, true);
await api.setEssence(12345, 99, 0, false);
const cmds = vi.mocked(oidb.runOidb).mock.calls.map(c => c[1]);
expect(cmds).toEqual(['OidbSvcTrpcTcp.0xeac_1', 'OidbSvcTrpcTcp.0xeac_2']);
});
it('getEmojiLikes decodes user list, base64-encodes cookie, and reports isLast', async () => {
const bridge = mockBridge();
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
@@ -73,7 +83,7 @@ describe('actions/interaction', () => {
} as any,
}),
);
const out = await inter.getEmojiLikes(bridge as any, 12345, 99, '128516');
const out = await new InteractionApi(bridge as any).getEmojiLikes(12345, 99, '128516');
expect(out.users).toEqual([{ uin: 10001 }]);
expect(out.cookie).toBe(Buffer.from([0xCA, 0xFE]).toString('base64'));
expect(out.isLast).toBe(false);
@@ -84,7 +94,7 @@ describe('actions/interaction', () => {
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
protobuf_encode<OidbBase<Oidb0x9083Resp>>({ body: {} }),
);
const out = await inter.getEmojiLikes(bridge as any, 12345, 99, '128516');
const out = await new InteractionApi(bridge as any).getEmojiLikes(12345, 99, '128516');
expect(out.users).toEqual([]);
expect(out.isLast).toBe(true);
});