diff src/plugins/plugin_xep_0033.py @ 1052:e88bff4c8b77

core (XMPP): sendMessage refactoring: - better separation of message sending actions - use of more generic exceptions to hook the behaviour (SkipHistory and CancelError) - use of raise instead of return - use of failure.trap
author Goffi <goffi@goffi.org>
date Sat, 07 Jun 2014 16:35:29 +0200
parents c37a24922f27
children 3e234902177a
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0033.py	Tue Jun 03 17:10:12 2014 +0200
+++ b/src/plugins/plugin_xep_0033.py	Sat Jun 07 16:35:29 2014 +0200
@@ -20,10 +20,11 @@
 from sat.core.i18n import _
 from sat.core.log import getLogger
 log = getLogger(__name__)
+from sat.core import exceptions
 from wokkel import disco, iwokkel
 from zope.interface import implements
 from twisted.words.protocols.jabber.jid import JID
-from twisted.python.failure import Failure
+from twisted.python import failure
 import copy
 try:
     from twisted.words.protocols.xmlstream import XMPPHandler
@@ -32,7 +33,6 @@
 from twisted.words.xish import domish
 from twisted.internet import defer
 
-from sat.core.sat_main import MessageSentAndStored, AbortSendMessage
 from sat.tools.misc import TriggerManager
 from time import time
 
@@ -84,7 +84,8 @@
 
             def discoCallback(entities):
                 if not entities:
-                    return Failure(AbortSendMessage(_("XEP-0033 is being used but the server doesn't support it!")))
+                    log.warning(_("XEP-0033 is being used but the server doesn't support it!"))
+                    raise failure.Failure(exceptions.CancelError())
                 if mess_data["to"] not in entities:
                     expected = _(' or ').join([entity.userhost() for entity in entities])
                     log.warning(_("Stanzas using XEP-0033 should be addressed to %(expected)s, not %(current)s!") % {'expected': expected, 'current': mess_data["to"]})
@@ -96,7 +97,8 @@
                     element.addChild(domish.Element((None, 'address'), None, {'type': type_, 'jid': jid_}))
                 # when the prosody plugin is completed, we can immediately return mess_data from here
                 self.sendAndStoreMessage(mess_data, entries, profile)
-                return Failure(MessageSentAndStored("XEP-0033 took over", mess_data))
+                log.debug("XEP-0033 took over")
+                raise failure.Failure(exceptions.CancelError())
             d = self.host.findFeaturesSet([NS_ADDRESS], profile_key=profile)
             d.addCallbacks(discoCallback, lambda dummy: discoCallback(None))
             return d