fix display names for lxmf announces

This commit is contained in:
liamcottle 2024-09-11 21:23:26 +12:00
commit 946fb17d8c
4 changed files with 24 additions and 24 deletions

View file

@ -1514,6 +1514,12 @@ class ReticulumMeshChat:
# 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 @@ class ReticulumMeshChat:
"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 @@ class ReticulumMeshChat:
.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)
return "Unknown"
# announce did not have app data, so provide a fallback name
return "Anonymous Peer"
# 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):

View file

@ -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>

View file

@ -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;

View file

@ -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>
@ -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;
});
},
},