show only once unread messages at startup when we have twice the same contact in 2 accounts. Fixes #2921

This commit is contained in:
Yann Leboulanger 2009-08-30 22:48:45 +02:00
parent 306fe18521
commit 23dbb00d2d
7 changed files with 43 additions and 8 deletions

View File

@ -1,5 +1,5 @@
AC_INIT([Gajim - A Jabber Instant Messager],
[0.12.3.1-dev],[http://trac.gajim.org/],[gajim])
[0.12.5.1-dev],[http://trac.gajim.org/],[gajim])
AC_PREREQ([2.59])
AC_CONFIG_HEADER(config.h)

View File

@ -64,7 +64,8 @@ def create_log_db():
CREATE TABLE unread_messages(
message_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
jid_id INTEGER
jid_id INTEGER,
shown BOOLEAN default 0
);
CREATE INDEX idx_unread_messages_jid_id ON unread_messages (jid_id);

View File

@ -27,7 +27,7 @@ docdir = '../'
datadir = '../'
localedir = '../po'
version = '0.12.3.1-dev'
version = '0.12.5.1-dev'
import sys, os.path
for base in ('.', 'common'):

View File

@ -390,17 +390,29 @@ class Logger:
sql = 'DELETE FROM unread_messages WHERE message_id IN (%s)' % ids
self.simple_commit(sql)
def set_shown_unread_msgs(self, msg_id):
''' mark unread message as shown un GUI '''
sql = 'UPDATE unread_messages SET shown = 1 where message_id = %s' % \
msg_id
self.simple_commit(sql)
def reset_shown_unread_messages(self):
''' Set shown field to False in unread_messages table '''
sql = 'UPDATE unread_messages SET shown = 0'
self.simple_commit(sql)
def get_unread_msgs(self):
''' get all unread messages '''
all_messages = []
try:
self.cur.execute(
'SELECT message_id from unread_messages')
'SELECT message_id, shown from unread_messages')
results = self.cur.fetchall()
except Exception:
pass
for message in results:
msg_id = message[0]
shown = message[1]
# 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
@ -416,7 +428,7 @@ class Logger:
# Log line is no more in logs table. remove it from unread_messages
self.set_read_messages([msg_id])
continue
all_messages.append(results[0])
all_messages.append(results[0] + (shown,))
return all_messages
def write(self, kind, jid, message = None, show = None, tim = None,

View File

@ -200,6 +200,8 @@ class OptionsParser:
self.update_config_to_01215()
if old < [0, 12, 3, 1] and new >= [0, 12, 3, 1]:
self.update_config_to_01231()
if old < [0, 12, 5, 1] and new >= [0, 12, 5, 1]:
self.update_config_to_01251()
gajim.logger.init_vars()
gajim.config.set('version', new_version)
@ -705,7 +707,23 @@ class OptionsParser:
con.close()
gajim.config.set('version', '0.12.3.1')
def update_config_to_01251(self):
back = os.getcwd()
os.chdir(logger.LOG_DB_FOLDER)
con = sqlite.connect(logger.LOG_DB_FILE)
os.chdir(back)
cur = con.cursor()
try:
cur.executescript(
'''
ALTER TABLE unread_messages
ADD shown BOOLEAN default 0;
'''
)
con.commit()
except sqlite.OperationalError:
pass
con.close()
gajim.config.set('version', '0.12.5.1')
# vim: se ts=3:

View File

@ -3247,6 +3247,7 @@ class Interface:
def __init__(self):
gajim.interface = self
gajim.thread_interface = ThreadInterface
gajim.logger.reset_shown_unread_messages()
# This is the manager and factory of message windows set by the module
self.msg_win_mgr = None
self.jabber_state_images = {'16': {}, '32': {}, 'opened': {},

View File

@ -1654,7 +1654,9 @@ class RosterWindow:
results = gajim.logger.get_unread_msgs()
for result in results:
jid = result[4]
if gajim.contacts.get_first_contact_from_jid(account, jid):
shown = result[5]
if gajim.contacts.get_first_contact_from_jid(account, jid) and not \
shown:
# We have this jid in our contacts list
# XXX unread messages should probably have their session saved with
# them
@ -1663,6 +1665,7 @@ class RosterWindow:
tim = time.localtime(float(result[2]))
session.roster_message(jid, result[1], tim, msg_type='chat',
msg_id=result[0])
gajim.logger.set_shown_unread_msgs(result[0])
elif (time.time() - result[2]) > 2592000:
# ok, here we see that we have a message in unread messages table