Change the way to remember last message time in groupchat again. Save the time on

disconnection or exit. Previous version seemed perfect, but if server don't have the
same exact time than us (always), lots of messages can be logged twice. Here we will
lost log for messages that were sent beetween we lost connection and we see it. But that
seems better for me. For previous version, see [9516].
This commit is contained in:
Jean-Marie Traissard 2008-06-05 11:18:33 +00:00
parent a0f57f5e99
commit e487aa7802
3 changed files with 16 additions and 7 deletions

View File

@ -1532,6 +1532,15 @@ class Connection(ConnectionHandlers):
# disconnect from jabber server
self.connection.send(p)
def gc_got_disconnected(self, room_jid):
''' A groupchat got disconnected. This can be or purpose or not.
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_time[room_jid] = log_time
gajim.logger.set_room_last_message_time(room_jid, log_time)
def gc_set_role(self, room_jid, nick, role, reason = ''):
'''role is for all the life of the room so it's based on nick'''
if not self.connection:

View File

@ -1879,7 +1879,6 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
no_log_for = ''
no_log_for = no_log_for.split()
tim_int = int(float(mktime(tim)))
if self.name not in no_log_for and jid not in no_log_for and not \
@ -1889,8 +1888,6 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
# so don't store it in logs
try:
gajim.logger.write('gc_msg', frm, msgtxt, tim=tim)
# save the time we log to avoid duplicate logs
self.last_history_time[jid] = tim_int
except exceptions.PysqliteOperationalError, e:
self.dispatch('ERROR', (_('Disk Write Error'), str(e)))

View File

@ -916,6 +916,8 @@ class GroupchatControl(ChatControlBase):
gajim.contacts.remove_gc_contact(self.account, gc_contact)
gajim.gc_connected[self.account][self.room_jid] = False
ChatControlBase.got_disconnected(self)
# Tell connection to note the date we disconnect to avoid duplicate logs
gajim.connections[self.account].gc_got_disconnected(self.room_jid)
# We don't redraw the whole banner here, because only icon change
self._update_banner_state_image()
if self.parent_win:
@ -1638,12 +1640,13 @@ class GroupchatControl(ChatControlBase):
def shutdown(self, status='offline'):
# destroy banner tooltip - bug #pygtk for that!
self.subject_tooltip.destroy()
if gajim.gc_connected[self.account][self.room_jid]:
# Tell connection to note the date we disconnect to avoid duplicate
# logs. We do it only when connected because if connection was lost
# there may be new messages since disconnection.
gajim.connections[self.account].gc_got_disconnected(self.room_jid)
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