Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0071.py @ 2144:1d3f73e065e1
core, jp: component handling + client handling refactoring:
- SàT can now handle components
- plugin have now a "modes" key in PLUGIN_INFO where they declare if they can be used with clients and or components. They default to be client only.
- components are really similar to clients, but with some changes in behaviour:
* component has "entry point", which is a special plugin with a componentStart method, which is called just after component is connected
* trigger end with a different suffixes (e.g. profileConnected vs profileConnectedComponent), so a plugin which manage both clients and components can have different workflow
* for clients, only triggers of plugins handling client mode are launched
* for components, only triggers of plugins needed in dependencies are launched. They all must handle component mode.
* component have a sendHistory attribute (False by default) which can be set to True to allow saving sent messages into history
* for convenience, "client" is still used in method even if it can now be a component
* a new "component" boolean attribute tells if we have a component or a client
* components have to add themselve Message protocol
* roster and presence protocols are not added for components
* component default port is 5347 (which is Prosody's default port)
- asyncCreateProfile has been renamed for profileCreate, both to follow new naming convention and to prepare the transition to fully asynchronous bridge
- createProfile has a new "component" attribute. When used to create a component, it must be set to a component entry point
- jp: added --component argument to profile/create
- disconnect bridge method is now asynchronous, this way frontends can know when disconnection is finished
- new PI_* constants for PLUGIN_INFO values (not used everywhere yet)
- client/component connection workflow has been moved to their classes instead of being a host methods
- host.messageSend is now client.sendMessage, and former client.sendMessage is now client.sendMessageData.
- identities are now handled in client.identities list, so it can be updated dynamically by plugins (in the future, frontends should be able to update them too through bridge)
- profileConnecting* profileConnected* profileDisconnected* and getHandler now all use client instead of profile
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 12 Feb 2017 17:55:43 +0100 |
parents | 2d633b3c923d |
children | 33c8c4973743 |
comparison
equal
deleted
inserted
replaced
2143:c3cac21157d4 | 2144:1d3f73e065e1 |
---|---|
79 log.info(_("XHTML-IM plugin initialization")) | 79 log.info(_("XHTML-IM plugin initialization")) |
80 self.host = host | 80 self.host = host |
81 self._s = self.host.plugins["TEXT-SYNTAXES"] | 81 self._s = self.host.plugins["TEXT-SYNTAXES"] |
82 self._s.addSyntax(self.SYNTAX_XHTML_IM, lambda xhtml: xhtml, self.XHTML2XHTML_IM, [self._s.OPT_HIDDEN]) | 82 self._s.addSyntax(self.SYNTAX_XHTML_IM, lambda xhtml: xhtml, self.XHTML2XHTML_IM, [self._s.OPT_HIDDEN]) |
83 host.trigger.add("MessageReceived", self.messageReceivedTrigger) | 83 host.trigger.add("MessageReceived", self.messageReceivedTrigger) |
84 host.trigger.add("messageSend", self.messageSendTrigger) | 84 host.trigger.add("sendMessage", self.sendMessageTrigger) |
85 | 85 |
86 def getHandler(self, profile): | 86 def getHandler(self, client): |
87 return XEP_0071_handler(self) | 87 return XEP_0071_handler(self) |
88 | 88 |
89 def _messagePostTreat(self, data, message_elt, body_elts, client): | 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 |
127 if not (lang or '') in data['message']: | 127 if not (lang or '') in data['message']: |
128 d = self._s.convert(markup, syntax, self._s.SYNTAX_TEXT) | 128 d = self._s.convert(markup, syntax, self._s.SYNTAX_TEXT) |
129 d.addCallback(self._fill_body_text, data, lang) | 129 d.addCallback(self._fill_body_text, data, lang) |
130 defers.append(d) | 130 defers.append(d) |
131 | 131 |
132 def _messageSendAddRich(self, data, client): | 132 def _sendMessageAddRich(self, data, client): |
133 """ Construct XHTML-IM node and add it XML element | 133 """ Construct XHTML-IM node and add it XML element |
134 | 134 |
135 @param data: message data as sended by messageSend callback | 135 @param data: message data as sended by sendMessage callback |
136 """ | 136 """ |
137 # at this point, either ['extra']['rich'] or ['extra']['xhtml'] exists | 137 # at this point, either ['extra']['rich'] or ['extra']['xhtml'] exists |
138 # but both can't exist at the same time | 138 # but both can't exist at the same time |
139 message_elt = data['xml'] | 139 message_elt = data['xml'] |
140 html_elt = message_elt.addElement((NS_XHTML_IM, 'html')) | 140 html_elt = message_elt.addElement((NS_XHTML_IM, 'html')) |
181 else: | 181 else: |
182 body_elts = html_elt.elements(NS_XHTML, 'body') | 182 body_elts = html_elt.elements(NS_XHTML, 'body') |
183 post_treat.addCallback(self._messagePostTreat, message, body_elts, client) | 183 post_treat.addCallback(self._messagePostTreat, message, body_elts, client) |
184 return True | 184 return True |
185 | 185 |
186 def messageSendTrigger(self, client, data, pre_xml_treatments, post_xml_treatments): | 186 def sendMessageTrigger(self, client, data, pre_xml_treatments, post_xml_treatments): |
187 """ Check presence of rich text in extra """ | 187 """ Check presence of rich text in extra """ |
188 rich = {} | 188 rich = {} |
189 xhtml = {} | 189 xhtml = {} |
190 for key, value in data['extra'].iteritems(): | 190 for key, value in data['extra'].iteritems(): |
191 if key.startswith('rich'): | 191 if key.startswith('rich'): |
197 if rich or xhtml: | 197 if rich or xhtml: |
198 if rich: | 198 if rich: |
199 data['rich'] = rich | 199 data['rich'] = rich |
200 else: | 200 else: |
201 data['xhtml'] = xhtml | 201 data['xhtml'] = xhtml |
202 post_xml_treatments.addCallback(self._messageSendAddRich, client) | 202 post_xml_treatments.addCallback(self._sendMessageAddRich, client) |
203 return True | 203 return True |
204 | 204 |
205 def _purgeStyle(self, styles_raw): | 205 def _purgeStyle(self, styles_raw): |
206 """ Remove unauthorised styles according to the XEP-0071 | 206 """ Remove unauthorised styles according to the XEP-0071 |
207 @param styles_raw: raw styles (value of the style attribute) | 207 @param styles_raw: raw styles (value of the style attribute) |