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
@@ -810,15 +810,22 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
}
|
||||
});
|
||||
|
||||
// get_emoji_likes / fetch_emoji_like both back into the same
|
||||
// ReactionStore-backed helper. The OIDB-only path can't surface the
|
||||
// user list (server-side capability whitelist blocks every "fetch
|
||||
// reactor" subcmd), so the local cache fed by GroupMsgEmojiLike push
|
||||
// events is the source of truth here. We cross-check totals against
|
||||
// OIDB 0x9084_1 summary so callers can tell when the cache is
|
||||
// incomplete (events missed before bot boot, etc.).
|
||||
h.registerAction('get_emoji_likes', async (params) => {
|
||||
const messageId = asNumber(params.message_id);
|
||||
const emojiId = asString(params.emoji_id) || '';
|
||||
if (!messageId || !emojiId) return failedResponse(RETCODE.BAD_REQUEST, 'message_id and emoji_id are required');
|
||||
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.apis.interaction.getEmojiLikes(meta.targetId, meta.sequence, emojiId);
|
||||
return okResponse({ emoji_like_list: result.users.map(u => ({ user_id: String(u.uin), nick_name: '' })) });
|
||||
const result = await ctx.fetchEmojiLikeUsers(messageId, emojiId, 1000);
|
||||
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));
|
||||
}
|
||||
@@ -827,21 +834,25 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
h.registerAction('fetch_emoji_like', async (params) => {
|
||||
const messageId = asNumber(params.message_id);
|
||||
const emojiId = asString(params.emojiId) || '';
|
||||
const emojiType = asNumber(params.emojiType) || 1;
|
||||
const count = asNumber(params.count) || 10;
|
||||
const cookie = asString(params.cookie) || '';
|
||||
if (!messageId || !emojiId) return failedResponse(RETCODE.BAD_REQUEST, 'message_id and emojiId are required');
|
||||
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.apis.interaction.getEmojiLikes(meta.targetId, meta.sequence, emojiId, emojiType, count, cookie);
|
||||
// Cookie-based pagination doesn't make sense over a local SQLite
|
||||
// store; parse incoming cookie as numeric offset for compatibility
|
||||
// with NapCat-style clients, and emit the next offset on the way
|
||||
// back out when there are still rows past the current page.
|
||||
const offset = cookie ? Number.parseInt(cookie, 10) || 0 : 0;
|
||||
const result = await ctx.fetchEmojiLikeUsers(messageId, emojiId, count, offset);
|
||||
const nextOffset = offset + result.users.length;
|
||||
const isLastPage = nextOffset >= result.cachedCount;
|
||||
return okResponse({
|
||||
result: 0,
|
||||
errMsg: '',
|
||||
emojiLikesList: result.users.map(u => ({ tinyId: String(u.uin), nickName: '', headUrl: '' })),
|
||||
cookie: result.cookie,
|
||||
isLastPage: result.isLast,
|
||||
isFirstPage: !cookie,
|
||||
cookie: isLastPage ? '' : String(nextOffset),
|
||||
isLastPage,
|
||||
isFirstPage: offset === 0,
|
||||
});
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
|
||||
Reference in new issue
Block a user