- 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.
This commit is contained in:
Jean-Marie Traissard 2008-03-19 21:43:01 +00:00
parent 7dca69467e
commit f9ca40ff1b
2 changed files with 33 additions and 27 deletions

View File

@ -343,25 +343,26 @@ class Logger:
except sqlite.OperationalError, e: except sqlite.OperationalError, e:
print >> sys.stderr, str(e) print >> sys.stderr, str(e)
def get_unread_msgs_for_jid(self, jid): def get_unread_msgs(self):
''' get unread messages for jid ''' ''' get all unread messages '''
if not jid:
return
jid_id = self.get_jid_id(jid)
all_messages = [] all_messages = []
try: try:
self.cur.execute( 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() results = self.cur.fetchall()
except: except:
pass pass
for message in results: for message in results:
msg_id = message[0] 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(''' self.cur.execute('''
SELECT log_line_id, message, time, subject FROM logs SELECT logs.log_line_id, logs.message, logs.time, logs.subject,
WHERE jid_id = %d AND log_line_id = %d jids.jid
''' % (jid_id, msg_id) FROM logs, jids
WHERE logs.log_line_id = %d AND logs.jid_id = jids.jid_id
''' % msg_id
) )
results = self.cur.fetchall() results = self.cur.fetchall()
all_messages.append(results[0]) all_messages.append(results[0])
@ -373,7 +374,7 @@ class Logger:
kind can be status, gcstatus, gc_msg, (we only recv for those 3), 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 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 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: we analyze jid and store it as follows:
jids.jid text column will hold JID if TC-related, room_jid if GC-related, jids.jid text column will hold JID if TC-related, room_jid if GC-related,
@ -424,7 +425,9 @@ class Logger:
else: else:
jid_id = self.get_jid_id(jid) jid_id = self.get_jid_id(jid)
if kind == 'chat_msg_recv': 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 if show_col == 'UNKNOWN': # unknown show, do not log
return return

View File

@ -1265,18 +1265,27 @@ class RosterWindow:
self.draw_account(account) self.draw_account(account)
def fire_up_unread_messages_events(self, account): def fire_up_unread_messages_events(self, account):
'''reads from db the unread messages, and fire them up''' '''reads from db the unread messages, and fire them up, and
for jid in gajim.contacts.get_jid_list(account): if we find very old unread messages, delete them from unread table'''
results = gajim.logger.get_unread_msgs_for_jid(jid) results = gajim.logger.get_unread_msgs()
for result in results:
# XXX unread messages should probably have their session saved with them jid = result[4]
if results: 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) session = gajim.connections[account].make_new_session(jid)
for result in results:
tim = time.localtime(float(result[2])) tim = time.localtime(float(result[2]))
self.on_message(jid, result[1], tim, account, msg_type = 'chat', self.on_message(jid, result[1], tim, account, msg_type = 'chat',
msg_id = result[0], session = session) 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): def fill_contacts_and_groups_dicts(self, array, account):
'''fill gajim.contacts and gajim.groups''' '''fill gajim.contacts and gajim.groups'''
@ -4275,19 +4284,13 @@ class RosterWindow:
< 2: < 2:
recent = True recent = True
break break
if unread: if unread or recent:
dialog = dialogs.ConfirmationDialog(_('You have unread messages'), dialog = dialogs.ConfirmationDialog(_('You have unread messages'),
_('Messages will only be available for reading them later if you' _('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: if dialog.get_response() != gtk.RESPONSE_OK:
return 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 self.quit_on_next_offline = 0
for acct in accounts: for acct in accounts:
if gajim.connections[acct].connected: if gajim.connections[acct].connected: