feat(chat): hydrate fromUser/toUser via users/show?userIds (notedeck#460)#8
Merged
Conversation
…460)
Misskey 本家の `chat/messages/{user|room}-timeline` REST と `chat:message` WS
は Lite packer 固定で `fromUser` / `toUser` を含まない (Lite packer の仕様で
リクエストパラメータでも切替不可)。`chat/history` だけが Detailed packer で
両方を含む。これにより notedeck では timeline 経由で取得した chat messages
の name/avatar が表示できない不具合があった (実測 65% の cache 行が null)。
本 commit で notecli の API client が透過的に hydrate するように修正:
- `MisskeyClient::get_users_bulk`: `users/show?userIds=[...]` で複数 user を
1 リクエストで bulk 取得 (新規 public API)
- `MisskeyClient::hydrate_chat_message_users`: messages から null になっている
fromUser/toUser を集めて bulk fetch → in-place 埋める private helper。
fetch 失敗は warn ログで済ませて null のまま継続 (best-effort)
- `get_chat_user_messages` / `get_chat_room_messages` の deserialize 直後に
hydrate 呼び出しを追加。`get_chat_history` は Detailed packer なので不要
- WS streaming (`handle_ws_message` の chat:message 分岐) でも hydrate。
`connection_task` / `run_ws_session` / `ws_loop` / `handle_ws_message` の
シグネチャに `api_client` / `account_host` / `account_token` を伝搬。
shadowed `host` 変数 (subscription info の host) との衝突を回避する命名
これで notedeck 側は Cargo.toml の rev を更新するだけで、既存 cache の null
行も次回 prefetch / loadOlder / WS event の UPSERT で自動上書きされて治る。
テスト: api.rs に wiremock ベースで 5 件追加 (bulk fetch / hydrate /
existing user skip / 500 error swallowing / timeline + hydrate 統合)。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Misskey 本家の chat 系 REST/WS は Lite packer 固定で `fromUser` / `toUser` を含まない (リクエストパラメータでも切替不可)。`chat/history` だけが Detailed packer で両方を含む。
本 PR は notecli の API client が `users/show?userIds=[...]` で透過的に hydrate するようにする。
Why
notedeck #460 のチャット履歴キャッシュで「ユーザー名/アイコンが表示できない user」が出ていた。実測で chat_messages_cache 4453 行中 2909 行 (65%) が `fromUser` null。timeline 経由で大量に prefetch された結果、Misskey の Lite packer 仕様 (本家) によって user 情報が抜け落ちている。
Changes
`src/api.rs`
`src/streaming.rs`
Test plan
新規ユニットテスト (wiremock):
```
cargo test --lib # 136 passed (5 新規)
cargo fmt --check
cargo clippy --no-default-features -- -D warnings # 私の変更範囲は warning ゼロ
```
Note
main の CI は本 PR 以前から既存の lint 違反 (`db.rs:1089` ほか) で fail 状態。
本 PR の変更範囲では fmt / clippy / test 全パスしている。既存 lint 違反は別 PR で扱う。
Related
🤖 Generated with Claude Code