diff options
| author | elioat <elioat@tilde.institute> | 2025-11-15 21:06:40 -0500 |
|---|---|---|
| committer | elioat <elioat@tilde.institute> | 2025-11-15 21:06:40 -0500 |
| commit | d026f91f5a0918cb02b17cbf79d5259ffc80324e (patch) | |
| tree | eefce89d2408c5e4283d76d54a4a9b5d9d84ec98 | |
| parent | ef9042fb2dedff012090ff9c4cc856970202a2d7 (diff) | |
| download | tour-d026f91f5a0918cb02b17cbf79d5259ffc80324e.tar.gz | |
Remove display formatting and go back to basics
Simple rule:
- Local messages (is_local=True): DON'T display
(User already sees terminal echo of what they typed)
- Remote messages (is_local=False): DO display
(Only way user sees messages from others)
Track all messages in deduplication cache to prevent mesh bouncebacks.
This is the correct, simple solution. No fancy formatting, no prompts,
just clean message exchange.
| -rw-r--r-- | gleam/gossip/src/registry.gleam | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/gleam/gossip/src/registry.gleam b/gleam/gossip/src/registry.gleam index 5d84332..1147b6d 100644 --- a/gleam/gossip/src/registry.gleam +++ b/gleam/gossip/src/registry.gleam @@ -329,37 +329,28 @@ fn loop(subject: process.Subject(messages.Message), state: RegistryState) -> Nil messages.Broadcast(from, text, origin_id, last_sender_id, timestamp, is_local) -> { // Broadcast message: display and forward // - // TEA (The Elm Architecture) Model Update: - // The registry receives messages from two sources: - // 1. Local input: user types something -> input_loop sends Broadcast(is_local=True) - // 2. Network: peer sends message -> input_loop not involved -> Broadcast(is_local=False) + // Message Display Strategy: + // - is_local=True: DON'T display (user already sees terminal echo) + // - is_local=False: Display (message from another peer, not yet visible) // - // Display Strategy: - // - is_local=True: Display with > prefix (marks as user's own message) - // - is_local=False: Display without prefix (marks as received from peer) - // - // Message deduplication: Track seen messages to prevent duplicates in mesh topologies. + // Message deduplication: Track ALL messages (local and network) to prevent + // duplicates when messages bounce back through mesh networks. // Use (origin_id, from, text, timestamp) as unique identifier. let message_id = #(origin_id, from, text, timestamp) let already_seen = has_seen_message(message_id) - // Display if we haven't seen it before (applies to both local and network messages) - case !already_seen { + // Only display messages from OTHER peers (not local input) + case !already_seen && !is_local { True -> { - // Add > prefix for local messages, no prefix for received messages - let display_text = case is_local { - True -> "> " <> text - False -> text - } - let _ = process.send(state.local_client, messages.ChatMessage(from, display_text, timestamp)) + let _ = process.send(state.local_client, messages.ChatMessage(from, text, timestamp)) Nil } False -> Nil } // Mark as seen regardless of origin - // Local messages need to be tracked so bouncebacks don't display again + // Local messages are tracked so bouncebacks don't display again let _ = mark_message_seen(message_id) case state.peers { |