diff --git a/meshchat.py b/meshchat.py index cef37bd..4f2f71f 100644 --- a/meshchat.py +++ b/meshchat.py @@ -1514,6 +1514,12 @@ def convert_lxmf_state_to_string(self, lxmf_message: LXMF.LXMessage): # convert database announce to a dictionary def convert_db_announce_to_dict(self, announce: database.Announce): + + # get display name for lxmf delivery announce + display_name = None + if announce.aspect == "lxmf.delivery": + display_name = self.parse_lxmf_display_name(announce.app_data) + return { "id": announce.id, "destination_hash": announce.destination_hash, @@ -1521,6 +1527,7 @@ def convert_db_announce_to_dict(self, announce: database.Announce): "identity_hash": announce.identity_hash, "identity_public_key": announce.identity_public_key, "app_data": announce.app_data, + "display_name": display_name, "created_at": announce.created_at, "updated_at": announce.updated_at, } @@ -1855,15 +1862,20 @@ def get_lxmf_conversation_name(self, destination_hash): .get_or_none()) # if app data is available in database, it should be base64 encoded text that was announced - # we will return this as the conversation name + # we will return the parsed lxmf display name as the conversation name if lxmf_announce is not None and lxmf_announce.app_data is not None: - try: - app_data_bytes = base64.b64decode(lxmf_announce.app_data) - return LXMF.display_name_from_app_data(app_data_bytes) - except: - pass + return self.parse_lxmf_display_name(app_data_base64=lxmf_announce.app_data) + + # announce did not have app data, so provide a fallback name + return "Anonymous Peer" - return "Unknown" + # reads the lxmf display name from the provided base64 app data + def parse_lxmf_display_name(self, app_data_base64: str): + try: + app_data_bytes = base64.b64decode(app_data_base64) + return LXMF.display_name_from_app_data(app_data_bytes) + except: + return "Anonymous Peer" # returns true if the conversation has messages newer than the last read at timestamp def is_lxmf_conversation_unread(self, destination_hash): diff --git a/src/frontend/components/messages/ConversationViewer.vue b/src/frontend/components/messages/ConversationViewer.vue index d3aa3f3..8ffb179 100644 --- a/src/frontend/components/messages/ConversationViewer.vue +++ b/src/frontend/components/messages/ConversationViewer.vue @@ -8,7 +8,7 @@
-
{{ selectedPeer.name }}
+
{{ selectedPeer.display_name }}
<{{ selectedPeer.destination_hash }}> {{ selectedPeerPath.hops }} {{ selectedPeerPath.hops === 1 ? 'hop' : 'hops' }} away
diff --git a/src/frontend/components/messages/MessagesPage.vue b/src/frontend/components/messages/MessagesPage.vue index ce48cbe..b72c4b1 100644 --- a/src/frontend/components/messages/MessagesPage.vue +++ b/src/frontend/components/messages/MessagesPage.vue @@ -167,20 +167,8 @@ export default { console.log(e); } }, - getPeerNameFromAppData: function(appData) { - try { - // app data should be peer name, and our server provides it base64 encoded - return Utils.decodeBase64ToUtf8String(appData); - } catch(e){ - return "Anonymous Peer"; - } - }, updatePeerFromAnnounce: function(announce) { - this.peers[announce.destination_hash] = { - ...announce, - // helper property for easily grabbing peer name from app data - name: this.getPeerNameFromAppData(announce.app_data), - }; + this.peers[announce.destination_hash] = announce; }, onPeerClick: function(peer) { this.selectedPeer = peer; diff --git a/src/frontend/components/messages/MessagesSidebar.vue b/src/frontend/components/messages/MessagesSidebar.vue index a396cd1..fbdcf51 100644 --- a/src/frontend/components/messages/MessagesSidebar.vue +++ b/src/frontend/components/messages/MessagesSidebar.vue @@ -90,7 +90,7 @@
-
{{ peer.name }}
+
{{ peer.display_name }}
{{ formatTimeAgo(peer.updated_at) }}
@@ -180,9 +180,9 @@ export default { searchedPeers() { return this.peersOrderedByLatestAnnounce.filter((peer) => { const search = this.peersSearchTerm.toLowerCase(); - const matchesAppData = peer.name.toLowerCase().includes(search); + const matchesDisplayName = peer.display_name.toLowerCase().includes(search); const matchesDestinationHash = peer.destination_hash.toLowerCase().includes(search); - return matchesAppData || matchesDestinationHash; + return matchesDisplayName || matchesDestinationHash; }); }, },