Author: jim++ Date: 2008-04-21 17:48:06 +0200 (Mon, 21 Apr 2008) New Revision: 9516
Modified: trunk/src/common/connection.py trunk/src/common/connection_handlers.py trunk/src/groupchat_control.py Log: Change the way last_history_time for room is saved. Save time in mem at each message logged. When closing control, save the value in rooms_last_message_time table. Previous version could introduce duplicate logs or messages not logged.
Modified: trunk/src/common/connection.py =================================================================== --- trunk/src/common/connection.py 2008-04-21 14:44:19 UTC (rev 9515) +++ trunk/src/common/connection.py 2008-04-21 15:48:06 UTC (rev 9516) @@ -128,7 +128,7 @@ self.on_purpose = False self.last_io = gajim.idlequeue.current_time() self.last_sent = [] - self.last_history_line = {} + self.last_history_time = {} self.password = passwords.get_password(name) self.server_resource = gajim.config.get_per('accounts', name, 'resource') # All valid resource substitution strings should be added to this hash. @@ -1441,7 +1441,7 @@ self.connection.send(p)
# last date/time in history to avoid duplicate - if not self.last_history_line.has_key(room_jid): + if not self.last_history_time.has_key(room_jid): # Not in memory, get it from DB no_log_for = gajim.config.get_per('accounts', self.name, 'no_log_for')\ .split() @@ -1454,11 +1454,11 @@ # Not in special table, get it from messages DB last_log = gajim.logger.get_last_date_that_has_logs(room_jid, is_room = True) - # Create self.last_history_line[room_jid] even if not logging, + # Create self.last_history_time[room_jid] even if not logging, # could be used in connection_handlers if last_log is None: last_log = 0 - self.last_history_line[room_jid]= last_log + self.last_history_time[room_jid]= last_log
def send_gc_message(self, jid, msg, xhtml = None): if not self.connection: @@ -1503,12 +1503,6 @@ ptype = None if show == 'offline': ptype = 'unavailable' - # Save the time we quit to avoid duplicate logs AND be faster than - # get that date from DB. Save it in mem AND in a small table (with - # fast access) - log_time = time_time() - self.last_history_line[jid] = log_time - gajim.logger.set_room_last_message_time(jid, log_time) xmpp_show = helpers.get_xmpp_show(show) p = common.xmpp.Presence(to = '%s/%s' % (jid, nick), typ = ptype, show = xmpp_show, status = status)
Modified: trunk/src/common/connection_handlers.py =================================================================== --- trunk/src/common/connection_handlers.py 2008-04-21 14:44:19 UTC (rev 9515) +++ trunk/src/common/connection_handlers.py 2008-04-21 15:48:06 UTC (rev 9516) @@ -1658,18 +1658,20 @@ self.dispatch('GC_CONFIG_CHANGE', (jid, statusCode)) return # Ignore message from room in which we are not - if not self.last_history_line.has_key(jid): + if not self.last_history_time.has_key(jid): return self.dispatch('GC_MSG', (frm, msgtxt, tim, has_timestamp, msghtml, statusCode)) if self.name not in no_log_for and jid not in no_log_for and not \ - int(float(mktime(tim))) <= self.last_history_line[jid] and msgtxt \ + int(float(mktime(tim))) <= self.last_history_time[jid] and msgtxt \ and frm.find('/') >= 0: # if frm.find('/') < 0, it means message comes from room itself # usually it hold description and can be send at each connection # so don't store it in logs try: gajim.logger.write('gc_msg', frm, msgtxt, tim = tim) + # save the time we quit to avoid duplicate logs + self.last_history_time[jid] = time_time() except exceptions.PysqliteOperationalError, e: self.dispatch('ERROR', (_('Disk Write Error'), str(e))) return
Modified: trunk/src/groupchat_control.py =================================================================== --- trunk/src/groupchat_control.py 2008-04-21 14:44:19 UTC (rev 9515) +++ trunk/src/groupchat_control.py 2008-04-21 15:48:06 UTC (rev 9516) @@ -1595,6 +1595,10 @@ self.subject_tooltip.destroy() gajim.connections[self.account].send_gc_status(self.nick, self.room_jid, show='offline', status=status) + # save in fast table in DB at what time we had last message + last_history_time = \ + gajim.connections[self.account].last_history_time[self.room_jid] + gajim.logger.set_room_last_message_time(self.room_jid, last_history_time) nick_list = gajim.contacts.get_nick_list(self.account, self.room_jid) for nick in nick_list: # Update pm chat window