Commit 4481b635 authored by Dicson's avatar Dicson

handle gc outgoing messages with events.

parent a0f7501f
......@@ -757,6 +757,8 @@ def __init__(self, name):
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 @@ def cleanup(self):
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 @@ def send_gc_message(self, jid, msg, xhtml=None, label=None,
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
......
......@@ -2444,6 +2444,25 @@ def init(self):
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 = []
......
......@@ -54,6 +54,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')
......@@ -1923,9 +1924,10 @@ def _cb(msg, msg_txt):
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()
......
......@@ -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 @@ def send_groupchat_message(self, room_jid, message, account):
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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment