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:
tmolitor 2016-09-05 03:25:37 +02:00
parent 235cadd5cc
commit 86345055cc
5 changed files with 43 additions and 31 deletions

View File

@ -849,7 +849,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
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,
xep0184_id=None, graphics=True, displaymarking=None, msg_log_id=None,
correct_id=None):
correct_id=None, additional_data={}):
"""
Print 'chat' type messages
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
# resource
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:
textview.print_conversation_line(text, jid, kind, name, tim,
other_tags_for_name, other_tags_for_time, other_tags_for_text,
subject, old_kind, xhtml, simple=simple, graphics=graphics,
displaymarking=displaymarking)
displaymarking=displaymarking, additional_data=additional_data)
if xep0184_id is not None:
textview.show_xep0184_warning(xep0184_id)
@ -2973,8 +2973,9 @@ class ChatControl(ChatControlBase):
rows = []
local_old_kind = None
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]
additional_data = row[4]
if not msg: # message is empty, we don't print it
continue
if row[1] in (constants.KIND_CHAT_MSG_SENT,
@ -3004,7 +3005,7 @@ class ChatControl(ChatControlBase):
ChatControlBase.print_conversation_line(self, msg, kind, name,
tim, small_attr, small_attr + ['restored_message'],
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'):
local_old_kind = None
else:

View File

@ -472,10 +472,10 @@ class Logger:
try:
self.cur.execute(
'SELECT message_id, shown from unread_messages')
results = self.cur.fetchall()
unread_results = self.cur.fetchall()
except Exception:
pass
for message in results:
unread_results = []
for message in unread_results:
msg_log_id = message[0]
shown = message[1]
# here we get infos for that message, and related jid from jids table
@ -483,7 +483,7 @@ class Logger:
# that called this function
self.cur.execute('''
SELECT logs.log_line_id, logs.message, logs.time, logs.subject,
jids.jid
jids.jid, logs.additional_data
FROM logs, jids
WHERE logs.log_line_id = %d AND logs.jid_id = jids.jid_id
''' % msg_log_id
@ -493,7 +493,10 @@ class Logger:
# Log line is no more in logs table. remove it from unread_messages
self.set_read_messages([msg_log_id])
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
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)
try:
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
ORDER BY time DESC LIMIT %d OFFSET %d
''' % (where_sql, constants.KIND_SINGLE_MSG_RECV,
@ -612,6 +615,9 @@ class Logger:
restore_how_many_rows, pending_how_many), jid_tuple)
results = self.cur.fetchall()
for entry in results:
entry = list(entry)
entry[4] = json.loads(entry[4])
except sqlite.DatabaseError:
raise exceptions.DatabaseMalformed
results.reverse()
@ -646,13 +652,16 @@ class Logger:
last_second_of_day = start_of_day + seconds_in_a_day - 1
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)
AND time BETWEEN %d AND %d
ORDER BY time
''' % (where_sql, start_of_day, last_second_of_day), jid_tuple)
results = self.cur.fetchall()
for entry in results:
entry = list(entry)
entry[6] = json.loads(entry[6])
return results
def get_search_results_for_query(self, jid, query, account, year=False,

View File

@ -460,7 +460,7 @@ class ConversationTextview(GObject.GObject):
self.tv.add_child_at_anchor(img, anchor)
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]
m2 = self.last_sent_message_marks[1]
buffer_ = self.tv.get_buffer()
@ -472,7 +472,7 @@ class ConversationTextview(GObject.GObject):
if message.startswith('/me'):
tag = 'outgoing'
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') % \
GLib.markup_escape_text(old_txt)
self.show_corrected_message_warning(i2, tt_txt)
@ -480,7 +480,7 @@ class ConversationTextview(GObject.GObject):
left_gravity=True)
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:
return
m1 = self.last_received_message_marks[name][0]
@ -492,7 +492,7 @@ class ConversationTextview(GObject.GObject):
buffer_.delete(i1, i2)
i2 = self.print_conversation_line(message, '', 'incoming', name, None,
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') % \
GLib.markup_escape_text(old_txt)
self.show_corrected_message_warning(i2, tt_txt)
@ -1031,7 +1031,7 @@ class ConversationTextview(GObject.GObject):
helpers.launch_browser_mailer(kind, word)
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
before any special text it founds, then print special text (that happens
@ -1085,7 +1085,7 @@ class ConversationTextview(GObject.GObject):
# now print it
self.print_special_text(special_text, other_tags, graphics=graphics,
iter_=end_iter)
iter_=end_iter, additional_data=additional_data)
specials_limit -= 1
if specials_limit <= 0:
break
@ -1096,7 +1096,7 @@ class ConversationTextview(GObject.GObject):
return end_iter
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
(emots, links, formatting)
@ -1106,7 +1106,7 @@ class ConversationTextview(GObject.GObject):
# PluginSystem: adding GUI extension point for ConversationTextview
self.plugin_modified = False
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:
return
@ -1247,7 +1247,7 @@ class ConversationTextview(GObject.GObject):
def print_conversation_line(self, text, jid, kind, name, tim,
other_tags_for_name=[], other_tags_for_time=[], other_tags_for_text=[],
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
"""
@ -1352,7 +1352,7 @@ class ConversationTextview(GObject.GObject):
else:
self.print_real_text(gajim.config.get(
'chat_merge_consecutive_nickname_indent'),
iter_=end_iter)
iter_=end_iter, additional_data=additional_data)
else:
self.print_name(name, kind, other_tags_for_name,
direction_mark=direction_mark, iter_=end_iter)
@ -1366,7 +1366,7 @@ class ConversationTextview(GObject.GObject):
mark1 = mark
self.print_subject(subject, iter_=end_iter)
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:
mark2 = buffer_.create_mark(None, buffer_.get_end_iter(),
left_gravity=True)
@ -1470,7 +1470,7 @@ class ConversationTextview(GObject.GObject):
self.print_empty_line(end_iter)
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
"""
@ -1490,4 +1490,4 @@ class ConversationTextview(GObject.GObject):
text_tags.append('italic')
# detect urls formatting and if the user has it on emoticons
return self.detect_and_print_special_text(text, text_tags, graphics=graphics,
iter_=iter_)
iter_=iter_, additional_data=additional_data)

View File

@ -399,14 +399,15 @@ class HistoryWindow:
# contact_name, time, kind, show, message
for line in lines:
# 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,
constants.KIND_STATUS):
continue
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
"""
@ -509,10 +510,10 @@ class HistoryWindow:
if 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:
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()
eob = buffer_.get_end_iter()
buffer_.insert_with_tags_by_name(eob, '\n', 'eol')

View File

@ -1850,7 +1850,8 @@ class RosterWindow:
results = gajim.logger.get_unread_msgs()
for result in results:
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 \
shown:
# We have this jid in our contacts list