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
This commit is contained in:
parent
5f2b90e163
commit
87b3e413ee
4 changed files with 74 additions and 71 deletions
|
|
@ -19,12 +19,12 @@
|
|||
|
||||
from sat.core.i18n import _
|
||||
from sat.core.constants import Const as C
|
||||
from sat.core.sat_main import MessageSentAndStored
|
||||
from sat.core import exceptions
|
||||
from twisted.words.protocols.jabber import jid
|
||||
from twisted.internet import defer
|
||||
from twisted.python.failure import Failure
|
||||
from sat.core.log import getLogger
|
||||
log = getLogger(__name__)
|
||||
from twisted.python import failure
|
||||
|
||||
PLUGIN_INFO = {
|
||||
"name": "Text commands",
|
||||
|
|
@ -128,7 +128,8 @@ class TextCommands(object):
|
|||
if ret:
|
||||
return mess_data
|
||||
else:
|
||||
return Failure(MessageSentAndStored("text commands took over", mess_data))
|
||||
log.debug("text commands took over")
|
||||
raise failure.Failure(exceptions.CancelError())
|
||||
|
||||
try:
|
||||
mess_data["unparsed"] = msg[1 + len(command):] # part not yet parsed of the message
|
||||
|
|
@ -136,7 +137,8 @@ class TextCommands(object):
|
|||
d.addCallback(retHandling)
|
||||
except KeyError:
|
||||
self.feedBack(_("Unknown command /%s. ") % command + self.HELP_SUGGESTION, mess_data, profile)
|
||||
return Failure(MessageSentAndStored("text commands took over", mess_data))
|
||||
self.debug("text commands took over")
|
||||
raise failure.Failure(exceptions.CancelError())
|
||||
|
||||
return d or mess_data # if a command is detected, we should have a deferred, else we send the message normally
|
||||
|
||||
|
|
|
|||
|
|
@ -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 @@ except ImportError:
|
|||
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 @@ class XEP_0033(object):
|
|||
|
||||
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 @@ class XEP_0033(object):
|
|||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue