fix(messaging): persist own-message IDs so bubbles stay right-aligned after reload #210
No reviewers
Labels
No labels
prio_critical
prio_low
type_bug
type_contact
type_issue
type_lead
type_question
type_story
type_task
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
lhumina_code/hero_archipelagos!210
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "development_fix_bubble_own_after_reload"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Fixes the post-reload regression of #62: after F5, every message bubble was rendering as
bubble-other(left-aligned, no checkmark) because the optimistic-send patch inarchipelago.rsonly fired inhandle_send, while the chat-load path refetched messages from the server withsender_public_key = "system"and no way to identify which were authored locally.This PR persists the SIDs of locally-authored messages in a per-context
localStorageset and falls back to acontains()check insidechatmessage_to_messagedatawhenever the existingown_user_keymatch doesn't fire. Once auth lands and the server stamps a realsender_public_key, the existing key-match path takes precedence and the persisted-IDs path becomes a no-op.Also bundles a 9-line
mutpatch toserver/src/main.rsthat unblocks the showcase wasm build (11 pre-existing E0596 errors ondevelopmentwere preventingmake runfrom compiling).Related Issue
Closes #192
Changes
archipelagos/messaging/Cargo.toml— added"Storage"to theweb-sysfeatures list.archipelagos/messaging/src/services/messaging_service.rs:pub struct OwnMessageIds(HashSet+ orderedVec, FIFO-capped atMAX_OWN_IDS_PER_CONTEXT = 5_000).pub fn load_own_message_ids(context_name)/pub fn save_own_message_ids(context_name, &ids)with cfg-gatedlocalStorageon wasm32 (keyhero_messaging_own_msg_ids:<context>) and a no-op on native.chatmessage_to_messagedatato take a 4th&OwnMessageIdsargument;is_own = (key match) || own_ids.contains(&msg.sid.to_string());sender_name = "Me"wheneveris_own.archipelagos/messaging/src/archipelago.rs:use_signal(|| services::load_own_message_ids(&context_name)).&own_message_ids.peek()into all 4chatmessage_to_messagedatacall sites (initial fetch, SSEResync, SSEChatmessageNew, send path).msg.sidinto the set and writes through to localStorage. Existing optimistic patch (msg_data.is_own = true; msg_data.sender_name = "Me") preserved.server/src/main.rs— addedmutto 9use_signalbindings (arch_transitioning,island_transitioning,paradigm_visible,wasm_visible,ai_visible,backend_visible,cta_visible,cards_visible,active_section) so the showcase wasm build compiles.Test Results
cargo test -p hero_archipelagos_messaging --lib: 5/5 passed.services::messaging_service::own_message_ids_tests::test_insert_dedupes— own-id set dedupes on repeat insert.services::messaging_service::own_message_ids_tests::test_insert_fifo_cap— FIFO eviction atMAX_OWN_IDS_PER_CONTEXT.services::messaging_service::chatmessage_conversion_tests::test_own_id_match_returns_is_own_true— sid in set =>is_own=trueeven when sender is"system".services::messaging_service::chatmessage_conversion_tests::test_other_party_in_dm_remains_other— DM regression guard:"system"sender NOT in own-ids =>is_own=false(the option-B false-positive the issue calls out).services::messaging_service::chatmessage_conversion_tests::test_real_key_takes_precedence— once auth lands, key match wins regardless of own-ids.cargo check --workspace --exclude hero_archipelagos_messaging: clean.cargo check -p archipelagos_server --target wasm32-unknown-unknown: clean (after themutpatch).Live verified in browser:
make run->http://localhost:8886-> messaging island -> sent messages renderbubble-own, F5, re-open chat, messages still renderbubble-own. localStorage entryhero_messaging_own_msg_ids:<context>populated. No re-fetch storm on send.Test plan
test_own_id_match_returns_is_own_true)test_other_party_in_dm_remains_other)test_real_key_takes_precedence)test_insert_fifo_cap)bubble-ownNotes
use_effectreactively subscribe toown_message_idsso the message list would re-derive when the set grew. That caused a re-fetch storm on every send (visible as a screen jump). Replaced with.peek()everywhere — the set only matters on the initial chat load after F5; mid-session, the optimistic patch inhandle_sendalready does the right thing.bubble-otheruntil real auth lands — acceptable degradation given that auth is the proper fix.sender_public_key, the persisted-IDs path becomes dead code. Retire in a follow-up: deleteOwnMessageIds, drop the parameter fromchatmessage_to_messagedata, one-time-clearhero_messaging_own_msg_ids:*keys on next load.Out of scope
sender_public_keywithX-Hero-Context(option C in the issue) — tracked in hero_osis #40.bubble-other(post-reload regression of #62) #192