changeset 6a285fa16cda in /home/hg/repos/gajim
branches: gtk3 details:http://hg.gajim.org/gajim?cmd=changeset;node=6a285fa16cda description: handle gc outgoing messages with events.
diffstat:
src/common/connection.py | 40 ++++++++++++++++++++++++++++++++ src/common/connection_handlers_events.py | 19 +++++++++++++++ src/groupchat_control.py | 8 ++++-- src/remote_control.py | 6 ++++- 4 files changed, 69 insertions(+), 4 deletions(-)
diffs (141 lines):
diff -r 4397917aa0d6 -r 6a285fa16cda src/common/connection.py --- a/src/common/connection.py Thu Jul 18 21:14:39 2013 +0200 +++ b/src/common/connection.py Fri Jul 19 13:52:37 2013 +0400 @@ -757,6 +757,8 @@ self._nec_agent_info_received) gajim.ged.register_event_handler('message-outgoing', ged.OUT_CORE, self._nec_message_outgoing) + gajim.ged.register_event_handler('gc-message-outgoing', ged.OUT_CORE, + self._nec_gc_message_outgoing) # END __init__
def cleanup(self): @@ -769,6 +771,8 @@ self._nec_agent_info_received) gajim.ged.remove_event_handler('message-outgoing', ged.OUT_CORE, self._nec_message_outgoing) + gajim.ged.remove_event_handler('message-outgoing', ged.OUT_CORE, + self._nec_gc_message_outgoing)
def get_config_values_or_default(self): if gajim.config.get_per('accounts', self.name, 'keep_alives_enabled'): @@ -2600,6 +2604,42 @@ if callback: callback(msg_iq, msg)
+ def _nec_gc_message_outgoing(self, obj): + if obj.account != self.name: + return + if not gajim.account_is_connected(self.name): + return + + if obj.correction_msg: + id_ = obj.correction_msg.getID() + if obj.correction_msg.getTag('replace'): + obj.correction_msg.delChild('replace') + obj.correction_msg.setTag('replace', attrs={'id': id_}, + namespace=nbxmpp.NS_CORRECT) + id2 = self.connection.getAnID() + obj.correction_msg.setID(id2) + obj.correction_msg.setBody(obj.message) + if obj.xhtml: + obj.correction_msg.setXHTML(xhtml) + self.connection.send(obj.correction_msg) + gajim.nec.push_incoming_event(MessageSentEvent(None, conn=self, + jid=obj.jid, message=obj.message, keyID=None, chatstate=None)) + if obj.callback: + obj.callback(obj.correction_msg, obj.message) + return + if not obj.xhtml and gajim.config.get('rst_formatting_outgoing_messages'): + from common.rst_xhtml_generator import create_xhtml + obj.xhtml = create_xhtml(obj.message) + msg_iq = nbxmpp.Message(obj.jid, obj.message, typ='groupchat', + xhtml=obj.xhtml) + if obj.label is not None: + msg_iq.addChild(node=label) + self.connection.send(msg_iq) + gajim.nec.push_incoming_event(MessageSentEvent(None, conn=self, + jid=obj.jid, message=obj.message, keyID=None, chatstate=None)) + if obj.callback: + obj.callback(msg_iq, obj.message) + def send_gc_subject(self, jid, subject): if not gajim.account_is_connected(self.name): return diff -r 4397917aa0d6 -r 6a285fa16cda src/common/connection_handlers_events.py --- a/src/common/connection_handlers_events.py Thu Jul 18 21:14:39 2013 +0200 +++ b/src/common/connection_handlers_events.py Fri Jul 19 13:52:37 2013 +0400 @@ -2462,6 +2462,25 @@ def generate(self): return True
+ +class GcMessageOutgoingEvent(nec.NetworkOutgoingEvent): + name = 'gc-message-outgoing' + base_network_events = [] + + def init(self): + self.message = '' + self.xhtml = None + self.label = None + self.callback = None + self.callback_args = [] + self.is_loggable = True + self.control = None + self.correction_msg = None + + def generate(self): + return True + + class ClientCertPassphraseEvent(nec.NetworkIncomingEvent): name = 'client-cert-passphrase' base_network_events = [] diff -r 4397917aa0d6 -r 6a285fa16cda src/groupchat_control.py --- a/src/groupchat_control.py Thu Jul 18 21:14:39 2013 +0200 +++ b/src/groupchat_control.py Fri Jul 19 13:52:37 2013 +0400 @@ -56,6 +56,7 @@
from command_system.implementation.hosts import PrivateChatCommands from command_system.implementation.hosts import GroupChatCommands +from common.connection_handlers_events import GcMessageOutgoingEvent
import logging log = logging.getLogger('gajim.groupchat_control') @@ -1933,9 +1934,10 @@ else: correction_msg = None # Send the message - gajim.connections[self.account].send_gc_message(self.room_jid, - message, xhtml=xhtml, label=label, - correction_msg=correction_msg, callback=_cb) + gajim.nec.push_outgoing_event(GcMessageOutgoingEvent(None, + account=self.account, jid=self.room_jid, message=message, + xhtml=xhtml, label=label, callback=_cb, + callback_args=[_cb] + [message], correction_msg=correction_msg)) self.msg_textview.get_buffer().set_text('') self.msg_textview.grab_focus()
diff -r 4397917aa0d6 -r 6a285fa16cda src/remote_control.py --- a/src/remote_control.py Thu Jul 18 21:14:39 2013 +0200 +++ b/src/remote_control.py Fri Jul 19 13:52:37 2013 +0400 @@ -37,7 +37,9 @@ from time import time from dialogs import AddNewContactWindow, NewChatDialog, JoinGroupchatWindow from common import ged -from common.connection_handlers_events import MessageOutgoingEvent +from common.connection_handlers_events import MessageOutgoingEvent, + GcMessageOutgoingEvent +
from common import dbus_support if dbus_support.supported: @@ -478,6 +480,8 @@ if connected_account: connection = gajim.connections[connected_account] connection.send_gc_message(room_jid, message) + gajim.nec.push_outgoing_event(GcMessageOutgoingEvent(None, + account=connected_account, jid=room_jid, message=message)) return DBUS_BOOLEAN(True) return DBUS_BOOLEAN(False)