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.
This commit is contained in:
parent
f2f0c7aba0
commit
94580b3019
|
@ -128,7 +128,7 @@ class Connection(ConnectionHandlers):
|
|||
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 @@ class Connection(ConnectionHandlers):
|
|||
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 @@ class Connection(ConnectionHandlers):
|
|||
# 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 @@ class Connection(ConnectionHandlers):
|
|||
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)
|
||||
|
|
|
@ -1658,18 +1658,20 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
|
|||
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
|
||||
|
|
|
@ -1595,6 +1595,10 @@ class GroupchatControl(ChatControlBase):
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue