plugin XEP-0277: pubsub cache analyser implementation
This commit is contained in:
parent
92c0c09eb2
commit
35bfb8b8b7
1 changed files with 26 additions and 4 deletions
|
|
@ -55,8 +55,8 @@ log = getLogger(__name__)
|
|||
|
||||
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 @@ PLUGIN_INFO = {
|
|||
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 @@ class XEP_0277(object):
|
|||
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 @@ class XEP_0277(object):
|
|||
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 @@ class XEP_0277(object):
|
|||
@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
|
||||
|
|
|
|||
Loading…
Reference in a new issue