handle gc outgoing messages with events.

This commit is contained in:
Denis Fomin 2013-07-19 13:52:37 +04:00
parent c9f22fdfba
commit 41b1a28a16
4 changed files with 69 additions and 4 deletions

View File

@ -757,6 +757,8 @@ class Connection(CommonConnection, ConnectionHandlers):
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 @@ class Connection(CommonConnection, ConnectionHandlers):
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 @@ class Connection(CommonConnection, ConnectionHandlers):
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

View File

@ -2462,6 +2462,25 @@ class MessageOutgoingEvent(nec.NetworkOutgoingEvent):
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 = []

View File

@ -56,6 +56,7 @@ from common.exceptions import GajimGeneralException
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 @@ class GroupchatControl(ChatControlBase):
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()

View File

@ -37,7 +37,9 @@ from common import helpers
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 @@ class SignalObject(dbus.service.Object):
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)