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:
DrSmoothl committed 2026-05-22 22:08:45 +08:00
1 parent 65636953e7
commit c3675aef7c
10 files changed
+506 -70

No files matched your search

@@ -548,6 +548,46 @@ export interface Oidb0x9083Resp {
inner?: pb<4, Oidb0x9083RespInner>;
cookie?: pb<5, bytes>;
}
// 0x9084_1: fetch reaction summary on a message. Returns one entry per
// emoji used + an "available reactions" catalog tail. Schema decoded
// from production wire dump:
// { 08 0A ← top-level field 1 (uint, meaning unclear: maybe
// "total reactions on msg" or a flag — empirically
// constant across messages)
// 12 0E 08 <ts:varint> 10 <cnt:varint> 18 01 22 02 "76" ← entry 1
// 12 07 18 01 22 03 "124" ← catalog
// ... }
// Used entries always carry field 1 (timestamp) and field 2 (count);
// catalog entries omit both.
export interface Oidb0x9084Req {
groupId?: pb<2, uint_64>;
sequence?: pb<3, uint_64>;
// Server returns the full per-emoji summary regardless of these,
// but we send them to mirror the working 0x9083_1 request shape.
emojiId?: pb<4, string>;
emojiType?: pb<5, uint_32>;
cookie?: pb<6, bytes>;
count?: pb<8, uint_32>;
field12?: pb<12, uint_32>;
}
export interface Oidb0x9084RespEntry {
/** Unix epoch (seconds) of the last reaction. Omitted for catalog
* entries that have never been reacted with on this message. */
lastReactionTime?: pb<1, uint_64>;
/** Number of reactors. Omitted for catalog entries. */
count?: pb<2, uint_32>;
/** Emoji type. 1 for QQ-face / short id, 2 for unicode codepoint. */
emojiType?: pb<3, uint_32>;
emojiId?: pb<4, string>;
}
export interface Oidb0x9084Resp {
/** Top-level varint, observed value `10` constant; semantics unknown. */
field1?: pb<1, uint_32>;
entries?: pb_repeated<2, Oidb0x9084RespEntry>;
}
export interface Oidb0x8a0Req {
groupId?: pb<1, uint_64>;
targetUids?: pb_repeated<3, string>;