From 23dbb00d2df4283ef220b517fcb2fb045327f295 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Sun, 30 Aug 2009 22:48:45 +0200 Subject: [PATCH] show only once unread messages at startup when we have twice the same contact in 2 accounts. Fixes #2921 --- configure.ac | 2 +- src/common/check_paths.py | 3 ++- src/common/defs.py | 2 +- src/common/logger.py | 16 ++++++++++++++-- src/common/optparser.py | 22 ++++++++++++++++++++-- src/gajim.py | 1 + src/roster_window.py | 5 ++++- 7 files changed, 43 insertions(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index 9261c14f7..7545378a6 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ AC_INIT([Gajim - A Jabber Instant Messager], - [0.12.3.1-dev],[http://trac.gajim.org/],[gajim]) + [0.12.5.1-dev],[http://trac.gajim.org/],[gajim]) AC_PREREQ([2.59]) AC_CONFIG_HEADER(config.h) diff --git a/src/common/check_paths.py b/src/common/check_paths.py index e883d1635..0a9dcb83e 100644 --- a/src/common/check_paths.py +++ b/src/common/check_paths.py @@ -64,7 +64,8 @@ def create_log_db(): CREATE TABLE unread_messages( message_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, - jid_id INTEGER + jid_id INTEGER, + shown BOOLEAN default 0 ); CREATE INDEX idx_unread_messages_jid_id ON unread_messages (jid_id); diff --git a/src/common/defs.py b/src/common/defs.py index c321440d0..e213fdab1 100644 --- a/src/common/defs.py +++ b/src/common/defs.py @@ -27,7 +27,7 @@ docdir = '../' datadir = '../' localedir = '../po' -version = '0.12.3.1-dev' +version = '0.12.5.1-dev' import sys, os.path for base in ('.', 'common'): diff --git a/src/common/logger.py b/src/common/logger.py index 51ad1d080..5fc94b9b9 100644 --- a/src/common/logger.py +++ b/src/common/logger.py @@ -390,17 +390,29 @@ class Logger: sql = 'DELETE FROM unread_messages WHERE message_id IN (%s)' % ids self.simple_commit(sql) + def set_shown_unread_msgs(self, msg_id): + ''' mark unread message as shown un GUI ''' + sql = 'UPDATE unread_messages SET shown = 1 where message_id = %s' % \ + msg_id + self.simple_commit(sql) + + def reset_shown_unread_messages(self): + ''' Set shown field to False in unread_messages table ''' + sql = 'UPDATE unread_messages SET shown = 0' + self.simple_commit(sql) + def get_unread_msgs(self): ''' get all unread messages ''' all_messages = [] try: self.cur.execute( - 'SELECT message_id from unread_messages') + 'SELECT message_id, shown from unread_messages') results = self.cur.fetchall() except Exception: pass for message in results: msg_id = message[0] + shown = message[1] # here we get infos for that message, and related jid from jids table # do NOT change order of SELECTed things, unless you change function(s) # that called this function @@ -416,7 +428,7 @@ class Logger: # Log line is no more in logs table. remove it from unread_messages self.set_read_messages([msg_id]) continue - all_messages.append(results[0]) + all_messages.append(results[0] + (shown,)) return all_messages def write(self, kind, jid, message = None, show = None, tim = None, diff --git a/src/common/optparser.py b/src/common/optparser.py index 9fbcf38f1..18cfe2802 100644 --- a/src/common/optparser.py +++ b/src/common/optparser.py @@ -200,6 +200,8 @@ class OptionsParser: self.update_config_to_01215() if old < [0, 12, 3, 1] and new >= [0, 12, 3, 1]: self.update_config_to_01231() + if old < [0, 12, 5, 1] and new >= [0, 12, 5, 1]: + self.update_config_to_01251() gajim.logger.init_vars() gajim.config.set('version', new_version) @@ -705,7 +707,23 @@ class OptionsParser: con.close() gajim.config.set('version', '0.12.3.1') - - + def update_config_to_01251(self): + back = os.getcwd() + os.chdir(logger.LOG_DB_FOLDER) + con = sqlite.connect(logger.LOG_DB_FILE) + os.chdir(back) + cur = con.cursor() + try: + cur.executescript( + ''' + ALTER TABLE unread_messages + ADD shown BOOLEAN default 0; + ''' + ) + con.commit() + except sqlite.OperationalError: + pass + con.close() + gajim.config.set('version', '0.12.5.1') # vim: se ts=3: diff --git a/src/gajim.py b/src/gajim.py index 41a29ce65..83382f7de 100644 --- a/src/gajim.py +++ b/src/gajim.py @@ -3247,6 +3247,7 @@ class Interface: def __init__(self): gajim.interface = self gajim.thread_interface = ThreadInterface + gajim.logger.reset_shown_unread_messages() # This is the manager and factory of message windows set by the module self.msg_win_mgr = None self.jabber_state_images = {'16': {}, '32': {}, 'opened': {}, diff --git a/src/roster_window.py b/src/roster_window.py index 2089dd7e6..b9358f07b 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -1654,7 +1654,9 @@ class RosterWindow: results = gajim.logger.get_unread_msgs() for result in results: jid = result[4] - if gajim.contacts.get_first_contact_from_jid(account, jid): + shown = result[5] + if gajim.contacts.get_first_contact_from_jid(account, jid) and not \ + shown: # We have this jid in our contacts list # XXX unread messages should probably have their session saved with # them @@ -1663,6 +1665,7 @@ class RosterWindow: tim = time.localtime(float(result[2])) session.roster_message(jid, result[1], tim, msg_type='chat', msg_id=result[0]) + gajim.logger.set_shown_unread_msgs(result[0]) elif (time.time() - result[2]) > 2592000: # ok, here we see that we have a message in unread messages table