Added ability to read additional_data from history db and use it in gui extension point print_special_text.
I also found an iterator reuse in common/logger.py, maybe this fixes bug #8277
This commit is contained in:
parent
235cadd5cc
commit
86345055cc
5 changed files with 43 additions and 31 deletions
|
@ -849,7 +849,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
|
||||||
other_tags_for_name=[], other_tags_for_time=[], other_tags_for_text=[],
|
other_tags_for_name=[], other_tags_for_time=[], other_tags_for_text=[],
|
||||||
count_as_new=True, subject=None, old_kind=None, xhtml=None, simple=False,
|
count_as_new=True, subject=None, old_kind=None, xhtml=None, simple=False,
|
||||||
xep0184_id=None, graphics=True, displaymarking=None, msg_log_id=None,
|
xep0184_id=None, graphics=True, displaymarking=None, msg_log_id=None,
|
||||||
correct_id=None):
|
correct_id=None, additional_data={}):
|
||||||
"""
|
"""
|
||||||
Print 'chat' type messages
|
Print 'chat' type messages
|
||||||
correct_id = (message_id, correct_id)
|
correct_id = (message_id, correct_id)
|
||||||
|
@ -874,12 +874,12 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
|
||||||
# this is for carbon copied messages that are sent from another
|
# this is for carbon copied messages that are sent from another
|
||||||
# resource
|
# resource
|
||||||
self.conv_textview.correct_last_sent_message(text, xhtml,
|
self.conv_textview.correct_last_sent_message(text, xhtml,
|
||||||
self.get_our_nick(), old_txt)
|
self.get_our_nick(), old_txt, additional_data=additional_data)
|
||||||
else:
|
else:
|
||||||
textview.print_conversation_line(text, jid, kind, name, tim,
|
textview.print_conversation_line(text, jid, kind, name, tim,
|
||||||
other_tags_for_name, other_tags_for_time, other_tags_for_text,
|
other_tags_for_name, other_tags_for_time, other_tags_for_text,
|
||||||
subject, old_kind, xhtml, simple=simple, graphics=graphics,
|
subject, old_kind, xhtml, simple=simple, graphics=graphics,
|
||||||
displaymarking=displaymarking)
|
displaymarking=displaymarking, additional_data=additional_data)
|
||||||
|
|
||||||
if xep0184_id is not None:
|
if xep0184_id is not None:
|
||||||
textview.show_xep0184_warning(xep0184_id)
|
textview.show_xep0184_warning(xep0184_id)
|
||||||
|
@ -2973,8 +2973,9 @@ class ChatControl(ChatControlBase):
|
||||||
rows = []
|
rows = []
|
||||||
local_old_kind = None
|
local_old_kind = None
|
||||||
self.conv_textview.just_cleared = True
|
self.conv_textview.just_cleared = True
|
||||||
for row in rows: # row[0] time, row[1] has kind, row[2] the message
|
for row in rows: # row[0] time, row[1] has kind, row[2] the message, row[3] subject, row[4] additional_data
|
||||||
msg = row[2]
|
msg = row[2]
|
||||||
|
additional_data = row[4]
|
||||||
if not msg: # message is empty, we don't print it
|
if not msg: # message is empty, we don't print it
|
||||||
continue
|
continue
|
||||||
if row[1] in (constants.KIND_CHAT_MSG_SENT,
|
if row[1] in (constants.KIND_CHAT_MSG_SENT,
|
||||||
|
@ -3004,7 +3005,7 @@ class ChatControl(ChatControlBase):
|
||||||
ChatControlBase.print_conversation_line(self, msg, kind, name,
|
ChatControlBase.print_conversation_line(self, msg, kind, name,
|
||||||
tim, small_attr, small_attr + ['restored_message'],
|
tim, small_attr, small_attr + ['restored_message'],
|
||||||
small_attr + ['restored_message'], False,
|
small_attr + ['restored_message'], False,
|
||||||
old_kind=local_old_kind, xhtml=xhtml)
|
old_kind=local_old_kind, xhtml=xhtml, additional_data=additional_data)
|
||||||
if row[2].startswith('/me ') or row[2].startswith('/me\n'):
|
if row[2].startswith('/me ') or row[2].startswith('/me\n'):
|
||||||
local_old_kind = None
|
local_old_kind = None
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -472,10 +472,10 @@ class Logger:
|
||||||
try:
|
try:
|
||||||
self.cur.execute(
|
self.cur.execute(
|
||||||
'SELECT message_id, shown from unread_messages')
|
'SELECT message_id, shown from unread_messages')
|
||||||
results = self.cur.fetchall()
|
unread_results = self.cur.fetchall()
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
unread_results = []
|
||||||
for message in results:
|
for message in unread_results:
|
||||||
msg_log_id = message[0]
|
msg_log_id = message[0]
|
||||||
shown = message[1]
|
shown = message[1]
|
||||||
# here we get infos for that message, and related jid from jids table
|
# here we get infos for that message, and related jid from jids table
|
||||||
|
@ -483,7 +483,7 @@ class Logger:
|
||||||
# that called this function
|
# that called this function
|
||||||
self.cur.execute('''
|
self.cur.execute('''
|
||||||
SELECT logs.log_line_id, logs.message, logs.time, logs.subject,
|
SELECT logs.log_line_id, logs.message, logs.time, logs.subject,
|
||||||
jids.jid
|
jids.jid, logs.additional_data
|
||||||
FROM logs, jids
|
FROM logs, jids
|
||||||
WHERE logs.log_line_id = %d AND logs.jid_id = jids.jid_id
|
WHERE logs.log_line_id = %d AND logs.jid_id = jids.jid_id
|
||||||
''' % msg_log_id
|
''' % msg_log_id
|
||||||
|
@ -493,7 +493,10 @@ class Logger:
|
||||||
# Log line is no more in logs table. remove it from unread_messages
|
# Log line is no more in logs table. remove it from unread_messages
|
||||||
self.set_read_messages([msg_log_id])
|
self.set_read_messages([msg_log_id])
|
||||||
continue
|
continue
|
||||||
all_messages.append(results[0] + (shown,))
|
results[0] = list(results[0])
|
||||||
|
results[0][5] = json.loads(results[0][5])
|
||||||
|
results[0][6] = shown
|
||||||
|
all_messages.append(results[0])
|
||||||
return all_messages
|
return all_messages
|
||||||
|
|
||||||
def write(self, kind, jid, message=None, show=None, tim=None, subject=None, additional_data={}):
|
def write(self, kind, jid, message=None, show=None, tim=None, subject=None, additional_data={}):
|
||||||
|
@ -603,7 +606,7 @@ class Logger:
|
||||||
# 3 - 8 (we avoid the last 2 lines but we still return 5 asked)
|
# 3 - 8 (we avoid the last 2 lines but we still return 5 asked)
|
||||||
try:
|
try:
|
||||||
self.cur.execute('''
|
self.cur.execute('''
|
||||||
SELECT time, kind, message, subject FROM logs
|
SELECT time, kind, message, subject, additional_data FROM logs
|
||||||
WHERE (%s) AND kind IN (%d, %d, %d, %d, %d) AND time > %d
|
WHERE (%s) AND kind IN (%d, %d, %d, %d, %d) AND time > %d
|
||||||
ORDER BY time DESC LIMIT %d OFFSET %d
|
ORDER BY time DESC LIMIT %d OFFSET %d
|
||||||
''' % (where_sql, constants.KIND_SINGLE_MSG_RECV,
|
''' % (where_sql, constants.KIND_SINGLE_MSG_RECV,
|
||||||
|
@ -612,6 +615,9 @@ class Logger:
|
||||||
restore_how_many_rows, pending_how_many), jid_tuple)
|
restore_how_many_rows, pending_how_many), jid_tuple)
|
||||||
|
|
||||||
results = self.cur.fetchall()
|
results = self.cur.fetchall()
|
||||||
|
for entry in results:
|
||||||
|
entry = list(entry)
|
||||||
|
entry[4] = json.loads(entry[4])
|
||||||
except sqlite.DatabaseError:
|
except sqlite.DatabaseError:
|
||||||
raise exceptions.DatabaseMalformed
|
raise exceptions.DatabaseMalformed
|
||||||
results.reverse()
|
results.reverse()
|
||||||
|
@ -646,13 +652,16 @@ class Logger:
|
||||||
last_second_of_day = start_of_day + seconds_in_a_day - 1
|
last_second_of_day = start_of_day + seconds_in_a_day - 1
|
||||||
|
|
||||||
self.cur.execute('''
|
self.cur.execute('''
|
||||||
SELECT contact_name, time, kind, show, message, subject FROM logs
|
SELECT contact_name, time, kind, show, message, subject, additional_data FROM logs
|
||||||
WHERE (%s)
|
WHERE (%s)
|
||||||
AND time BETWEEN %d AND %d
|
AND time BETWEEN %d AND %d
|
||||||
ORDER BY time
|
ORDER BY time
|
||||||
''' % (where_sql, start_of_day, last_second_of_day), jid_tuple)
|
''' % (where_sql, start_of_day, last_second_of_day), jid_tuple)
|
||||||
|
|
||||||
results = self.cur.fetchall()
|
results = self.cur.fetchall()
|
||||||
|
for entry in results:
|
||||||
|
entry = list(entry)
|
||||||
|
entry[6] = json.loads(entry[6])
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def get_search_results_for_query(self, jid, query, account, year=False,
|
def get_search_results_for_query(self, jid, query, account, year=False,
|
||||||
|
|
|
@ -460,7 +460,7 @@ class ConversationTextview(GObject.GObject):
|
||||||
self.tv.add_child_at_anchor(img, anchor)
|
self.tv.add_child_at_anchor(img, anchor)
|
||||||
buffer_.end_user_action()
|
buffer_.end_user_action()
|
||||||
|
|
||||||
def correct_last_sent_message(self, message, xhtml, name, old_txt):
|
def correct_last_sent_message(self, message, xhtml, name, old_txt, additional_data={}):
|
||||||
m1 = self.last_sent_message_marks[0]
|
m1 = self.last_sent_message_marks[0]
|
||||||
m2 = self.last_sent_message_marks[1]
|
m2 = self.last_sent_message_marks[1]
|
||||||
buffer_ = self.tv.get_buffer()
|
buffer_ = self.tv.get_buffer()
|
||||||
|
@ -472,7 +472,7 @@ class ConversationTextview(GObject.GObject):
|
||||||
if message.startswith('/me'):
|
if message.startswith('/me'):
|
||||||
tag = 'outgoing'
|
tag = 'outgoing'
|
||||||
i2 = self.print_conversation_line(message, '', 'outgoing', name, None,
|
i2 = self.print_conversation_line(message, '', 'outgoing', name, None,
|
||||||
xhtml=xhtml, iter_=i1)
|
xhtml=xhtml, iter_=i1, additional_data=additional_data)
|
||||||
tt_txt = _('<b>Message was corrected. Last message was:</b>\n %s') % \
|
tt_txt = _('<b>Message was corrected. Last message was:</b>\n %s') % \
|
||||||
GLib.markup_escape_text(old_txt)
|
GLib.markup_escape_text(old_txt)
|
||||||
self.show_corrected_message_warning(i2, tt_txt)
|
self.show_corrected_message_warning(i2, tt_txt)
|
||||||
|
@ -480,7 +480,7 @@ class ConversationTextview(GObject.GObject):
|
||||||
left_gravity=True)
|
left_gravity=True)
|
||||||
|
|
||||||
def correct_last_received_message(self, message, xhtml, name, old_txt,
|
def correct_last_received_message(self, message, xhtml, name, old_txt,
|
||||||
other_tags_for_name=[], other_tags_for_text=[]):
|
other_tags_for_name=[], other_tags_for_text=[], additional_data={}):
|
||||||
if name not in self.last_received_message_marks:
|
if name not in self.last_received_message_marks:
|
||||||
return
|
return
|
||||||
m1 = self.last_received_message_marks[name][0]
|
m1 = self.last_received_message_marks[name][0]
|
||||||
|
@ -492,7 +492,7 @@ class ConversationTextview(GObject.GObject):
|
||||||
buffer_.delete(i1, i2)
|
buffer_.delete(i1, i2)
|
||||||
i2 = self.print_conversation_line(message, '', 'incoming', name, None,
|
i2 = self.print_conversation_line(message, '', 'incoming', name, None,
|
||||||
other_tags_for_name=other_tags_for_name,
|
other_tags_for_name=other_tags_for_name,
|
||||||
other_tags_for_text=other_tags_for_text, xhtml=xhtml, iter_=i1)
|
other_tags_for_text=other_tags_for_text, xhtml=xhtml, iter_=i1, additional_data=additional_data)
|
||||||
tt_txt = _('<b>Message was corrected. Last message was:</b>\n %s') % \
|
tt_txt = _('<b>Message was corrected. Last message was:</b>\n %s') % \
|
||||||
GLib.markup_escape_text(old_txt)
|
GLib.markup_escape_text(old_txt)
|
||||||
self.show_corrected_message_warning(i2, tt_txt)
|
self.show_corrected_message_warning(i2, tt_txt)
|
||||||
|
@ -1031,7 +1031,7 @@ class ConversationTextview(GObject.GObject):
|
||||||
helpers.launch_browser_mailer(kind, word)
|
helpers.launch_browser_mailer(kind, word)
|
||||||
|
|
||||||
def detect_and_print_special_text(self, otext, other_tags, graphics=True,
|
def detect_and_print_special_text(self, otext, other_tags, graphics=True,
|
||||||
iter_=None):
|
iter_=None, additional_data={}):
|
||||||
"""
|
"""
|
||||||
Detect special text (emots & links & formatting), print normal text
|
Detect special text (emots & links & formatting), print normal text
|
||||||
before any special text it founds, then print special text (that happens
|
before any special text it founds, then print special text (that happens
|
||||||
|
@ -1085,7 +1085,7 @@ class ConversationTextview(GObject.GObject):
|
||||||
|
|
||||||
# now print it
|
# now print it
|
||||||
self.print_special_text(special_text, other_tags, graphics=graphics,
|
self.print_special_text(special_text, other_tags, graphics=graphics,
|
||||||
iter_=end_iter)
|
iter_=end_iter, additional_data=additional_data)
|
||||||
specials_limit -= 1
|
specials_limit -= 1
|
||||||
if specials_limit <= 0:
|
if specials_limit <= 0:
|
||||||
break
|
break
|
||||||
|
@ -1096,7 +1096,7 @@ class ConversationTextview(GObject.GObject):
|
||||||
return end_iter
|
return end_iter
|
||||||
|
|
||||||
def print_special_text(self, special_text, other_tags, graphics=True,
|
def print_special_text(self, special_text, other_tags, graphics=True,
|
||||||
iter_=None):
|
iter_=None, additional_data={}):
|
||||||
"""
|
"""
|
||||||
Is called by detect_and_print_special_text and prints special text
|
Is called by detect_and_print_special_text and prints special text
|
||||||
(emots, links, formatting)
|
(emots, links, formatting)
|
||||||
|
@ -1106,7 +1106,7 @@ class ConversationTextview(GObject.GObject):
|
||||||
# PluginSystem: adding GUI extension point for ConversationTextview
|
# PluginSystem: adding GUI extension point for ConversationTextview
|
||||||
self.plugin_modified = False
|
self.plugin_modified = False
|
||||||
gajim.plugin_manager.gui_extension_point('print_special_text', self,
|
gajim.plugin_manager.gui_extension_point('print_special_text', self,
|
||||||
special_text, other_tags, graphics)
|
special_text, other_tags, graphics, additional_data)
|
||||||
if self.plugin_modified:
|
if self.plugin_modified:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -1247,7 +1247,7 @@ class ConversationTextview(GObject.GObject):
|
||||||
def print_conversation_line(self, text, jid, kind, name, tim,
|
def print_conversation_line(self, text, jid, kind, name, tim,
|
||||||
other_tags_for_name=[], other_tags_for_time=[], other_tags_for_text=[],
|
other_tags_for_name=[], other_tags_for_time=[], other_tags_for_text=[],
|
||||||
subject=None, old_kind=None, xhtml=None, simple=False, graphics=True,
|
subject=None, old_kind=None, xhtml=None, simple=False, graphics=True,
|
||||||
displaymarking=None, iter_=None):
|
displaymarking=None, iter_=None, additional_data={}):
|
||||||
"""
|
"""
|
||||||
Print 'chat' type messages
|
Print 'chat' type messages
|
||||||
"""
|
"""
|
||||||
|
@ -1352,7 +1352,7 @@ class ConversationTextview(GObject.GObject):
|
||||||
else:
|
else:
|
||||||
self.print_real_text(gajim.config.get(
|
self.print_real_text(gajim.config.get(
|
||||||
'chat_merge_consecutive_nickname_indent'),
|
'chat_merge_consecutive_nickname_indent'),
|
||||||
iter_=end_iter)
|
iter_=end_iter, additional_data=additional_data)
|
||||||
else:
|
else:
|
||||||
self.print_name(name, kind, other_tags_for_name,
|
self.print_name(name, kind, other_tags_for_name,
|
||||||
direction_mark=direction_mark, iter_=end_iter)
|
direction_mark=direction_mark, iter_=end_iter)
|
||||||
|
@ -1366,7 +1366,7 @@ class ConversationTextview(GObject.GObject):
|
||||||
mark1 = mark
|
mark1 = mark
|
||||||
self.print_subject(subject, iter_=end_iter)
|
self.print_subject(subject, iter_=end_iter)
|
||||||
self.print_real_text(text, text_tags, name, xhtml, graphics=graphics,
|
self.print_real_text(text, text_tags, name, xhtml, graphics=graphics,
|
||||||
iter_=end_iter)
|
iter_=end_iter, additional_data=additional_data)
|
||||||
if not iter_ and mark1:
|
if not iter_ and mark1:
|
||||||
mark2 = buffer_.create_mark(None, buffer_.get_end_iter(),
|
mark2 = buffer_.create_mark(None, buffer_.get_end_iter(),
|
||||||
left_gravity=True)
|
left_gravity=True)
|
||||||
|
@ -1470,7 +1470,7 @@ class ConversationTextview(GObject.GObject):
|
||||||
self.print_empty_line(end_iter)
|
self.print_empty_line(end_iter)
|
||||||
|
|
||||||
def print_real_text(self, text, text_tags=[], name=None, xhtml=None,
|
def print_real_text(self, text, text_tags=[], name=None, xhtml=None,
|
||||||
graphics=True, iter_=None):
|
graphics=True, iter_=None, additional_data={}):
|
||||||
"""
|
"""
|
||||||
Add normal and special text. call this to add text
|
Add normal and special text. call this to add text
|
||||||
"""
|
"""
|
||||||
|
@ -1490,4 +1490,4 @@ class ConversationTextview(GObject.GObject):
|
||||||
text_tags.append('italic')
|
text_tags.append('italic')
|
||||||
# detect urls formatting and if the user has it on emoticons
|
# detect urls formatting and if the user has it on emoticons
|
||||||
return self.detect_and_print_special_text(text, text_tags, graphics=graphics,
|
return self.detect_and_print_special_text(text, text_tags, graphics=graphics,
|
||||||
iter_=iter_)
|
iter_=iter_, additional_data=additional_data)
|
||||||
|
|
|
@ -399,14 +399,15 @@ class HistoryWindow:
|
||||||
# contact_name, time, kind, show, message
|
# contact_name, time, kind, show, message
|
||||||
for line in lines:
|
for line in lines:
|
||||||
# line[0] is contact_name, line[1] is time of message
|
# line[0] is contact_name, line[1] is time of message
|
||||||
# line[2] is kind, line[3] is show, line[4] is message
|
# line[2] is kind, line[3] is show, line[4] is message, line[5] is subject
|
||||||
|
# line[6] is additional_data
|
||||||
if not show_status and line[2] in (constants.KIND_GCSTATUS,
|
if not show_status and line[2] in (constants.KIND_GCSTATUS,
|
||||||
constants.KIND_STATUS):
|
constants.KIND_STATUS):
|
||||||
continue
|
continue
|
||||||
self._add_new_line(line[0], line[1], line[2], line[3], line[4],
|
self._add_new_line(line[0], line[1], line[2], line[3], line[4],
|
||||||
line[5])
|
line[5], line[6])
|
||||||
|
|
||||||
def _add_new_line(self, contact_name, tim, kind, show, message, subject):
|
def _add_new_line(self, contact_name, tim, kind, show, message, subject, additional_data):
|
||||||
"""
|
"""
|
||||||
Add a new line in textbuffer
|
Add a new line in textbuffer
|
||||||
"""
|
"""
|
||||||
|
@ -509,10 +510,10 @@ class HistoryWindow:
|
||||||
|
|
||||||
if tag_msg:
|
if tag_msg:
|
||||||
self.history_textview.print_real_text(message, [tag_msg],
|
self.history_textview.print_real_text(message, [tag_msg],
|
||||||
name=contact_name, xhtml=xhtml)
|
name=contact_name, xhtml=xhtml, additional_data=additional_data)
|
||||||
else:
|
else:
|
||||||
self.history_textview.print_real_text(message, name=contact_name,
|
self.history_textview.print_real_text(message, name=contact_name,
|
||||||
xhtml=xhtml)
|
xhtml=xhtml, additional_data=additional_data)
|
||||||
buffer_ = self.history_textview.tv.get_buffer()
|
buffer_ = self.history_textview.tv.get_buffer()
|
||||||
eob = buffer_.get_end_iter()
|
eob = buffer_.get_end_iter()
|
||||||
buffer_.insert_with_tags_by_name(eob, '\n', 'eol')
|
buffer_.insert_with_tags_by_name(eob, '\n', 'eol')
|
||||||
|
|
|
@ -1850,7 +1850,8 @@ class RosterWindow:
|
||||||
results = gajim.logger.get_unread_msgs()
|
results = gajim.logger.get_unread_msgs()
|
||||||
for result in results:
|
for result in results:
|
||||||
jid = result[4]
|
jid = result[4]
|
||||||
shown = result[5]
|
additional_data = result[5]
|
||||||
|
shown = result[6]
|
||||||
if gajim.contacts.get_first_contact_from_jid(account, jid) and not \
|
if gajim.contacts.get_first_contact_from_jid(account, jid) and not \
|
||||||
shown:
|
shown:
|
||||||
# We have this jid in our contacts list
|
# We have this jid in our contacts list
|
||||||
|
|
Loading…
Add table
Reference in a new issue