From 6f081eb90ef28ec63dd151cbcf0a9117800b6e84 Mon Sep 17 00:00:00 2001 From: liamcottle Date: Mon, 12 Aug 2024 11:20:47 +1200 Subject: [PATCH] fix for conversations marked as unread when we are first to send a message --- meshchat.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/meshchat.py b/meshchat.py index 8efdc58..39f20cc 100644 --- a/meshchat.py +++ b/meshchat.py @@ -1852,15 +1852,11 @@ class ReticulumMeshChat: # returns true if the conversation has messages newer than the last read at timestamp def is_lxmf_conversation_unread(self, destination_hash): - # get lxmf.delivery announce from database for the provided destination hash + # get lxmf conversation read state from database for the provided destination hash lxmf_conversation_read_state = (database.LxmfConversationReadState.select() .where(database.LxmfConversationReadState.destination_hash == destination_hash) .get_or_none()) - # user has never read this conversation, so it's unread - if lxmf_conversation_read_state is None: - return True - # get most recent incoming message from destination hash latest_incoming_lxmf_message = (database.LxmfMessage.select() .where(database.LxmfMessage.source_hash == destination_hash) @@ -1871,6 +1867,10 @@ class ReticulumMeshChat: if latest_incoming_lxmf_message is None: return False + # user has never read this conversation, so it's unread + if lxmf_conversation_read_state is None: + return True + # conversation is unread if last read at is before the latest incoming message creation date conversation_last_read_at = datetime.strptime(lxmf_conversation_read_state.last_read_at, "%Y-%m-%d %H:%M:%S.%f%z") conversation_latest_message_at = datetime.strptime(latest_incoming_lxmf_message.created_at, "%Y-%m-%d %H:%M:%S.%f%z")