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")