Mercurial > libervia-backend
diff src/plugins/plugin_xep_0085.py @ 697:0c84fb112d70
core: sendMessage triggers now use a treatments deferred;
- treaments deferred can be used by plugins to change XML elements before sending them, in a similar way as for newMessage
- sendMessageXml trigger became useless, so it as been removed in favor of the new deferred
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 13 Nov 2013 13:57:36 +0100 |
parents | 8004c7d4aba7 |
children | d731ae066158 |
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0085.py Tue Nov 12 16:56:34 2013 +0100 +++ b/src/plugins/plugin_xep_0085.py Wed Nov 13 13:57:36 2013 +0100 @@ -97,7 +97,7 @@ # triggers from core host.trigger.add("MessageReceived", self.messageReceivedTrigger) - host.trigger.add("sendMessageXml", self.sendMessageXmlTrigger) + host.trigger.add("sendMessage", self.sendMessageTrigger) host.trigger.add("paramUpdateTrigger", self.paramUpdateTrigger) # TODO: handle profile disconnection (free memory in entity data) @@ -168,25 +168,30 @@ break return True - def sendMessageXmlTrigger(self, message, mess_data, profile): + def sendMessageTrigger(self, mess_data, treatments, profile): """ Eventually add the chat state to the message and initiate the state machine when sending an "active" state. """ - to_jid = JID(message.getAttribute("to")) - if not self.__checkActivation(to_jid, forceEntityData=True, profile=profile): - return True - try: - # message with a body always mean active state - domish.generateElementsNamed(message.elements(), name="body").next() - message.addElement('active', NS_CHAT_STATES) - # launch the chat state machine (init the timer) - self.__chatStateActive(to_jid, mess_data["type"], profile) - except StopIteration: - if "chat_state" in mess_data["options"]: - state = mess_data["options"]["chat_state"] - assert(state in CHAT_STATES) - message.addElement(state, NS_CHAT_STATES) + def treatment(mess_data): + message = mess_data['xml'] + to_jid = JID(message.getAttribute("to")) + if not self.__checkActivation(to_jid, forceEntityData=True, profile=profile): + return True + try: + # message with a body always mean active state + domish.generateElementsNamed(message.elements(), name="body").next() + message.addElement('active', NS_CHAT_STATES) + # launch the chat state machine (init the timer) + self.__chatStateActive(to_jid, mess_data["type"], profile) + except StopIteration: + if "chat_state" in mess_data["options"]: + state = mess_data["options"]["chat_state"] + assert(state in CHAT_STATES) + message.addElement(state, NS_CHAT_STATES) + return mess_data + + treatments.addCallback(treatment) return True def __checkActivation(self, to_jid, forceEntityData, profile):