changeset 3322:56ee491c0df6

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.
author Goffi <goffi@goffi.org>
date Sat, 01 Aug 2020 16:17:19 +0200
parents 8bbd2ed924e8
children 44a9438d6608
files sat/plugins/plugin_exp_list_of_interest.py
diffstat 1 files changed, 12 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/sat/plugins/plugin_exp_list_of_interest.py	Sat Aug 01 16:14:37 2020 +0200
+++ b/sat/plugins/plugin_exp_list_of_interest.py	Sat Aug 01 16:17:19 2020 +0200
@@ -21,6 +21,7 @@
 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 @@
             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 @@
             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]
         )