Philipp Hörist pushed to branch master at gajim / gajim
Commits: cf7b9f26 by Philipp Hörist at 2019-06-10T17:08:55Z Dont style delayed messages differently
The timestamp should be enough indication of how recent the message is
- - - - - 40dd5cf7 by Philipp Hörist at 2019-06-10T19:31:19Z Remove duplicate code
Same code exists in the ChatControlBase.add_message() method already
- - - - - 021e3fc1 by Philipp Hörist at 2019-06-10T19:31:27Z Fix documentation
- - - - - 99906bfc by Philipp Hörist at 2019-06-10T19:31:27Z Fix MUC Messages sent by the server
- - - - - b23759c9 by Philipp Hörist at 2019-06-10T19:31:33Z Rename msg_stanza_id to message_id
This helps to prevent confusion because there exist XEP-0359 stanza-ids which are not used here
- - - - - 6d50b72e by Philipp Hörist at 2019-06-10T19:31:33Z Remove unused argument
graphics was always True, we only use it in add_info_message()
- - - - - 0334f676 by Philipp Hörist at 2019-06-10T19:31:33Z ChatControl: Simplify receipt code
Determine if we add a receipt mark inisde ConversationsTextview instead of in the ChatControl
- - - - -
7 changed files:
- gajim/chat_control.py - gajim/chat_control_base.py - gajim/common/config.py - gajim/conversation_textview.py - gajim/data/style/default.css - gajim/groupchat_control.py - gajim/gtk/themes.py
Changes:
===================================== gajim/chat_control.py ===================================== @@ -858,7 +858,7 @@ class ChatControl(ChatControlBase): self.add_message( obj.msgtxt, kind, tim=obj.timestamp, encrypted=obj.encrypted, correct_id=obj.correct_id, - msg_stanza_id=obj.message_id, additional_data=obj.additional_data) + message_id=obj.message_id, additional_data=obj.additional_data)
def _nec_decrypted_message_received(self, obj): if not obj.msgtxt: @@ -871,18 +871,16 @@ class ChatControl(ChatControlBase): return
typ = '' - xep0184_id = None if obj.mtype == 'error': typ = 'error' if obj.forwarded and obj.sent: typ = 'out' - if obj.jid != app.get_jid_from_account(obj.conn.name): - xep0184_id = obj.id_ + self.add_message(obj.msgtxt, typ, tim=obj.timestamp, encrypted=obj.encrypted, subject=obj.subject, xhtml=obj.xhtml, displaymarking=obj.displaymarking, - msg_log_id=obj.msg_log_id, msg_stanza_id=obj.id_, correct_id=obj.correct_id, - xep0184_id=xep0184_id, additional_data=obj.additional_data) + msg_log_id=obj.msg_log_id, message_id=obj.message_id, correct_id=obj.correct_id, + additional_data=obj.additional_data) if obj.msg_log_id: pw = self.parent_win end = self.conv_textview.autoscroll @@ -899,11 +897,8 @@ class ChatControl(ChatControlBase): return
self.last_sent_msg = obj.stanza_id - id_ = obj.msg_iq.getID() - xep0184_id = None - if self.contact.jid != app.get_jid_from_account(self.account): - if app.config.get_per('accounts', self.account, 'request_receipt'): - xep0184_id = id_ + message_id = obj.msg_iq.getID() + if obj.label: displaymarking = obj.label.getTag('displaymarking') else: @@ -914,8 +909,8 @@ class ChatControl(ChatControlBase): self.msg_textview, 'gajim-msg-correcting')
self.add_message(obj.message, self.contact.jid, tim=obj.timestamp, - encrypted=obj.encrypted, xep0184_id=xep0184_id, xhtml=obj.xhtml, - displaymarking=displaymarking, msg_stanza_id=id_, + encrypted=obj.encrypted, xhtml=obj.xhtml, + displaymarking=displaymarking, message_id=message_id, correct_id=obj.correct_id, additional_data=obj.additional_data)
@@ -947,9 +942,9 @@ class ChatControl(ChatControlBase): return app.nicks[self.account]
def add_message(self, text, frm='', tim=None, encrypted=None, - subject=None, xhtml=None, xep0184_id=None, - displaymarking=None, msg_log_id=None, correct_id=None, - msg_stanza_id=None, additional_data=None): + subject=None, xhtml=None, + displaymarking=None, msg_log_id=None, correct_id=None, + message_id=None, additional_data=None): """ Print a line in the conversation
@@ -988,8 +983,8 @@ class ChatControl(ChatControlBase): xhtml = '<body xmlns="%s">%s</body>' % (NS_XHTML, xhtml) ChatControlBase.add_message(self, text, kind, name, tim, subject=subject, old_kind=self.old_msg_kind, xhtml=xhtml, - xep0184_id=xep0184_id, displaymarking=displaymarking, - msg_log_id=msg_log_id, msg_stanza_id=msg_stanza_id, + displaymarking=displaymarking, + msg_log_id=msg_log_id, message_id=message_id, correct_id=correct_id, additional_data=additional_data, encrypted=encrypted) if text.startswith('/me ') or text.startswith('/me\n'): @@ -1308,20 +1303,21 @@ class ChatControl(ChatControlBase):
tim = float(row.time)
- if app.config.get('restored_messages_small'): - small_attr = ['small'] - else: - small_attr = [] xhtml = None if msg.startswith('<body '): xhtml = msg if row.subject: msg = _('Subject: %(subject)s\n%(message)s') % \ {'subject': row.subject, 'message': msg} - ChatControlBase.add_message(self, msg, kind, name, - tim, small_attr, small_attr + ['restored_message'], - small_attr + ['restored_message'], False, - old_kind=local_old_kind, xhtml=xhtml, additional_data=additional_data) + ChatControlBase.add_message(self, + msg, + kind, + name, + tim, + restored=True, + old_kind=local_old_kind, + xhtml=xhtml, + additional_data=additional_data) if row.message.startswith('/me ') or row.message.startswith('/me\n'): local_old_kind = None else:
===================================== gajim/chat_control_base.py ===================================== @@ -931,11 +931,12 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools): text, 'status', '', None)
def add_message(self, text, kind, name, tim, - other_tags_for_name=None, other_tags_for_time=None, other_tags_for_text=None, - count_as_new=True, subject=None, old_kind=None, xhtml=None, - xep0184_id=None, graphics=True, displaymarking=None, msg_log_id=None, - msg_stanza_id=None, correct_id=None, additional_data=None, - encrypted=None): + other_tags_for_name=None, other_tags_for_time=None, + other_tags_for_text=None, restored=False, subject=None, + old_kind=None, xhtml=None, + displaymarking=None, msg_log_id=None, + message_id=None, correct_id=None, additional_data=None, + encrypted=None): """ Print 'chat' type messages correct_id = (message_id, correct_id) @@ -958,16 +959,14 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
textview.print_conversation_line(text, kind, name, tim, other_tags_for_name, other_tags_for_time, other_tags_for_text, - subject, old_kind, xhtml, graphics=graphics, - displaymarking=displaymarking, msg_stanza_id=msg_stanza_id, + subject, old_kind, xhtml, + displaymarking=displaymarking, message_id=message_id, correct_id=correct_id, additional_data=additional_data, encrypted=encrypted)
- if xep0184_id is not None: - textview.add_xep0184_mark(xep0184_id) - - if not count_as_new: + if restored: return + if kind == 'incoming': if not self.type_id == message_control.TYPE_GC or \ app.config.notify_for_muc(jid) or \
===================================== gajim/common/config.py ===================================== @@ -236,7 +236,6 @@ class Config: 'print_status_muc_default': [opt_bool, False, _('Default Setting: Show a status message for all status (away, dnd, etc.) changes of users in a group chat')], 'log_contact_status_changes': [opt_bool, False], 'log_xhtml_messages': [opt_bool, False, _('Log XHTML messages instead of plain text messages.')], - 'restored_messages_small': [opt_bool, True, _('If true, restored messages will use a smaller font than the default one.')], 'hide_avatar_of_transport': [opt_bool, False, _('Don't show avatar for the transport itself.')], 'roster_window_skip_taskbar': [opt_bool, False, _('Don't show roster in the system taskbar.')], 'use_urgency_hint': [opt_bool, True, _('If true, make the window flash (the default behaviour in most Window Managers) when holding pending events.')],
===================================== gajim/conversation_textview.py ===================================== @@ -206,9 +206,9 @@ class ConversationTextview(GObject.GObject): self.handlers = {} self.image_cache = {} self.xep0184_marks = {} - # self.last_sent_message_id = msg_stanza_id + # self.last_sent_message_id = message_id self.last_sent_message_id = None - # last_received_message_id[name] = (msg_stanza_id, line_start_mark) + # last_received_message_id[name] = (message_id, line_start_mark) self.last_received_message_id = {} self.autoscroll = True # connect signals @@ -285,10 +285,6 @@ class ConversationTextview(GObject.GObject): #Pango.SCALE_SMALL tag.set_property('scale', 0.8333333333333)
- tag = buffer_.create_tag('restored_message') - color = app.css_config.get_value('.gajim-restored-message', StyleAttr.COLOR) - tag.set_property('foreground', color) - self.tv.create_tags()
tag = buffer_.create_tag('bold') @@ -898,9 +894,9 @@ class ConversationTextview(GObject.GObject): buffer_.insert_with_tags_by_name(iter_, '\n', 'eol') self.just_cleared = False
- def get_end_mark(self, msg_stanza_id, start_mark): + def get_end_mark(self, message_id, start_mark): for index, msg in enumerate(self.message_list): - if msg[2] == msg_stanza_id and msg[1] == start_mark: + if msg[2] == message_id and msg[1] == start_mark: try: end_mark = self.message_list[index + 1][1] end_mark_name = end_mark.get_name() @@ -918,7 +914,7 @@ class ConversationTextview(GObject.GObject): return None, None
def get_insert_mark(self, timestamp): - # message_list = [(timestamp, line_start_mark, msg_stanza_id)] + # message_list = [(timestamp, line_start_mark, message_id)] # We check if this is a new Message try: if self.message_list[-1][0] <= timestamp: @@ -939,7 +935,7 @@ class ConversationTextview(GObject.GObject): def print_conversation_line(self, text, kind, name, tim, other_tags_for_name=None, other_tags_for_time=None, other_tags_for_text=None, subject=None, old_kind=None, xhtml=None, graphics=True, - displaymarking=None, msg_stanza_id=None, correct_id=None, additional_data=None, + displaymarking=None, message_id=None, correct_id=None, additional_data=None, encrypted=None): """ Print 'chat' type messages @@ -966,12 +962,12 @@ class ConversationTextview(GObject.GObject): index, insert_mark, old_txt = \ self.correct_message(correct_id, kind, name) if correct_id in self.corrected_text_list: - self.corrected_text_list[msg_stanza_id] = \ + self.corrected_text_list[message_id] = \ self.corrected_text_list[correct_id] + '\n{}' \ .format(GLib.markup_escape_text(old_txt)) del self.corrected_text_list[correct_id] else: - self.corrected_text_list[msg_stanza_id] = \ + self.corrected_text_list[message_id] = \ _('<b>Message corrected. Original message:</b>\n{}') \ .format(GLib.markup_escape_text(old_txt)) corrected = True @@ -989,7 +985,7 @@ class ConversationTextview(GObject.GObject): 'Printed Line: %s, %s, %s, inserted after: %s' ', stanza-id: %s, correct-id: %s', self.line, text, tim, insert_mark_name, - msg_stanza_id, correct_id) + message_id, correct_id)
if not insert_mark: # Texview is empty or Message is new iter_ = buffer_.get_end_iter() @@ -1058,14 +1054,14 @@ class ConversationTextview(GObject.GObject):
if corrected: # Show Correction Icon - buffer_.create_tag(tag_name=msg_stanza_id) + buffer_.create_tag(tag_name=message_id) buffer_.insert(iter_, ' ') icon = load_icon('document-edit-symbolic', self.tv, pixbuf=True) buffer_.insert_pixbuf( iter_, icon) tag_start_iter = iter_.copy() tag_start_iter.backward_chars(2) - buffer_.apply_tag_by_name(msg_stanza_id, tag_start_iter, iter_) + buffer_.apply_tag_by_name(message_id, tag_start_iter, iter_)
# If we inserted a Line we add a new line at the end if insert_mark: @@ -1079,18 +1075,18 @@ class ConversationTextview(GObject.GObject):
if index is None: # New Message - self.message_list.append((tim, new_mark, msg_stanza_id)) + self.message_list.append((tim, new_mark, message_id)) elif corrected: # Replace the corrected message - self.message_list[index] = (tim, new_mark, msg_stanza_id) + self.message_list[index] = (tim, new_mark, message_id) else: # We insert the message at index - self.message_list.insert(index, (tim, new_mark, msg_stanza_id)) + self.message_list.insert(index, (tim, new_mark, message_id))
if kind == 'incoming': - self.last_received_message_id[name] = (msg_stanza_id, new_mark) + self.last_received_message_id[name] = (message_id, new_mark) elif kind == 'outgoing': - self.last_sent_message_id = (msg_stanza_id, new_mark) + self.last_sent_message_id = (message_id, new_mark)
if not insert_mark: if self.autoscroll or kind == 'outgoing': @@ -1101,7 +1097,9 @@ class ConversationTextview(GObject.GObject): buffer_.end_user_action()
self.line += 1 - return iter_ + + if kind == 'outgoing' and message_id is not None: + self.add_xep0184_mark(message_id)
def get_time_to_show(self, tim, direction_mark=''): """
===================================== gajim/data/style/default.css ===================================== @@ -1 +1 @@ - .gajim-incoming-nickname { color: rgb(164, 0, 0) } .gajim-outgoing-nickname { color: rgb(52, 101, 164) } .gajim-outgoing-message-text { color: rgb(85, 87, 83) } .gajim-status-message { color: rgb(78, 154, 6) } .gajim-url { color: rgb(32, 74, 135) } .gajim-highlight-message { color: rgb(255, 128, 128) } .gajim-restored-message { color: rgb(85, 87, 83) } .gajim-roster-disconnected { background: rgb(171 ,97 ,97) } .gajim-roster-connected { background: rgb(173, 195, 198) } .gajim-state-composing { color: rgb(0, 139, 0) } .gajim-state-inactive { color: rgb(158, 158, 158) } .gajim-state-gone { color: rgb(128, 128, 128) } .gajim-state-paused { color: rgb(0, 0, 205) } .gajim-message-placeholder { color: rgb(195, 195, 192) } \ No newline at end of file + .gajim-incoming-nickname { color: rgb(164, 0, 0) } .gajim-outgoing-nickname { color: rgb(52, 101, 164) } .gajim-outgoing-message-text { color: rgb(85, 87, 83) } .gajim-status-message { color: rgb(78, 154, 6) } .gajim-url { color: rgb(32, 74, 135) } .gajim-highlight-message { color: rgb(255, 128, 128) } .gajim-roster-disconnected { background: rgb(171 ,97 ,97) } .gajim-roster-connected { background: rgb(173, 195, 198) } .gajim-state-composing { color: rgb(0, 139, 0) } .gajim-state-inactive { color: rgb(158, 158, 158) } .gajim-state-gone { color: rgb(128, 128, 128) } .gajim-state-paused { color: rgb(0, 0, 205) } .gajim-message-placeholder { color: rgb(195, 195, 192) } \ No newline at end of file
===================================== gajim/groupchat_control.py ===================================== @@ -56,7 +56,6 @@ from gajim.common import events from gajim.common import app from gajim.common import helpers from gajim.common.helpers import open_uri -from gajim.common.helpers import AdditionalDataDict from gajim.common import ged from gajim.common.i18n import _ from gajim.common import contacts @@ -1203,7 +1202,7 @@ class GroupchatControl(ChatControlBase): obj.msgtxt, contact=obj.nick, tim=obj.timestamp, correct_id=obj.correct_id, encrypted=obj.encrypted, - msg_stanza_id=obj.message_id, + message_id=obj.message_id, additional_data=obj.additional_data)
def _nec_gc_message_received(self, obj): @@ -1217,24 +1216,14 @@ class GroupchatControl(ChatControlBase): xhtml=obj.xhtml_msgtxt, displaymarking=obj.displaymarking, additional_data=obj.additional_data) else: - # message from someone - if obj.delayed: - # don't print xhtml if it's an old message. - # Like that xhtml messages are grayed too. - self.add_delayed_message( - obj.msgtxt, contact=obj.nick, - tim=obj.timestamp, xhtml=None, encrypted=obj.encrypted, - displaymarking=obj.displaymarking, msg_stanza_id=obj.id_, - additional_data=obj.additional_data) - else: - if obj.nick == self.nick: - self.last_sent_txt = obj.msgtxt - self.add_message( - obj.msgtxt, contact=obj.nick, - tim=obj.timestamp, xhtml=obj.xhtml_msgtxt, - displaymarking=obj.displaymarking, encrypted=obj.encrypted, - correct_id=obj.correct_id, msg_stanza_id=obj.id_, - additional_data=obj.additional_data) + if obj.nick == self.nick: + self.last_sent_txt = obj.msgtxt + self.add_message( + obj.msgtxt, contact=obj.nick, + tim=obj.timestamp, xhtml=obj.xhtml_msgtxt, + displaymarking=obj.displaymarking, encrypted=obj.encrypted, + correct_id=obj.correct_id, message_id=obj.message_id, + additional_data=obj.additional_data) obj.needs_highlight = self.needs_visual_notification(obj.msgtxt)
def on_private_message(self, nick, sent, msg, tim, xhtml, session, msg_log_id=None, @@ -1287,46 +1276,23 @@ class GroupchatControl(ChatControlBase): return None return self.model.get_iter(path)
- - def add_delayed_message(self, text, contact='', tim=None, xhtml=None, - displaymarking=None, msg_stanza_id=None, encrypted=None, additional_data=None): - if additional_data is None: - additional_data = AdditionalDataDict() - - if contact: - if contact == self.nick: # it's us - kind = 'outgoing' - else: - kind = 'incoming' - else: - kind = 'status' - if app.config.get('restored_messages_small'): - small_attr = ['small'] - else: - small_attr = [] - - ChatControlBase.add_message(self, text, kind, contact, tim, - small_attr, small_attr + ['restored_message'], - small_attr + ['restored_message'], count_as_new=False, xhtml=xhtml, - displaymarking=displaymarking, msg_stanza_id=msg_stanza_id, - encrypted=encrypted, additional_data=additional_data) - def add_message(self, text, contact='', tim=None, xhtml=None, - graphics=True, displaymarking=None, correct_id=None, msg_stanza_id=None, - encrypted=None, additional_data=None): + displaymarking=None, correct_id=None, message_id=None, + encrypted=None, additional_data=None): """ - Print a line in the conversation + Add message to the ConversationsTextview
- If contact is set: it's a message from someone or an info message - (contact = 'info' in such a case). + If contact is set: it's a message from someone If contact is not set: it's a message from the server or help. """ - if additional_data is None: - additional_data = AdditionalDataDict() + other_tags_for_name = [] other_tags_for_text = []
- if contact == self.nick: # it's us + if not contact: + # Message from the server + kind = 'status' + elif contact == self.nick: # it's us kind = 'outgoing' else: kind = 'incoming' @@ -1353,8 +1319,8 @@ class GroupchatControl(ChatControlBase):
ChatControlBase.add_message(self, text, kind, contact, tim, other_tags_for_name, [], other_tags_for_text, xhtml=xhtml, - graphics=graphics, displaymarking=displaymarking, - correct_id=correct_id, msg_stanza_id=msg_stanza_id, encrypted=encrypted, + displaymarking=displaymarking, + correct_id=correct_id, message_id=message_id, encrypted=encrypted, additional_data=additional_data)
def get_nb_unread(self): @@ -1533,7 +1499,7 @@ class GroupchatControl(ChatControlBase): frm = 'out' obj.session.control.add_message(obj.msgtxt, frm, tim=obj.timestamp, xhtml=obj.xhtml, encrypted=obj.encrypted, - displaymarking=obj.displaymarking, msg_stanza_id=obj.id_, + displaymarking=obj.displaymarking, message_id=obj.message_id, correct_id=obj.correct_id) else: # otherwise pass it off to the control to be queued
===================================== gajim/gtk/themes.py ===================================== @@ -153,10 +153,6 @@ CSS_STYLE_OPTIONS = [ '.gajim-msg-correcting text', StyleAttr.BACKGROUND),
- StyleOption(_('Restored Message Color'), - '.gajim-restored-message', - StyleAttr.COLOR), - StyleOption(_('Contact Disconnected Background'), '.gajim-roster-disconnected', StyleAttr.BACKGROUND),
View it on GitLab: https://dev.gajim.org/gajim/gajim/compare/b1decf2b142a949a4e85d9ea07521fc36c...