Catch decrypted-message-received event in ChatControl
It makes more sense to catch the event with ChatControl than with the RosterWindow. RosterWindow is only used now if no ChatControl is open.
This commit is contained in:
parent
8a4264c94e
commit
4caa4971b2
|
@ -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()
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue