feat(emoji-like): back fetch_emoji_like / get_emoji_likes with a local cache
Two rounds of production wire-level probing established that the OIDB
SSO path cannot surface the reactor user list for an emoji:
- 0x9083_1 → 4-byte ack `18 01 20 01` (no list)
- 0x9084_1 → per-emoji summary (count + timestamp,
still no user IDs)
- 0x9082_3..5, 0x9083_0/2/3, 0x9084_2..5, 0x9085_1/2, 0x9087_1
→ "no privilege" — the cmds exist but
aren't in NTQQ's client capability
bitmap, so the server blocks anything
not registered at login. NTQQ itself
serves getMsgEmojiLikesList from a
wrapper-internal cache, not SSO.
Mirror that wrapper-cache approach on the OneBot side. SnowLuma
already receives GroupMsgEmojiLikeEvent push events for every
reaction add/remove (with operator uin + uid + emoji + msgSeq); we
just weren't persisting them. Now we do.
Changes:
* proto-defs: add Oidb0x9084 Req/Resp schema for the summary call.
RespEntry's lastReactionTime/count are optional because the
"available reactions catalog" tail entries omit both — only the
"used" subset carries metadata.
* core InteractionApi: revert the 9-candidate probe loop, restore a
single 0x9083_1 call as a legacy stub (returns empty list, with a
debug-level hex dump on empty responses), and add
fetchReactionSummary() that calls 0x9084_1 and yields the per-emoji
summary (count + last-reaction timestamp).
* onebot ReactionStore: new SQLite-backed cache, schema
reactions(group_id, msg_seq, emoji_id, emoji_type, operator_uin,
operator_uid, set_at), PK on (group_id, msg_seq, emoji_id,
operator_uin). Mirrors MessageStore design — prepared statements at
construction, WAL journal.
* onebot event-pipeline: subscribe group_msg_emoji_like, call
reactionStore.recordAdd / recordRemove before convertAndDispatch so
a fetch_emoji_like racing with the push still sees the new row.
* onebot instance / instance-context: own the ReactionStore, expose
it on OneBotInstanceContext, close it on dispose. New
fetchEmojiLikeUsers helper on ApiActionContext combines local-cache
reads with a 0x9084_1 cross-check so callers can detect cache gaps
(events missed before bot boot, etc).
* onebot actions: get_emoji_likes and fetch_emoji_like now read from
the cache. fetch_emoji_like's NapCat-style cookie becomes a numeric
offset for cache pagination (no real cursor needed against local
SQLite).
* tests: 7 new ReactionStore unit tests (CRUD + pagination +
cross-key isolation + summarizeMessage). Existing event-pipeline
test harness picks up a no-op ReactionStore stub.
This commit is contained in:
10 files changed
+506
-70
No files matched your search
@@ -4,6 +4,7 @@ import type { ApiActionContext } from './api-handler';
|
||||
import type { ConverterContext } from './event-converter';
|
||||
import type { MediaStore } from './media-store';
|
||||
import type { MessageStore } from './message-store';
|
||||
import type { ReactionStore } from './reaction-store';
|
||||
import type { JsonObject, MessageMeta, OneBotConfig } from './types';
|
||||
import {
|
||||
getDownloadRKeys,
|
||||
@@ -60,6 +61,10 @@ export interface OneBotInstanceContext {
|
||||
|
||||
messageStore: MessageStore;
|
||||
mediaStore: MediaStore;
|
||||
/** Local cache of emoji-reaction events keyed by (group, msgSeq, emoji,
|
||||
* reactor). Fed from `GroupMsgEmojiLikeEvent` push by the event
|
||||
* pipeline; queried by fetch_emoji_like / get_emoji_likes. */
|
||||
reactionStore: ReactionStore;
|
||||
|
||||
converterCtx: ConverterContext;
|
||||
|
||||
@@ -86,7 +91,7 @@ export interface OneBotInstanceContext {
|
||||
* happening (set_group_admin, set_online_status, set_avatar, …).
|
||||
*/
|
||||
export function buildApiContext(ref: OneBotInstanceContext): ApiActionContext {
|
||||
const { bridge, messageStore, mediaStore } = ref;
|
||||
const { bridge, messageStore, mediaStore, reactionStore } = ref;
|
||||
|
||||
return {
|
||||
bridge,
|
||||
@@ -152,6 +157,36 @@ export function buildApiContext(ref: OneBotInstanceContext): ApiActionContext {
|
||||
await bridge.apis.interaction.setReaction(meta.targetId, meta.sequence, emojiId, set);
|
||||
},
|
||||
|
||||
// Fetch reactor user list from local cache, cross-checked against
|
||||
// the server's 0x9084_1 summary so callers can tell when the cache
|
||||
// is incomplete (push events missed before bot boot, etc).
|
||||
fetchEmojiLikeUsers: async (messageId, emojiId, count, offset = 0) => {
|
||||
const meta = messageStore.findMeta(messageId);
|
||||
if (!meta) throw new Error('message not found');
|
||||
if (!meta.isGroup) throw new Error('emoji reactions are not supported on private messages');
|
||||
const raw = reactionStore.listUsers(meta.targetId, meta.sequence, emojiId, count, offset);
|
||||
const users = raw.map(r => ({ uin: r.operatorUin, uid: r.operatorUid, setAt: r.setAt }));
|
||||
const cachedCount = reactionStore.countUsers(meta.targetId, meta.sequence, emojiId);
|
||||
// Best-effort server-side count cross-check. If the summary call
|
||||
// itself fails (network blip / server hiccup) we fall back to the
|
||||
// cached count and report complete=true since we have no contrary
|
||||
// evidence.
|
||||
let serverCount = cachedCount;
|
||||
try {
|
||||
const summary = await bridge.apis.interaction.fetchReactionSummary(meta.targetId, meta.sequence);
|
||||
const match = summary.find(s => s.emojiId === emojiId);
|
||||
if (match) serverCount = match.count;
|
||||
} catch {
|
||||
/* keep serverCount = cachedCount */
|
||||
}
|
||||
return {
|
||||
users,
|
||||
cachedCount,
|
||||
serverCount,
|
||||
complete: cachedCount >= serverCount,
|
||||
};
|
||||
},
|
||||
|
||||
// Media lookup.
|
||||
getImageInfo: (file) => getCachedImageInfo(mediaStore, file),
|
||||
getRecordInfo: (file) => getCachedRecordInfo(bridge, mediaStore, file),
|
||||
|
||||
Reference in new issue
Block a user