Mercurial > libervia-backend
changeset 3598:d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 29 Jul 2021 22:51:01 +0200 (2021-07-29) |
parents | 5d108ce026d7 |
children | ab1fe6b25631 |
files | sat/plugins/plugin_xep_0277.py |
diffstat | 1 files changed, 26 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0277.py Thu Jul 29 22:51:01 2021 +0200 +++ b/sat/plugins/plugin_xep_0277.py Thu Jul 29 22:51:01 2021 +0200 @@ -55,8 +55,8 @@ NS_MICROBLOG = "urn:xmpp:microblog:0" NS_ATOM = "http://www.w3.org/2005/Atom" -NS_PUBSUB_EVENT = "{}{}".format(pubsub.NS_PUBSUB, "#event") -NS_COMMENT_PREFIX = "{}:comments/".format(NS_MICROBLOG) +NS_PUBSUB_EVENT = f"{pubsub.NS_PUBSUB}#event" +NS_COMMENT_PREFIX = f"{NS_MICROBLOG}:comments/" PLUGIN_INFO = { @@ -65,7 +65,7 @@ C.PI_TYPE: "XEP", C.PI_PROTOCOLS: ["XEP-0277"], C.PI_DEPENDENCIES: ["XEP-0163", "XEP-0060", "TEXT_SYNTAXES"], - C.PI_RECOMMENDATIONS: ["XEP-0059", "EXTRA-PEP"], + C.PI_RECOMMENDATIONS: ["XEP-0059", "EXTRA-PEP", "PUBSUB_CACHE"], C.PI_MAIN: "XEP_0277", C.PI_HANDLER: "yes", C.PI_DESCRIPTION: _("""Implementation of microblogging Protocol"""), @@ -86,6 +86,19 @@ self._p = self.host.plugins[ "XEP-0060" ] # this facilitate the access to pubsub plugin + ps_cache = self.host.plugins.get("PUBSUB_CACHE") + if ps_cache is not None: + ps_cache.registerAnalyser( + { + "name": "XEP-0277", + "node": NS_MICROBLOG, + "namespace": NS_ATOM, + "type": "blog", + "to_sync": True, + "parser": self.item2mbdata, + "match_cb": self._cacheNodeMatchCb, + } + ) self.rt_sessions = sat_defer.RTDeferredSessions() self.host.plugins["XEP-0060"].addManagedNode( NS_MICROBLOG, items_cb=self._itemsReceived @@ -180,6 +193,15 @@ def getHandler(self, client): return XEP_0277_handler() + def _cacheNodeMatchCb( + self, + client: SatXMPPEntity, + analyse: dict, + ) -> None: + """Check is analysed node is a comment and fill analyse accordingly""" + if analyse["node"].startswith(NS_COMMENT_PREFIX): + analyse["subtype"] = "comment" + def _checkFeaturesCb(self, available): return {"available": C.BOOL_TRUE} @@ -682,7 +704,7 @@ @param item_id(unicode): id of the parent item @return (unicode): comment node to use """ - return "{}{}".format(NS_COMMENT_PREFIX, item_id) + return f"{NS_COMMENT_PREFIX}{item_id}" def getCommentsService(self, client, parent_service=None): """Get prefered PubSub service to create comment node