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.
This commit is contained in:
Goffi 2020-08-01 16:17:19 +02:00
commit 25a429fa1b

View file

@ -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]
)