Skip to content

Commit

Permalink
fix display names for lxmf announces
Browse files Browse the repository at this point in the history
  • Loading branch information
liamcottle committed Sep 11, 2024
1 parent 7b4db96 commit 946fb17
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
26 changes: 19 additions & 7 deletions meshchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1514,13 +1514,20 @@ 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,
"aspect": announce.aspect,
"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,
}
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/components/messages/ConversationViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<!-- peer info -->
<div>
<div class="font-semibold">{{ selectedPeer.name }}</div>
<div class="font-semibold">{{ selectedPeer.display_name }}</div>
<div class="text-sm"><{{ selectedPeer.destination_hash }}> <span v-if="selectedPeerPath" @click="onDestinationPathClick(selectedPeerPath)" class="cursor-pointer">{{ selectedPeerPath.hops }} {{ selectedPeerPath.hops === 1 ? 'hop' : 'hops' }} away</span></div>
</div>

Expand Down
14 changes: 1 addition & 13 deletions src/frontend/components/messages/MessagesPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/frontend/components/messages/MessagesSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
</div>
</div>
<div>
<div class="text-gray-900">{{ peer.name }}</div>
<div class="text-gray-900">{{ peer.display_name }}</div>
<div class="text-gray-500 text-sm">{{ formatTimeAgo(peer.updated_at) }}</div>
</div>
</div>
Expand Down Expand Up @@ -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;
});
},
},
Expand Down

0 comments on commit 946fb17

Please sign in to comment.