From 25a429fa1be86a929a151f79cd264c4d2d7cc6ac Mon Sep 17 00:00:00 2001 From: Goffi Date: Sat, 1 Aug 2020 16:17:19 +0200 Subject: [PATCH] plugin list for interest: build ID using URI or file path metadata: by using those metadata, we get the same ID for 2 interests linking to the same location. This has been done to avoid duplicated interests. --- sat/plugins/plugin_exp_list_of_interest.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/sat/plugins/plugin_exp_list_of_interest.py b/sat/plugins/plugin_exp_list_of_interest.py index d57f3faa..9dc455d4 100644 --- a/sat/plugins/plugin_exp_list_of_interest.py +++ b/sat/plugins/plugin_exp_list_of_interest.py @@ -21,6 +21,7 @@ from sat.core.i18n import _ from sat.core.constants import Const as C from sat.core.log import getLogger from sat.tools.common import data_format +from sat.tools.common import uri from wokkel import disco, iwokkel, pubsub from zope.interface import implementer from twisted.internet import defer @@ -134,7 +135,15 @@ class ListInterest(object): pubsub_elt["creator"] = C.BOOL_TRUE if element is not None: pubsub_elt.addChild(element) - item_elt = pubsub.Item(payload=interest_elt) + uri_kwargs = { + "path": service, + "node": node + } + if item_id: + uri_kwargs['id'] = item_id + interest_uri = uri.buildXMPPUri("pubsub", **uri_kwargs) + # we use URI of the interest as item id to avoid duplicates + item_elt = pubsub.Item(interest_uri, payload=interest_elt) yield self._p.publish( client, client.jid.userhostJID(), NS_LIST_INTEREST, items=[item_elt] ) @@ -182,7 +191,8 @@ class ListInterest(object): file_sharing_elt["namespace"] = namespace if path is not None: file_sharing_elt["path"] = path - item_elt = pubsub.Item(payload=interest_elt) + item_id = f"{service}_{namespace or ''}_{path or ''}" + item_elt = pubsub.Item(item_id, payload=interest_elt) await self._p.publish( client, client.jid.userhostJID(), NS_LIST_INTEREST, items=[item_elt] )