handle message-outgoing events for zeroconf. We can now send messages in trunk. Fixes #6920
This commit is contained in:
parent
533b17b37a
commit
4bbafcf5d0
|
@ -43,6 +43,7 @@ import gobject
|
|||
|
||||
from common.connection import CommonConnection
|
||||
from common import gajim
|
||||
from common import ged
|
||||
from common.zeroconf import client_zeroconf
|
||||
from common.zeroconf import zeroconf
|
||||
from connection_handlers_zeroconf import *
|
||||
|
@ -64,6 +65,9 @@ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
|
|||
CommonConnection.__init__(self, name)
|
||||
self.is_zeroconf = True
|
||||
|
||||
gajim.ged.register_event_handler('message-outgoing', ged.OUT_CORE,
|
||||
self._nec_message_outgoing)
|
||||
|
||||
def get_config_values_or_default(self):
|
||||
"""
|
||||
Get name, host, port from config, or create zeroconf account with default
|
||||
|
@ -367,6 +371,47 @@ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
|
|||
forward_from=forward_from, form_node=form_node,
|
||||
original_message=original_message, delayed=delayed, callback=cb)
|
||||
|
||||
def _nec_message_outgoing(self, obj):
|
||||
if obj.account != self.name:
|
||||
return
|
||||
|
||||
def on_send_ok(msg_id):
|
||||
gajim.nec.push_incoming_event(MessageSentEvent(None, conn=self,
|
||||
jid=obj.jid, message=obj.message, keyID=obj.keyID))
|
||||
if obj.callback:
|
||||
obj.callback(obj.msg_id, *obj.callback_args)
|
||||
|
||||
if not obj.is_loggable:
|
||||
return
|
||||
self.log_message(obj.jid, obj.message, obj.forward_from,
|
||||
obj.session, obj.original_message, obj.subject, obj.type_)
|
||||
|
||||
def on_send_not_ok(reason):
|
||||
reason += ' ' + _('Your message could not be sent.')
|
||||
gajim.nec.push_incoming_event(MessageErrorEvent(None, conn=self,
|
||||
fjid=obj.jid, error_code=-1, error_msg=reason, msg=None,
|
||||
time_=None, session=obj.session))
|
||||
|
||||
def cb(jid, msg, keyID, forward_from, session, original_message, subject,
|
||||
type_, msg_iq, xhtml):
|
||||
ret = self.connection.send(msg_iq, msg is not None, on_ok=on_send_ok,
|
||||
on_not_ok=on_send_not_ok)
|
||||
|
||||
if ret == -1:
|
||||
# Contact Offline
|
||||
gajim.nec.push_incoming_event(MessageErrorEvent(None, conn=self,
|
||||
fjid=jid, error_code=-1, error_msg=_(
|
||||
'Contact is offline. Your message could not be sent.'),
|
||||
msg=None, time_=None, session=session))
|
||||
|
||||
self._prepare_message(obj.jid, obj.message, obj.keyID, type_=obj.type_,
|
||||
subject=obj.subject, chatstate=obj.chatstate, msg_id=obj.msg_id,
|
||||
composing_xep=obj.composing_xep, resource=obj.resource,
|
||||
user_nick=obj.user_nick, xhtml=obj.xhtml, label=obj.label,
|
||||
session=obj.session, forward_from=obj.forward_from,
|
||||
form_node=obj.form_node, original_message=obj.original_message,
|
||||
delayed=obj.delayed, callback=cb)
|
||||
|
||||
def send_stanza(self, stanza):
|
||||
# send a stanza untouched
|
||||
if not self.connection:
|
||||
|
|
Loading…
Reference in New Issue