diff src/plugins/plugin_xep_0071.py @ 2110:2d633b3c923d

plugin XEP-0231: Bits of Binary first draft: The current implementation only retrieve data from Bits of Binary, it's not used yet for sending. When an XHTML-IM message is received (XEP-0071), all <img> are checked and if a cid scheme is found in src attribute the file is retrieved and the src is changed with cached file.
author Goffi <goffi@goffi.org>
date Thu, 05 Jan 2017 20:29:05 +0100
parents 3626b2813158
children 1d3f73e065e1
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0071.py	Thu Jan 05 20:23:38 2017 +0100
+++ b/src/plugins/plugin_xep_0071.py	Thu Jan 05 20:29:05 2017 +0100
@@ -86,9 +86,11 @@
     def getHandler(self, profile):
         return XEP_0071_handler(self)
 
-    def _messagePostTreat(self, data, body_elts):
+    def _messagePostTreat(self, data, message_elt, body_elts, client):
         """Callback which manage the post treatment of the message in case of XHTML-IM found
+
         @param data: data send by MessageReceived trigger through post_treat deferred
+        @param message_elt: whole <message> stanza
         @param body_elts: XHTML-IM body elements found
         @return: the data with the extra parameter updated
         """
@@ -102,9 +104,12 @@
         defers = []
         for body_elt in body_elts:
             lang = body_elt.getAttribute((C.NS_XML, 'lang'), '')
-            d = self._s.convert(body_elt.toXml(), self.SYNTAX_XHTML_IM, safe=True)
-            d.addCallback(converted, lang)
-            defers.append(d)
+            treat_d = defer.succeed(None)  # deferred used for treatments
+            if self.host.trigger.point("xhtml_post_treat", client, message_elt, body_elt, lang, treat_d):
+                continue
+            treat_d.addCallback(lambda dummy: self._s.convert(body_elt.toXml(), self.SYNTAX_XHTML_IM, safe=True))
+            treat_d.addCallback(converted, lang)
+            defers.append(treat_d)
 
         d_list = defer.DeferredList(defers)
         d_list.addCallback(lambda dummy: data)
@@ -175,7 +180,7 @@
             pass
         else:
             body_elts = html_elt.elements(NS_XHTML, 'body')
-            post_treat.addCallback(self._messagePostTreat, body_elts)
+            post_treat.addCallback(self._messagePostTreat, message, body_elts, client)
         return True
 
     def messageSendTrigger(self, client, data, pre_xml_treatments, post_xml_treatments):