From 331c00fe708648453a94f4d6d9d6702576a69f6f Mon Sep 17 00:00:00 2001 From: Sudo-Ivan Date: Fri, 2 Jan 2026 01:20:05 -0600 Subject: [PATCH] feat(message_handler): add filter_unread option to get_conversations method for improved message retrieval --- meshchatx/src/backend/message_handler.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/meshchatx/src/backend/message_handler.py b/meshchatx/src/backend/message_handler.py index fb6e0e9..38199b6 100644 --- a/meshchatx/src/backend/message_handler.py +++ b/meshchatx/src/backend/message_handler.py @@ -56,7 +56,7 @@ class MessageHandler: params = [local_hash, local_hash, like_term, like_term, like_term, like_term] return self.db.provider.fetchall(query, params) - def get_conversations(self, local_hash): + def get_conversations(self, local_hash, filter_unread=False): # Implementation moved from get_conversations DAO but with local_hash filter query = """ SELECT m1.* FROM lxmf_messages m1 @@ -69,8 +69,7 @@ class MessageHandler: GROUP BY peer_hash ) m2 ON (CASE WHEN m1.source_hash = ? THEN m1.destination_hash ELSE m1.source_hash END = m2.peer_hash AND m1.timestamp = m2.max_ts) - WHERE m1.source_hash = ? OR m1.destination_hash = ? - ORDER BY m1.timestamp DESC + WHERE (m1.source_hash = ? OR m1.destination_hash = ?) """ params = [ local_hash, @@ -80,4 +79,11 @@ class MessageHandler: local_hash, local_hash, ] + + if filter_unread: + query += " AND EXISTS (SELECT 1 FROM lxmf_messages m3 WHERE (m3.source_hash = m2.peer_hash AND m3.destination_hash = ?) AND m3.state = 'received' AND m3.is_incoming = 1)" + params.append(local_hash) + + query += " ORDER BY m1.timestamp DESC" + return self.db.provider.fetchall(query, params)