# HG changeset patch # User Goffi # Date 1387241205 -3600 # Node ID f49945d728de2968c06a367abe382914dd30b2c4 # Parent 1def5b7edf9f8513b08784268e0dd9c7d30bc693 core,bridge: sendMessage bridge method is now async diff -r 1def5b7edf9f -r f49945d728de frontends/src/bridge/DBus.py --- a/frontends/src/bridge/DBus.py Tue Dec 17 00:56:39 2013 +0100 +++ b/frontends/src/bridge/DBus.py Tue Dec 17 01:46:45 2013 +0100 @@ -196,8 +196,8 @@ 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) diff -r 1def5b7edf9f -r f49945d728de frontends/src/primitivus/primitivus --- a/frontends/src/primitivus/primitivus Tue Dec 17 00:56:39 2013 +0100 +++ b/frontends/src/primitivus/primitivus Tue Dec 17 01:46:45 2013 +0100 @@ -107,7 +107,7 @@ 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': diff -r 1def5b7edf9f -r f49945d728de src/bridge/DBus.py --- a/src/bridge/DBus.py Tue Dec 17 00:56:39 2013 +0100 +++ b/src/bridge/DBus.py Tue Dec 17 01:46:45 2013 +0100 @@ -391,9 +391,9 @@ @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='', diff -r 1def5b7edf9f -r f49945d728de src/bridge/bridge_constructor/bridge_template.ini --- a/src/bridge/bridge_constructor/bridge_template.ini Tue Dec 17 00:56:39 2013 +0100 +++ b/src/bridge/bridge_constructor/bridge_template.ini Tue Dec 17 01:46:45 2013 +0100 @@ -342,6 +342,7 @@ [sendMessage] +async= type=method category=core sig_in=ssssa{ss}s diff -r 1def5b7edf9f -r f49945d728de src/core/sat_main.py --- a/src/core/sat_main.py Tue Dec 17 00:56:39 2013 +0100 +++ b/src/core/sat_main.py Tue Dec 17 01:46:45 2013 +0100 @@ -509,7 +509,7 @@ 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 @@ 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 @@ 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