From 94b194966f81bceb8190a32bd4e04555555b2805 Mon Sep 17 00:00:00 2001
From: Dimitur Kirov <dkirov@gmail.com>
Date: Mon, 10 Apr 2006 22:36:55 +0000
Subject: [PATCH] show unread messages on roster load

---
 src/common/logger.py | 16 ++++++++++++++++
 src/roster_window.py |  6 +++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/src/common/logger.py b/src/common/logger.py
index 85932cb95a..6a14bbc2be 100644
--- a/src/common/logger.py
+++ b/src/common/logger.py
@@ -228,6 +228,21 @@ class Logger:
 		except sqlite.OperationalError, e:
 			print >> sys.stderr, str(e)
 	
+	def get_um_for_contact(self, jid):
+		''' get unread messages for jid '''
+		if not jid:
+			return
+		jid = jid.lower()
+		jid_id = self.get_jid_id(jid)
+		self.cur.execute('''
+			SELECT message_id, message, time, subject FROM logs , unread_messages 
+			WHERE jid_id = %d AND log_line_id = message_id ORDER BY time ASC 
+			''' % (jid_id)
+			)
+
+		results = self.cur.fetchall()
+		return results
+		
 	def write(self, kind, jid, message = None, show = None, tim = None,
 	subject = None):
 		'''write a row (status, gcstatus, message etc) to logs database
@@ -320,6 +335,7 @@ class Logger:
 			)
 
 		results = self.cur.fetchall()
+		#FIXME: why do we reverse, instead of selecting by ASC order?
 		results.reverse()
 		return results
 	
diff --git a/src/roster_window.py b/src/roster_window.py
index bd87a7728b..cfaed6074d 100644
--- a/src/roster_window.py
+++ b/src/roster_window.py
@@ -888,7 +888,11 @@ class RosterWindow:
 	def add_account_contacts(self, account):
 		for jid in gajim.contacts.get_jid_list(account):
 			self.add_contact_to_roster(jid, account)
-
+			results = gajim.logger.get_um_for_contact(jid)
+			for result in results:
+				tim = time.localtime(float(result[2]))
+				self.on_message(jid, result[1], tim, account, msg_type= 'chat', msg_id=result[0])
+	
 	def fill_contacts_and_groups_dicts(self, array, account):
 		'''fill gajim.contacts and gajim.groups'''
 		if account not in gajim.contacts.get_accounts():
-- 
GitLab