From 9a5891bb4c326f4fde3529b03b13478f40b2b12c Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Wed, 23 Sep 2015 22:39:11 +0200 Subject: [PATCH] add new event after message stanza is built so it can be modified by plugins. Fixes #8150 --- src/common/connection.py | 15 +++++++++++++-- src/common/connection_handlers_events.py | 6 ++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/common/connection.py b/src/common/connection.py index 1e9171fb6..28bb98844 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -818,6 +818,8 @@ class Connection(CommonConnection, ConnectionHandlers): self._nec_message_outgoing) gajim.ged.register_event_handler('gc-message-outgoing', ged.OUT_CORE, self._nec_gc_message_outgoing) + gajim.ged.register_event_handler('stanza-message-outgoing', + ged.OUT_CORE, self._nec_stanza_message_outgoing) # END __init__ def cleanup(self): @@ -832,6 +834,8 @@ class Connection(CommonConnection, ConnectionHandlers): self._nec_message_outgoing) gajim.ged.remove_event_handler('gc-message-outgoing', ged.OUT_CORE, self._nec_gc_message_outgoing) + gajim.ged.remove_event_handler('stanza-message-outgoing', ged.OUT_CORE, + self._nec_stanza_message_outgoing) def get_config_values_or_default(self): if gajim.config.get_per('accounts', self.name, 'keep_alives_enabled'): @@ -2131,9 +2135,11 @@ class Connection(CommonConnection, ConnectionHandlers): subject, type_, msg_iq, xhtml): if isinstance(msg_iq, list): for iq in msg_iq: - msg_id = self.connection.send(iq, now=obj.now) + gajim.nec.push_incoming_event(StanzaMessageOutgoingEvent( + None, conn=self, msg_iq=iq, now=obj.now)) else: - msg_id = self.connection.send(msg_iq, now=obj.now) + gajim.nec.push_incoming_event(StanzaMessageOutgoingEvent(None, + conn=self, msg_iq=msg_iq, now=obj.now)) gajim.nec.push_incoming_event(MessageSentEvent(None, conn=self, jid=jid, message=msg, keyID=keyID, chatstate=obj.chatstate)) if obj.callback: @@ -2159,6 +2165,11 @@ class Connection(CommonConnection, ConnectionHandlers): delayed=obj.delayed, attention=obj.attention, correction_msg=obj.correction_msg, callback=cb) + def _nec_stanza_message_outgoing(self, obj): + if obj.conn.name != self.name: + return + obj.msg_id = self.connection.send(obj.msg_iq, now=obj.now) + def send_contacts(self, contacts, fjid, type_='message'): """ Send contacts with RosterX (Xep-0144) diff --git a/src/common/connection_handlers_events.py b/src/common/connection_handlers_events.py index 16257c982..4cd91e97e 100644 --- a/src/common/connection_handlers_events.py +++ b/src/common/connection_handlers_events.py @@ -2616,6 +2616,12 @@ class MessageOutgoingEvent(nec.NetworkOutgoingEvent): def generate(self): return True +class StanzaMessageOutgoingEvent(nec.NetworkOutgoingEvent): + name='stanza-message-outgoing' + base_network_events = [] + + def generate(self): + return True class GcMessageOutgoingEvent(nec.NetworkOutgoingEvent): name = 'gc-message-outgoing'