Mercurial > libervia-backend
diff sat/plugins/plugin_xep_0280.py @ 2816:114cdde9ff96
plugin XEP-0280: priority and "sent" fixes:
- carbon prioriy must be bigger than ones of encryption plugins, because the carbon copied messages must be unwrapped to be decrypted, this patch fixes it
- "sent" carbon elements was only stored and notified to frontends, it is now unwrapped and injected in normal traffic, this way other plugin can manage it, in particular encrypted elements can be decrypted
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 28 Feb 2019 18:57:06 +0100 |
parents | 003b8b4b56a7 |
children | ab2696e34d29 |
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0280.py Thu Feb 28 18:57:04 2019 +0100 +++ b/sat/plugins/plugin_xep_0280.py Thu Feb 28 18:57:06 2019 +0100 @@ -75,7 +75,7 @@ log.info(_("Plugin XEP_0280 initialization")) self.host = host host.memory.updateParams(self.params) - host.trigger.add("MessageReceived", self.messageReceivedTrigger, priority=1000) + host.trigger.add("MessageReceived", self.messageReceivedTrigger, priority=200000) def getHandler(self, client): return XEP_0280_handler() @@ -138,30 +138,26 @@ return forwarded_elt = next(carbons_elt.elements(C.NS_FORWARD, "forwarded")) cc_message_elt = next(forwarded_elt.elements(C.NS_CLIENT, "message")) + + # we replace the wrapping message with the CCed one + # and continue the normal behaviour if carbons_elt.name == "received": - # on receive we replace the wrapping message with the CCed one - # and continue the normal behaviour message_elt["from"] = cc_message_elt["from"] - del message_elt.children[:] - for c in cc_message_elt.children: - message_elt.addChild(c) - return True elif carbons_elt.name == "sent": - # on sent we parse the message and just add it to history - # and send it to frontends (without normal sending treatments) - mess_data = client.messageProt.parseMessage(cc_message_elt) - if not mess_data["message"] and not mess_data["subject"]: - return False - client.messageAddToHistory(mess_data) - client.messageSendToBridge(mess_data) + message_elt["to"] = cc_message_elt["to"] else: log.warning( u"invalid message carbons received:\n{xml}".format( xml=message_elt.toXml() ) ) - return False + return False + del message_elt.children[:] + for c in cc_message_elt.children: + message_elt.addChild(c) + + return True class XEP_0280_handler(XMPPHandler): implements(iwokkel.IDisco)