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
3 changed files with 12 additions and 12 deletions
|
@ -128,7 +128,7 @@ class Connection(ConnectionHandlers):
|
||||||
self.on_purpose = False
|
self.on_purpose = False
|
||||||
self.last_io = gajim.idlequeue.current_time()
|
self.last_io = gajim.idlequeue.current_time()
|
||||||
self.last_sent = []
|
self.last_sent = []
|
||||||
self.last_history_line = {}
|
self.last_history_time = {}
|
||||||
self.password = passwords.get_password(name)
|
self.password = passwords.get_password(name)
|
||||||
self.server_resource = gajim.config.get_per('accounts', name, 'resource')
|
self.server_resource = gajim.config.get_per('accounts', name, 'resource')
|
||||||
# All valid resource substitution strings should be added to this hash.
|
# All valid resource substitution strings should be added to this hash.
|
||||||
|
@ -1441,7 +1441,7 @@ class Connection(ConnectionHandlers):
|
||||||
self.connection.send(p)
|
self.connection.send(p)
|
||||||
|
|
||||||
# last date/time in history to avoid duplicate
|
# 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
|
# Not in memory, get it from DB
|
||||||
no_log_for = gajim.config.get_per('accounts', self.name, 'no_log_for')\
|
no_log_for = gajim.config.get_per('accounts', self.name, 'no_log_for')\
|
||||||
.split()
|
.split()
|
||||||
|
@ -1454,11 +1454,11 @@ class Connection(ConnectionHandlers):
|
||||||
# Not in special table, get it from messages DB
|
# Not in special table, get it from messages DB
|
||||||
last_log = gajim.logger.get_last_date_that_has_logs(room_jid,
|
last_log = gajim.logger.get_last_date_that_has_logs(room_jid,
|
||||||
is_room = True)
|
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
|
# could be used in connection_handlers
|
||||||
if last_log is None:
|
if last_log is None:
|
||||||
last_log = 0
|
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):
|
def send_gc_message(self, jid, msg, xhtml = None):
|
||||||
if not self.connection:
|
if not self.connection:
|
||||||
|
@ -1503,12 +1503,6 @@ class Connection(ConnectionHandlers):
|
||||||
ptype = None
|
ptype = None
|
||||||
if show == 'offline':
|
if show == 'offline':
|
||||||
ptype = 'unavailable'
|
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)
|
xmpp_show = helpers.get_xmpp_show(show)
|
||||||
p = common.xmpp.Presence(to = '%s/%s' % (jid, nick), typ = ptype,
|
p = common.xmpp.Presence(to = '%s/%s' % (jid, nick), typ = ptype,
|
||||||
show = xmpp_show, status = status)
|
show = xmpp_show, status = status)
|
||||||
|
|
|
@ -1658,18 +1658,20 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
|
||||||
self.dispatch('GC_CONFIG_CHANGE', (jid, statusCode))
|
self.dispatch('GC_CONFIG_CHANGE', (jid, statusCode))
|
||||||
return
|
return
|
||||||
# Ignore message from room in which we are not
|
# 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
|
return
|
||||||
self.dispatch('GC_MSG', (frm, msgtxt, tim, has_timestamp, msghtml,
|
self.dispatch('GC_MSG', (frm, msgtxt, tim, has_timestamp, msghtml,
|
||||||
statusCode))
|
statusCode))
|
||||||
if self.name not in no_log_for and jid not in no_log_for and not \
|
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:
|
and frm.find('/') >= 0:
|
||||||
# if frm.find('/') < 0, it means message comes from room itself
|
# if frm.find('/') < 0, it means message comes from room itself
|
||||||
# usually it hold description and can be send at each connection
|
# usually it hold description and can be send at each connection
|
||||||
# so don't store it in logs
|
# so don't store it in logs
|
||||||
try:
|
try:
|
||||||
gajim.logger.write('gc_msg', frm, msgtxt, tim = tim)
|
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:
|
except exceptions.PysqliteOperationalError, e:
|
||||||
self.dispatch('ERROR', (_('Disk Write Error'), str(e)))
|
self.dispatch('ERROR', (_('Disk Write Error'), str(e)))
|
||||||
return
|
return
|
||||||
|
|
|
@ -1595,6 +1595,10 @@ class GroupchatControl(ChatControlBase):
|
||||||
self.subject_tooltip.destroy()
|
self.subject_tooltip.destroy()
|
||||||
gajim.connections[self.account].send_gc_status(self.nick, self.room_jid,
|
gajim.connections[self.account].send_gc_status(self.nick, self.room_jid,
|
||||||
show='offline', status=status)
|
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)
|
nick_list = gajim.contacts.get_nick_list(self.account, self.room_jid)
|
||||||
for nick in nick_list:
|
for nick in nick_list:
|
||||||
# Update pm chat window
|
# Update pm chat window
|
||||||
|
|
Loading…
Add table
Reference in a new issue