Mercurial > libervia-backend
diff frontends/src/quick_frontend/quick_app.py @ 1347:ba41a81d14c2 frontends_multi_profiles
frontends (QuickApp), tools (TriggerManager): frontends can also use triggers + add those for sending and receiving a message
author | souliane <souliane@mailoo.org> |
---|---|
date | Tue, 03 Mar 2015 15:05:10 +0100 |
parents | b26dd78de495 |
children | a39d2db03c80 |
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_app.py Tue Mar 03 06:00:23 2015 +0100 +++ b/frontends/src/quick_frontend/quick_app.py Tue Mar 03 15:05:10 2015 +0100 @@ -22,6 +22,7 @@ from sat.core.i18n import _ from sat.core import exceptions +from sat.tools.misc import TriggerManager from sat_frontends.tools import jid from sat_frontends.quick_frontend.quick_widgets import QuickWidgetsManager @@ -219,6 +220,9 @@ # listeners self._listeners = {} # key: listener type ("avatar", "selected", etc), value: list of callbacks + # triggers + self.trigger = TriggerManager() # trigger are used to change the default behaviour + ## bridge ## try: self.bridge = create_bridge() @@ -453,6 +457,10 @@ def newMessageHandler(self, from_jid_s, msg, type_, to_jid_s, extra, profile): from_jid = jid.JID(from_jid_s) to_jid = jid.JID(to_jid_s) + + if not self.trigger.point("newMessageTrigger", from_jid, msg, type_, to_jid, extra, profile=profile): + return + from_me = from_jid.bare == self.profiles[profile].whoami.bare target = to_jid if from_me else from_jid @@ -486,7 +494,11 @@ callback = lambda dummy=None: None # FIXME: optional argument is here because pyjamas doesn't support callback without arg with json proxy if errback is None: errback = lambda failure: self.showDialog(failure.fullname, failure.message, "error") - self.bridge.sendMessage(to_jid, message, subject, mess_type, extra, profile_key, callback=callback, errback=errback) + + if not self.trigger.point("sendMessageTrigger", to_jid, message, subject, mess_type, extra, callback, errback, profile_key=profile_key): + return + + self.bridge.sendMessage(unicode(to_jid), message, subject, mess_type, extra, profile_key, callback=callback, errback=errback) def newAlertHandler(self, msg, title, alert_type, profile): assert alert_type in ['INFO', 'ERROR']