From 5cd13f2d98dc03a32981d07d3b10590bb21ed9fd Mon Sep 17 00:00:00 2001 From: pe1hvh Date: Fri, 13 Mar 2026 04:01:33 +0100 Subject: [PATCH] HotFixRoomServer --- CHANGELOG.md | 1 + meshcore_gui/gui/panels/room_server_panel.py | 43 +++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ae3259..5bc3bfd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - 🛠 **Incoming room messages from other participants could be misclassified as normal DMs** — `CONTACT_MSG_RECV` room detection now keys on `txt_type == 2` instead of requiring `signature`. - 🛠 **Incoming room traffic could be attached to the wrong key** — room message handling now prefers `room_pubkey` / receiver-style payload keys before falling back to `pubkey_prefix`. - 🛠 **Room login UI could stay out of sync with the actual server-confirmed state** — `LOGIN_SUCCESS` now updates `room_login_states` and refreshes room history using the resolved room key. +- 🛠 **Room Server panel showed hex codes instead of sender names** — when a contact was not yet known at the time a room message was archived, `msg.sender` was stored as a raw hex prefix. The panel now performs a live lookup against the current contacts snapshot on every render tick, so names are shown as soon as the contact is known. ### Changed - 🔄 `meshcore_gui/ble/events.py` — Broadened room payload parsing and added payload-key debug logging for incoming room traffic. diff --git a/meshcore_gui/gui/panels/room_server_panel.py b/meshcore_gui/gui/panels/room_server_panel.py index afd7e35..ab326a7 100644 --- a/meshcore_gui/gui/panels/room_server_panel.py +++ b/meshcore_gui/gui/panels/room_server_panel.py @@ -116,10 +116,12 @@ class RoomServerPanel: room_messages: Dict = data.get('room_messages', {}) # Live messages from current session's rolling buffer live_messages: List[Message] = data.get('messages', []) + # Contact dict for live sender-name resolution + contacts: Dict = data.get('contacts', {}) for pubkey, card_state in self._room_cards.items(): self._update_room_messages( - pubkey, card_state, room_messages, live_messages, + pubkey, card_state, room_messages, live_messages, contacts, ) # ------------------------------------------------------------------ @@ -389,6 +391,41 @@ class RoomServerPanel: if card_state and card_state.get('card'): self._container.remove(card_state['card']) + # ------------------------------------------------------------------ + # Internal — sender name resolution + # ------------------------------------------------------------------ + + @staticmethod + def _resolve_sender_name(sender: str, contacts: Dict) -> str: + """Resolve a sender field to a display name when possible. + + When ``msg.sender`` was stored as a raw hex prefix (because the + contact was not yet known at archive time), this method attempts + a live lookup against the current contacts snapshot so the UI + always shows a human-readable name instead of a hex code. + + Args: + sender: Value from ``Message.sender`` — may be a name or a hex string. + contacts: Current contacts snapshot from ``SharedData.get_snapshot()``. + + Returns: + Resolved display name, or the original sender value if no + match is found, or ``'?'`` when sender is empty. + """ + if not sender: + return '?' + probe = sender.strip().lower() + # Only resolve when the field looks like a hex identifier (6–64 hex chars) + if not (6 <= len(probe) <= 64 and all(ch in '0123456789abcdef' for ch in probe)): + return sender + for key, contact in contacts.items(): + candidate = key.strip().lower() + if candidate.startswith(probe) or probe.startswith(candidate[:len(probe)]): + name = str(contact.get('adv_name', '') or '').strip() + if name: + return name + return sender + # ------------------------------------------------------------------ # Internal — message display # ------------------------------------------------------------------ @@ -399,6 +436,7 @@ class RoomServerPanel: card_state: Dict, room_messages: Dict, live_messages: List[Message], + contacts: Dict, ) -> None: """Update the message display for a single room card. @@ -412,6 +450,7 @@ class RoomServerPanel: card_state: UI state dict for this room card. room_messages: ``{12-char-prefix: [Message, …]}`` from archive cache. live_messages: Current session's rolling message buffer. + contacts: Current contacts snapshot for live name resolution. """ msg_container = card_state.get('msg_container') if not msg_container: @@ -455,7 +494,7 @@ class RoomServerPanel: with msg_container: for msg in display: direction = '→' if msg.direction == 'out' else '←' - sender = msg.sender or '?' + sender = self._resolve_sender_name(msg.sender or '', contacts) line = f"{msg.time} {direction} {sender}: {msg.text}" ui.label(line).classes(