Mercurial > libervia-backend
comparison 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 |
comparison
equal
deleted
inserted
replaced
2109:85f3e12e984d | 2110:2d633b3c923d |
---|---|
84 host.trigger.add("messageSend", self.messageSendTrigger) | 84 host.trigger.add("messageSend", self.messageSendTrigger) |
85 | 85 |
86 def getHandler(self, profile): | 86 def getHandler(self, profile): |
87 return XEP_0071_handler(self) | 87 return XEP_0071_handler(self) |
88 | 88 |
89 def _messagePostTreat(self, data, body_elts): | 89 def _messagePostTreat(self, data, message_elt, body_elts, client): |
90 """Callback which manage the post treatment of the message in case of XHTML-IM found | 90 """Callback which manage the post treatment of the message in case of XHTML-IM found |
91 | |
91 @param data: data send by MessageReceived trigger through post_treat deferred | 92 @param data: data send by MessageReceived trigger through post_treat deferred |
93 @param message_elt: whole <message> stanza | |
92 @param body_elts: XHTML-IM body elements found | 94 @param body_elts: XHTML-IM body elements found |
93 @return: the data with the extra parameter updated | 95 @return: the data with the extra parameter updated |
94 """ | 96 """ |
95 # TODO: check if text only body is empty, then try to convert XHTML-IM to pure text and show a warning message | 97 # TODO: check if text only body is empty, then try to convert XHTML-IM to pure text and show a warning message |
96 def converted(xhtml, lang): | 98 def converted(xhtml, lang): |
100 data['extra']['xhtml'] = xhtml | 102 data['extra']['xhtml'] = xhtml |
101 | 103 |
102 defers = [] | 104 defers = [] |
103 for body_elt in body_elts: | 105 for body_elt in body_elts: |
104 lang = body_elt.getAttribute((C.NS_XML, 'lang'), '') | 106 lang = body_elt.getAttribute((C.NS_XML, 'lang'), '') |
105 d = self._s.convert(body_elt.toXml(), self.SYNTAX_XHTML_IM, safe=True) | 107 treat_d = defer.succeed(None) # deferred used for treatments |
106 d.addCallback(converted, lang) | 108 if self.host.trigger.point("xhtml_post_treat", client, message_elt, body_elt, lang, treat_d): |
107 defers.append(d) | 109 continue |
110 treat_d.addCallback(lambda dummy: self._s.convert(body_elt.toXml(), self.SYNTAX_XHTML_IM, safe=True)) | |
111 treat_d.addCallback(converted, lang) | |
112 defers.append(treat_d) | |
108 | 113 |
109 d_list = defer.DeferredList(defers) | 114 d_list = defer.DeferredList(defers) |
110 d_list.addCallback(lambda dummy: data) | 115 d_list.addCallback(lambda dummy: data) |
111 return d_list | 116 return d_list |
112 | 117 |
173 except StopIteration: | 178 except StopIteration: |
174 # No XHTML-IM | 179 # No XHTML-IM |
175 pass | 180 pass |
176 else: | 181 else: |
177 body_elts = html_elt.elements(NS_XHTML, 'body') | 182 body_elts = html_elt.elements(NS_XHTML, 'body') |
178 post_treat.addCallback(self._messagePostTreat, body_elts) | 183 post_treat.addCallback(self._messagePostTreat, message, body_elts, client) |
179 return True | 184 return True |
180 | 185 |
181 def messageSendTrigger(self, client, data, pre_xml_treatments, post_xml_treatments): | 186 def messageSendTrigger(self, client, data, pre_xml_treatments, post_xml_treatments): |
182 """ Check presence of rich text in extra """ | 187 """ Check presence of rich text in extra """ |
183 rich = {} | 188 rich = {} |