From f9ca40ff1b63133244047beb2f56804c49ca4da8 Mon Sep 17 00:00:00 2001 From: Jean-Marie Traissard Date: Wed, 19 Mar 2008 21:43:01 +0000 Subject: [PATCH] - Change the way roster.fire_up_unread_messages_events()/logger.get_unread_msgs() work, so it's faster - Stop adding pm chat messages received to unread messages. This is in addition to [8311], but works also when chat win is already opened now. - Automatically remove unread_message lines for messages older than a month, so we will clear this table for everybody, and keep it quite clear. Specially because messages can still be blocked here if it's from someone not in the roster and we don't open it during the session. This can be long at first connection with this version, because we delete a lot of lines (nearly one per PMs you received since a long time). Could also be a very little longer during one month. --- src/common/logger.py | 27 +++++++++++++++------------ src/roster_window.py | 33 ++++++++++++++++++--------------- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/src/common/logger.py b/src/common/logger.py index c737eb190..b980c0046 100644 --- a/src/common/logger.py +++ b/src/common/logger.py @@ -343,25 +343,26 @@ class Logger: except sqlite.OperationalError, e: print >> sys.stderr, str(e) - def get_unread_msgs_for_jid(self, jid): - ''' get unread messages for jid ''' - if not jid: - return - jid_id = self.get_jid_id(jid) + def get_unread_msgs(self): + ''' get all unread messages ''' all_messages = [] try: self.cur.execute( - 'SELECT message_id from unread_messages WHERE jid_id = %d' % jid_id) + 'SELECT message_id from unread_messages') results = self.cur.fetchall() except: pass - for message in results: msg_id = message[0] + # 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 self.cur.execute(''' - SELECT log_line_id, message, time, subject FROM logs - WHERE jid_id = %d AND log_line_id = %d - ''' % (jid_id, msg_id) + SELECT logs.log_line_id, logs.message, logs.time, logs.subject, + jids.jid + FROM logs, jids + WHERE logs.log_line_id = %d AND logs.jid_id = jids.jid_id + ''' % msg_id ) results = self.cur.fetchall() all_messages.append(results[0]) @@ -373,7 +374,7 @@ class Logger: kind can be status, gcstatus, gc_msg, (we only recv for those 3), single_msg_recv, chat_msg_recv, chat_msg_sent, single_msg_sent we cannot know if it is pm or normal chat message, we try to guess - see jid_is_from_pm() which is called by get_jid_id() + see jid_is_from_pm() we analyze jid and store it as follows: jids.jid text column will hold JID if TC-related, room_jid if GC-related, @@ -424,7 +425,9 @@ class Logger: else: jid_id = self.get_jid_id(jid) if kind == 'chat_msg_recv': - write_unread = True + if not self.jid_is_from_pm(jid): + # Save in unread table only if it's not a pm + write_unread = True if show_col == 'UNKNOWN': # unknown show, do not log return diff --git a/src/roster_window.py b/src/roster_window.py index 7582f6a07..587542385 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -1265,18 +1265,27 @@ class RosterWindow: self.draw_account(account) def fire_up_unread_messages_events(self, account): - '''reads from db the unread messages, and fire them up''' - for jid in gajim.contacts.get_jid_list(account): - results = gajim.logger.get_unread_msgs_for_jid(jid) - - # XXX unread messages should probably have their session saved with them - if results: + '''reads from db the unread messages, and fire them up, and + if we find very old unread messages, delete them from unread table''' + results = gajim.logger.get_unread_msgs() + for result in results: + jid = result[4] + if gajim.contacts.get_first_contact_from_jid(account, jid): + # We have this jid in our contacts list + # XXX unread messages should probably have their session saved with + # them session = gajim.connections[account].make_new_session(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], session = session) + + elif (time.time() - result[2]) > 2592000: + # ok, here we see that we have a message in unread messages table + # that is older than a month. It is probably from someone not in our + # roster for accounts we usually launch, so we will delete this id + # from unread message tables. + gajim.logger.set_read_messages([result[0]]) def fill_contacts_and_groups_dicts(self, array, account): '''fill gajim.contacts and gajim.groups''' @@ -4275,19 +4284,13 @@ class RosterWindow: < 2: recent = True break - if unread: + if unread or recent: dialog = dialogs.ConfirmationDialog(_('You have unread messages'), _('Messages will only be available for reading them later if you' - ' have history enabled.')) + ' have history enabled and contact is in your roster.')) if dialog.get_response() != gtk.RESPONSE_OK: return - if recent: - dialog = dialogs.ConfirmationDialog(_('You have unread messages'), - _('Messages will only be available for reading them later if you' - ' have history enabled.')) - if dialog.get_response() != gtk.RESPONSE_OK: - return self.quit_on_next_offline = 0 for acct in accounts: if gajim.connections[acct].connected: