keep reference to unread messages untill they
are printed in tv
This commit is contained in:
parent
6b1e1d1c8b
commit
97dc7215df
|
@ -1403,6 +1403,8 @@ class ChatControl(ChatControlBase):
|
||||||
if control and control.type_id == message_control.TYPE_GC:
|
if control and control.type_id == message_control.TYPE_GC:
|
||||||
is_pm = True
|
is_pm = True
|
||||||
events_to_keep = []
|
events_to_keep = []
|
||||||
|
# list of message ids which should be marked as read
|
||||||
|
message_ids = []
|
||||||
for event in l:
|
for event in l:
|
||||||
typ = event[0]
|
typ = event[0]
|
||||||
if typ != 'chat':
|
if typ != 'chat':
|
||||||
|
@ -1416,13 +1418,15 @@ class ChatControl(ChatControlBase):
|
||||||
kind = 'print_queue'
|
kind = 'print_queue'
|
||||||
self.print_conversation(data[0], kind, tim = data[3],
|
self.print_conversation(data[0], kind, tim = data[3],
|
||||||
encrypted = data[4], subject = data[1])
|
encrypted = data[4], subject = data[1])
|
||||||
|
if len(data) > 6 and isinstance(data[6], int):
|
||||||
|
message_ids.append(data[6])
|
||||||
# remove from gc nb_unread if it's pm or from roster
|
# remove from gc nb_unread if it's pm or from roster
|
||||||
if is_pm:
|
if is_pm:
|
||||||
control.nb_unread -= 1
|
control.nb_unread -= 1
|
||||||
else:
|
else:
|
||||||
gajim.interface.roster.nb_unread -= 1
|
gajim.interface.roster.nb_unread -= 1
|
||||||
|
if message_ids:
|
||||||
|
gajim.logger.set_read_messages(message_ids)
|
||||||
if is_pm:
|
if is_pm:
|
||||||
control.parent_win.show_title()
|
control.parent_win.show_title()
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -35,6 +35,20 @@ Q_ = i18n.Q_
|
||||||
|
|
||||||
from pysqlite2 import dbapi2 as sqlite # DO NOT MOVE ABOVE OF import gajim
|
from pysqlite2 import dbapi2 as sqlite # DO NOT MOVE ABOVE OF import gajim
|
||||||
|
|
||||||
|
def assert_um_exists():
|
||||||
|
''' create table unread_messages if there is no such table '''
|
||||||
|
con = sqlite.connect(logger.LOG_DB_PATH)
|
||||||
|
os.chmod(logger.LOG_DB_PATH, 0600) # rw only for us
|
||||||
|
cur = con.cursor()
|
||||||
|
cur.executescript(
|
||||||
|
'''
|
||||||
|
CREATE TABLE IF NOT EXISTS unread_messages (
|
||||||
|
message_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE
|
||||||
|
);
|
||||||
|
'''
|
||||||
|
)
|
||||||
|
con.commit()
|
||||||
|
|
||||||
def create_log_db():
|
def create_log_db():
|
||||||
print _('creating logs database')
|
print _('creating logs database')
|
||||||
con = sqlite.connect(logger.LOG_DB_PATH)
|
con = sqlite.connect(logger.LOG_DB_PATH)
|
||||||
|
@ -56,6 +70,10 @@ def create_log_db():
|
||||||
type INTEGER
|
type INTEGER
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE unread_messages(
|
||||||
|
message_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE
|
||||||
|
);
|
||||||
|
|
||||||
CREATE TABLE logs(
|
CREATE TABLE logs(
|
||||||
log_line_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
|
log_line_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||||
jid_id INTEGER,
|
jid_id INTEGER,
|
||||||
|
@ -105,6 +123,8 @@ def check_and_possibly_create_paths():
|
||||||
print _('%s is directory but should be file') % LOG_DB_PATH
|
print _('%s is directory but should be file') % LOG_DB_PATH
|
||||||
print _('Gajim will now exit')
|
print _('Gajim will now exit')
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
else:
|
||||||
|
assert_um_exists()
|
||||||
|
|
||||||
else: # dot_gajim doesn't exist
|
else: # dot_gajim doesn't exist
|
||||||
if dot_gajim: # is '' on win9x so avoid that
|
if dot_gajim: # is '' on win9x so avoid that
|
||||||
|
|
|
@ -1288,7 +1288,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco)
|
||||||
return
|
return
|
||||||
if msg.getTag('body') and self.name not in no_log_for and jid not in\
|
if msg.getTag('body') and self.name not in no_log_for and jid not in\
|
||||||
no_log_for and msgtxt:
|
no_log_for and msgtxt:
|
||||||
gajim.logger.write('chat_msg_recv', frm, msgtxt, tim = tim,
|
msg_id = gajim.logger.write('chat_msg_recv', frm, msgtxt, tim = tim,
|
||||||
subject = subject)
|
subject = subject)
|
||||||
self.dispatch('MSG', (frm, msgtxt, tim, encrypted, mtype, subject,
|
self.dispatch('MSG', (frm, msgtxt, tim, encrypted, mtype, subject,
|
||||||
chatstate, msg_id, composing_jep))
|
chatstate, msg_id, composing_jep))
|
||||||
|
|
|
@ -194,10 +194,35 @@ class Logger:
|
||||||
|
|
||||||
return kind_col, show_col
|
return kind_col, show_col
|
||||||
|
|
||||||
def commit_to_db(self, values):
|
def commit_to_db(self, values, write_unread = False):
|
||||||
#print 'saving', values
|
#print 'saving', values
|
||||||
sql = 'INSERT INTO logs (jid_id, contact_name, time, kind, show, message, subject) VALUES (?, ?, ?, ?, ?, ?, ?)'
|
sql = 'INSERT INTO logs (jid_id, contact_name, time, kind, show, message, subject) VALUES (?, ?, ?, ?, ?, ?, ?)'
|
||||||
self.cur.execute(sql, values)
|
self.cur.execute(sql, values)
|
||||||
|
message_id = None
|
||||||
|
try:
|
||||||
|
self.con.commit()
|
||||||
|
if write_unread:
|
||||||
|
message_id = self.cur.lastrowid
|
||||||
|
except sqlite.OperationalError, e:
|
||||||
|
print >> sys.stderr, str(e)
|
||||||
|
if message_id:
|
||||||
|
self.insert_unread_events(message_id)
|
||||||
|
return message_id
|
||||||
|
|
||||||
|
def insert_unread_events(self, message_id):
|
||||||
|
''' add unread message with id: message_id'''
|
||||||
|
sql = 'INSERT INTO unread_messages VALUES (%d)' % message_id
|
||||||
|
self.cur.execute(sql)
|
||||||
|
try:
|
||||||
|
self.con.commit()
|
||||||
|
except sqlite.OperationalError, e:
|
||||||
|
print >> sys.stderr, str(e)
|
||||||
|
|
||||||
|
def set_read_messages(self, message_ids):
|
||||||
|
''' mark all messages with ids in message_ids as read'''
|
||||||
|
ids = ','.join([str(i) for i in message_ids])
|
||||||
|
sql = 'DELETE FROM unread_messages WHERE message_id IN (%s)' % ids
|
||||||
|
self.cur.execute(sql)
|
||||||
try:
|
try:
|
||||||
self.con.commit()
|
self.con.commit()
|
||||||
except sqlite.OperationalError, e:
|
except sqlite.OperationalError, e:
|
||||||
|
@ -234,6 +259,8 @@ class Logger:
|
||||||
kind_col, show_col = self.convert_human_values_to_db_api_values(kind,
|
kind_col, show_col = self.convert_human_values_to_db_api_values(kind,
|
||||||
show)
|
show)
|
||||||
|
|
||||||
|
write_unread = False
|
||||||
|
|
||||||
# now we may have need to do extra care for some values in columns
|
# now we may have need to do extra care for some values in columns
|
||||||
if kind == 'status': # we store (not None) time, jid, show, msg
|
if kind == 'status': # we store (not None) time, jid, show, msg
|
||||||
# status for roster items
|
# status for roster items
|
||||||
|
@ -260,13 +287,15 @@ class Logger:
|
||||||
contact_name_col = nick
|
contact_name_col = nick
|
||||||
else:
|
else:
|
||||||
jid_id = self.get_jid_id(jid)
|
jid_id = self.get_jid_id(jid)
|
||||||
|
if kind == 'chat_msg_recv':
|
||||||
|
write_unread = True
|
||||||
|
|
||||||
if show_col == 'UNKNOWN': # unknown show, do not log
|
if show_col == 'UNKNOWN': # unknown show, do not log
|
||||||
return
|
return
|
||||||
|
|
||||||
values = (jid_id, contact_name_col, time_col, kind_col, show_col,
|
values = (jid_id, contact_name_col, time_col, kind_col, show_col,
|
||||||
message_col, subject_col)
|
message_col, subject_col)
|
||||||
self.commit_to_db(values)
|
return self.commit_to_db(values, write_unread)
|
||||||
|
|
||||||
def get_last_conversation_lines(self, jid, restore_how_many_rows,
|
def get_last_conversation_lines(self, jid, restore_how_many_rows,
|
||||||
pending_how_many, timeout):
|
pending_how_many, timeout):
|
||||||
|
|
|
@ -618,7 +618,7 @@ class Interface:
|
||||||
|
|
||||||
# array: (jid, msg, time, encrypted, msg_type, subject)
|
# array: (jid, msg, time, encrypted, msg_type, subject)
|
||||||
self.roster.on_message(jid, message, array[2], account, array[3],
|
self.roster.on_message(jid, message, array[2], account, array[3],
|
||||||
msg_type, array[5], resource)
|
msg_type, array[5], resource, msg_id)
|
||||||
if self.remote_ctrl:
|
if self.remote_ctrl:
|
||||||
self.remote_ctrl.raise_signal('NewMessage', (account, array))
|
self.remote_ctrl.raise_signal('NewMessage', (account, array))
|
||||||
|
|
||||||
|
|
|
@ -2097,7 +2097,7 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
|
||||||
mw.new_tab(gc_control)
|
mw.new_tab(gc_control)
|
||||||
|
|
||||||
def on_message(self, jid, msg, tim, account, encrypted = False,
|
def on_message(self, jid, msg, tim, account, encrypted = False,
|
||||||
msg_type = '', subject = None, resource = ''):
|
msg_type = '', subject = None, resource = '', msg_id = None):
|
||||||
'''when we receive a message'''
|
'''when we receive a message'''
|
||||||
contact = None
|
contact = None
|
||||||
# if chat window will be for specific resource
|
# if chat window will be for specific resource
|
||||||
|
@ -2167,6 +2167,8 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
|
||||||
typ = 'status'
|
typ = 'status'
|
||||||
ctrl.print_conversation(msg, typ, tim = tim, encrypted = encrypted,
|
ctrl.print_conversation(msg, typ, tim = tim, encrypted = encrypted,
|
||||||
subject = subject)
|
subject = subject)
|
||||||
|
if msg_id:
|
||||||
|
gajim.logger.set_read_messages([msg_id])
|
||||||
return
|
return
|
||||||
|
|
||||||
# We save it in a queue
|
# We save it in a queue
|
||||||
|
@ -2176,7 +2178,7 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
|
||||||
if msg_type == 'normal':
|
if msg_type == 'normal':
|
||||||
kind = 'normal'
|
kind = 'normal'
|
||||||
qs[fjid].append((kind, (msg, subject, msg_type, tim, encrypted,
|
qs[fjid].append((kind, (msg, subject, msg_type, tim, encrypted,
|
||||||
resource)))
|
resource, msg_id)))
|
||||||
self.nb_unread += 1
|
self.nb_unread += 1
|
||||||
if popup:
|
if popup:
|
||||||
if not ctrl:
|
if not ctrl:
|
||||||
|
|
Loading…
Reference in New Issue