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,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']);
});
});