core,bridge: sendMessage bridge method is now async

This commit is contained in:
Goffi 2013-12-17 01:46:45 +01:00
commit bc776be0f2
5 changed files with 11 additions and 8 deletions

View file

@ -196,8 +196,8 @@ class DBusBridgeFrontend(BridgeFrontend):
def registerNewAccount(self, login, password, email, host, port=5222):
return unicode(self.db_core_iface.registerNewAccount(login, password, email, host, port))
def sendMessage(self, to_jid, message, subject='', mess_type="auto", extra={}, profile_key="@NONE@"):
return self.db_core_iface.sendMessage(to_jid, message, subject, mess_type, extra, profile_key)
def sendMessage(self, to_jid, message, subject='', mess_type="auto", extra={}, profile_key="@NONE@", callback=None, errback=None):
return self.db_core_iface.sendMessage(to_jid, message, subject, mess_type, extra, profile_key, reply_handler=callback, error_handler=lambda err:errback(err._dbus_error_name[len(const_ERROR_PREFIX)+1:]))
def setParam(self, name, value, category, security_limit=-1, profile_key="@DEFAULT@"):
return self.db_core_iface.setParam(name, value, category, security_limit, profile_key)

View file

@ -107,7 +107,7 @@ class EditBar(sat_widgets.ModalEdit):
editBar.get_edit_text(),
mess_type = "groupchat" if chat.type == 'group' else "chat",
profile_key=self.app.profile)
except:
except: # FIXME: bad global catch + sendMessage is now async
self.app.notify(_("Error while sending message"))
editBar.set_edit_text('')
elif self.mode == 'COMMAND':

View file

@ -391,9 +391,9 @@ class DbusObject(dbus.service.Object):
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
in_signature='ssssa{ss}s', out_signature='',
async_callbacks=None)
def sendMessage(self, to_jid, message, subject='', mess_type="auto", extra={}, profile_key="@NONE@"):
return self._callback("sendMessage", unicode(to_jid), unicode(message), unicode(subject), unicode(mess_type), extra, unicode(profile_key))
async_callbacks=('callback', 'errback'))
def sendMessage(self, to_jid, message, subject='', mess_type="auto", extra={}, profile_key="@NONE@", callback=None, errback=None):
return self._callback("sendMessage", unicode(to_jid), unicode(message), unicode(subject), unicode(mess_type), extra, unicode(profile_key), callback=callback, errback=errback)
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
in_signature='sssis', out_signature='',

View file

@ -342,6 +342,7 @@ doc_return=List of confirmation request data, same as for [askConfirmation]
[sendMessage]
async=
type=method
category=core
sig_in=ssssa{ss}s

View file

@ -509,7 +509,7 @@ class SAT(service.Service):
def _sendMessage(self, to_s, msg, subject=None, mess_type='auto', extra={}, profile_key='@NONE@'):
to_jid = jid.JID(to_s)
#XXX: we need to use the dictionary comprehension because D-Bus return its own types, and pickle can't manage them. TODO: Need to find a better way
self.sendMessage(to_jid, msg, subject, mess_type, {unicode(key): unicode(value) for key, value in extra.items()}, profile_key=profile_key)
return self.sendMessage(to_jid, msg, subject, mess_type, {unicode(key): unicode(value) for key, value in extra.items()}, profile_key=profile_key)
def sendMessage(self, to_jid, msg, subject=None, mess_type='auto', extra={}, no_trigger=False, profile_key='@NONE@'):
#FIXME: check validity of recipient
@ -550,7 +550,7 @@ class SAT(service.Service):
if not no_trigger:
if not self.trigger.point("sendMessage", mess_data, treatments, profile):
return
return defer.succeed(None)
debug(_("Sending jabber message of type [%(type)s] to %(to)s...") % {"type": mess_data["type"], "to": to_jid.full()})
mess_data['xml'] = domish.Element((None, 'message'))
@ -569,12 +569,14 @@ class SAT(service.Service):
debug(text)
elif e.check(AbortSendMessage):
warning(text)
return e
else:
error("Unmanaged exception: %s" % text)
return e
treatments.addCallbacks(self.sendAndStoreMessage, sendErrback, [False, profile])
treatments.callback(mess_data)
return treatments
def sendAndStoreMessage(self, mess_data, skip_send=False, profile=None):
"""Actually send and store the message to history, after all the treatments