From 2f267afa0a88fccf10a6bddcb88c14a366692ff0 Mon Sep 17 00:00:00 2001 From: liamcottle Date: Sat, 1 Jun 2024 17:56:22 +1200 Subject: [PATCH] use most recent lxmf.delivery announce as conversation name --- web.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/web.py b/web.py index 2e979a4..8aa20e1 100644 --- a/web.py +++ b/web.py @@ -843,6 +843,7 @@ class ReticulumWebChat: # add to conversations conversations.append({ + "name": self.get_lxmf_conversation_name(other_user_hash), "destination_hash": other_user_hash, "updated_at": updated_at, }) @@ -1434,6 +1435,26 @@ class ReticulumWebChat: "announce": self.convert_db_announce_to_dict(announce), }))) + # get name to show for an lxmf conversation + # currently, this will use the app data from the most recent announce + # TODO: we should fetch this from our contacts database, when it gets implemented, and if not found, fallback to app data + def get_lxmf_conversation_name(self, destination_hash): + + # get lxmf.delivery announce from database for the provided destination hash + lxmf_announce = (database.Announce.select() + .where(database.Announce.aspect == "lxmf.delivery") + .where(database.Announce.destination_hash == 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 + if lxmf_announce is not None and lxmf_announce.app_data is not None: + try: + return base64.b64decode(lxmf_announce.app_data).decode("utf-8") + except: + pass + + return "Unknown" # class to manage config stored in database class Config: