Mercurial > libervia-backend
comparison sat/plugins/plugin_xep_0277.py @ 3598:d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 29 Jul 2021 22:51:01 +0200 |
parents | d830c11eeef3 |
children | cbb988a6f507 |
comparison
equal
deleted
inserted
replaced
3597:5d108ce026d7 | 3598:d390ff50af0f |
---|---|
53 log = getLogger(__name__) | 53 log = getLogger(__name__) |
54 | 54 |
55 | 55 |
56 NS_MICROBLOG = "urn:xmpp:microblog:0" | 56 NS_MICROBLOG = "urn:xmpp:microblog:0" |
57 NS_ATOM = "http://www.w3.org/2005/Atom" | 57 NS_ATOM = "http://www.w3.org/2005/Atom" |
58 NS_PUBSUB_EVENT = "{}{}".format(pubsub.NS_PUBSUB, "#event") | 58 NS_PUBSUB_EVENT = f"{pubsub.NS_PUBSUB}#event" |
59 NS_COMMENT_PREFIX = "{}:comments/".format(NS_MICROBLOG) | 59 NS_COMMENT_PREFIX = f"{NS_MICROBLOG}:comments/" |
60 | 60 |
61 | 61 |
62 PLUGIN_INFO = { | 62 PLUGIN_INFO = { |
63 C.PI_NAME: "Microblogging over XMPP Plugin", | 63 C.PI_NAME: "Microblogging over XMPP Plugin", |
64 C.PI_IMPORT_NAME: "XEP-0277", | 64 C.PI_IMPORT_NAME: "XEP-0277", |
65 C.PI_TYPE: "XEP", | 65 C.PI_TYPE: "XEP", |
66 C.PI_PROTOCOLS: ["XEP-0277"], | 66 C.PI_PROTOCOLS: ["XEP-0277"], |
67 C.PI_DEPENDENCIES: ["XEP-0163", "XEP-0060", "TEXT_SYNTAXES"], | 67 C.PI_DEPENDENCIES: ["XEP-0163", "XEP-0060", "TEXT_SYNTAXES"], |
68 C.PI_RECOMMENDATIONS: ["XEP-0059", "EXTRA-PEP"], | 68 C.PI_RECOMMENDATIONS: ["XEP-0059", "EXTRA-PEP", "PUBSUB_CACHE"], |
69 C.PI_MAIN: "XEP_0277", | 69 C.PI_MAIN: "XEP_0277", |
70 C.PI_HANDLER: "yes", | 70 C.PI_HANDLER: "yes", |
71 C.PI_DESCRIPTION: _("""Implementation of microblogging Protocol"""), | 71 C.PI_DESCRIPTION: _("""Implementation of microblogging Protocol"""), |
72 } | 72 } |
73 | 73 |
84 self.host = host | 84 self.host = host |
85 host.registerNamespace("microblog", NS_MICROBLOG) | 85 host.registerNamespace("microblog", NS_MICROBLOG) |
86 self._p = self.host.plugins[ | 86 self._p = self.host.plugins[ |
87 "XEP-0060" | 87 "XEP-0060" |
88 ] # this facilitate the access to pubsub plugin | 88 ] # this facilitate the access to pubsub plugin |
89 ps_cache = self.host.plugins.get("PUBSUB_CACHE") | |
90 if ps_cache is not None: | |
91 ps_cache.registerAnalyser( | |
92 { | |
93 "name": "XEP-0277", | |
94 "node": NS_MICROBLOG, | |
95 "namespace": NS_ATOM, | |
96 "type": "blog", | |
97 "to_sync": True, | |
98 "parser": self.item2mbdata, | |
99 "match_cb": self._cacheNodeMatchCb, | |
100 } | |
101 ) | |
89 self.rt_sessions = sat_defer.RTDeferredSessions() | 102 self.rt_sessions = sat_defer.RTDeferredSessions() |
90 self.host.plugins["XEP-0060"].addManagedNode( | 103 self.host.plugins["XEP-0060"].addManagedNode( |
91 NS_MICROBLOG, items_cb=self._itemsReceived | 104 NS_MICROBLOG, items_cb=self._itemsReceived |
92 ) | 105 ) |
93 | 106 |
177 method=self._mbGetFromManyWithComments, | 190 method=self._mbGetFromManyWithComments, |
178 ) | 191 ) |
179 | 192 |
180 def getHandler(self, client): | 193 def getHandler(self, client): |
181 return XEP_0277_handler() | 194 return XEP_0277_handler() |
195 | |
196 def _cacheNodeMatchCb( | |
197 self, | |
198 client: SatXMPPEntity, | |
199 analyse: dict, | |
200 ) -> None: | |
201 """Check is analysed node is a comment and fill analyse accordingly""" | |
202 if analyse["node"].startswith(NS_COMMENT_PREFIX): | |
203 analyse["subtype"] = "comment" | |
182 | 204 |
183 def _checkFeaturesCb(self, available): | 205 def _checkFeaturesCb(self, available): |
184 return {"available": C.BOOL_TRUE} | 206 return {"available": C.BOOL_TRUE} |
185 | 207 |
186 def _checkFeaturesEb(self, fail): | 208 def _checkFeaturesEb(self, fail): |
680 """Generate comment node | 702 """Generate comment node |
681 | 703 |
682 @param item_id(unicode): id of the parent item | 704 @param item_id(unicode): id of the parent item |
683 @return (unicode): comment node to use | 705 @return (unicode): comment node to use |
684 """ | 706 """ |
685 return "{}{}".format(NS_COMMENT_PREFIX, item_id) | 707 return f"{NS_COMMENT_PREFIX}{item_id}" |
686 | 708 |
687 def getCommentsService(self, client, parent_service=None): | 709 def getCommentsService(self, client, parent_service=None): |
688 """Get prefered PubSub service to create comment node | 710 """Get prefered PubSub service to create comment node |
689 | 711 |
690 @param pubsub_service(jid.JID, None): PubSub service of the parent item | 712 @param pubsub_service(jid.JID, None): PubSub service of the parent item |