diff --git a/gajim/chat_control.py b/gajim/chat_control.py index d0bb5bfda..b27e59630 100644 --- a/gajim/chat_control.py +++ b/gajim/chat_control.py @@ -242,6 +242,9 @@ class ChatControl(ChatControlBase): app.ged.register_event_handler( 'mam-decrypted-message-received', ged.GUI1, self._nec_mam_decrypted_message_received) + app.ged.register_event_handler( + 'decrypted-message-received', + ged.GUI1, self._nec_decrypted_message_received) # PluginSystem: adding GUI extension point for this ChatControl # instance object @@ -822,6 +825,36 @@ class ChatControl(ChatControlBase): encrypted=obj.encrypted, correct_id=obj.correct_id, msg_stanza_id=obj.message_id, additional_data=obj.additional_data) + def _nec_decrypted_message_received(self, obj): + if not obj.msgtxt: + return True + if obj.conn.name != self.account: + return + if obj.mtype != 'chat': + return + if obj.session.control != self: + 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.print_conversation(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) + if obj.msg_log_id: + pw = self.parent_win + end = self.conv_textview.autoscroll + if not pw or (pw.get_active_control() and self \ + == pw.get_active_control() and pw.is_active() and end): + app.logger.set_read_messages([obj.msg_log_id]) + def _message_sent(self, obj): if obj.conn.name != self.account: return @@ -1164,6 +1197,9 @@ class ChatControl(ChatControlBase): app.ged.remove_event_handler( 'mam-decrypted-message-received', ged.GUI1, self._nec_mam_decrypted_message_received) + app.ged.remove_event_handler( + 'decrypted-message-received', + ged.GUI1, self._nec_decrypted_message_received) self.unsubscribe_events() diff --git a/gajim/roster_window.py b/gajim/roster_window.py index 4eea5e3cc..912083543 100644 --- a/gajim/roster_window.py +++ b/gajim/roster_window.py @@ -2695,8 +2695,6 @@ class RosterWindow: self.draw_account(obj.conn.name) def _nec_decrypted_message_received(self, obj): - if not obj.msgtxt: # empty message text - return True if obj.mtype not in ('normal', 'chat'): return if obj.mtype == 'normal' and obj.popup: @@ -2706,28 +2704,8 @@ class RosterWindow: message=obj.msgtxt, resource=obj.resource, session=obj.session, form_node=obj.form_node) return - if obj.session.control and obj.mtype == 'chat': - 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_ - obj.session.control.print_conversation(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) - if obj.msg_log_id: - pw = obj.session.control.parent_win - end = obj.session.control.conv_textview.autoscroll - if not pw or (pw.get_active_control() and obj.session.control \ - == pw.get_active_control() and pw.is_active() and end): - app.logger.set_read_messages([obj.msg_log_id]) - elif obj.popup and obj.mtype == 'chat': + if obj.popup and obj.mtype == 'chat' and not obj.session.control: contact = app.contacts.get_contact(obj.conn.name, obj.jid) obj.session.control = app.interface.new_chat(contact, obj.conn.name, session=obj.session) diff --git a/gajim/session.py b/gajim/session.py index f835f816a..b2f90dbf7 100644 --- a/gajim/session.py +++ b/gajim/session.py @@ -40,7 +40,7 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession): def __init__(self, conn, jid, thread_id, type_='chat'): stanza_session.EncryptedStanzaSession.__init__(self, conn, jid, thread_id, type_='chat') - app.ged.register_event_handler('decrypted-message-received', ged.GUI1, + app.ged.register_event_handler('decrypted-message-received', ged.PREGUI, self._nec_decrypted_message_received) self.control = None