plugin list of interests: normalize item ID + added get method
This commit is contained in:
parent
35920d53af
commit
6f139b80e1
2 changed files with 27 additions and 9 deletions
|
|
@ -35,7 +35,7 @@ PLUGIN_INFO = {
|
|||
C.PI_IMPORT_NAME: "INVITATION",
|
||||
C.PI_TYPE: "EXP",
|
||||
C.PI_PROTOCOLS: [],
|
||||
C.PI_DEPENDENCIES: ["XEP-0060", "XEP-0106", "XEP-0329"],
|
||||
C.PI_DEPENDENCIES: ["XEP-0060", "XEP-0329", "LIST_INTEREST"],
|
||||
C.PI_RECOMMENDATIONS: ["EMAIL_INVITATION"],
|
||||
C.PI_MAIN: "Invitation",
|
||||
C.PI_HANDLER: "yes",
|
||||
|
|
@ -163,12 +163,8 @@ class Invitation(object):
|
|||
"""
|
||||
if extra is None:
|
||||
extra = {}
|
||||
# FIXME: Q&D fix as the bare file sharing service JID will lead to user own
|
||||
# repository, which thus would not be the same for the host and the guest.
|
||||
# By specifying the user part, we for the use of the host repository.
|
||||
# A cleaner way should be implemented
|
||||
if service.user is None:
|
||||
service.user = self.host.plugins['XEP-0106'].escape(client.jid.user)
|
||||
li_plg = self.host.plugins["LIST_INTEREST"]
|
||||
li_plg.normaliseFileSharingService(client, service)
|
||||
|
||||
# FIXME: not the best place to adapt permission, but it's necessary to check them
|
||||
# for UX
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
from sat.core.i18n import _
|
||||
from sat.core.constants import Const as C
|
||||
from sat.core.xmpp import SatXMPPEntity
|
||||
from sat.core import exceptions
|
||||
from sat.core.log import getLogger
|
||||
from sat.tools.common import data_format
|
||||
from sat.tools.common import uri
|
||||
|
|
@ -37,7 +39,7 @@ PLUGIN_INFO = {
|
|||
C.PI_IMPORT_NAME: "LIST_INTEREST",
|
||||
C.PI_TYPE: "EXP",
|
||||
C.PI_PROTOCOLS: [],
|
||||
C.PI_DEPENDENCIES: ["XEP-0060", "XEP-0329"],
|
||||
C.PI_DEPENDENCIES: ["XEP-0060", "XEP-0329", "XEP-0106"],
|
||||
C.PI_RECOMMENDATIONS: [],
|
||||
C.PI_MAIN: "ListInterest",
|
||||
C.PI_HANDLER: "yes",
|
||||
|
|
@ -160,6 +162,16 @@ class ListInterest(object):
|
|||
name or None, extra
|
||||
))
|
||||
|
||||
def normaliseFileSharingService(self, client, service):
|
||||
# FIXME: Q&D fix as the bare file sharing service JID will lead to user own
|
||||
# repository, which thus would not be the same for the host and the guest.
|
||||
# By specifying the user part, we for the use of the host repository.
|
||||
# A cleaner way should be implemented
|
||||
if service.user is None:
|
||||
service.user = self.host.plugins['XEP-0106'].escape(client.jid.user)
|
||||
|
||||
def getFileSharingId(self, service, namespace, path):
|
||||
return f"{service}_{namespace or ''}_{path or ''}"
|
||||
|
||||
async def registerFileSharing(
|
||||
self, client, service, repos_type=None, namespace=None, path=None, name=None,
|
||||
|
|
@ -175,7 +187,9 @@ class ListInterest(object):
|
|||
"""
|
||||
if extra is None:
|
||||
extra = {}
|
||||
self.normaliseFileSharingService(client, service)
|
||||
await self.createNode(client)
|
||||
item_id = self.getFileSharingId(service, namespace, path)
|
||||
interest_elt = domish.Element((NS_LIST_INTEREST, "interest"))
|
||||
interest_elt["namespace"] = self.host.getNamespace("fis")
|
||||
if name is not None:
|
||||
|
|
@ -183,6 +197,7 @@ class ListInterest(object):
|
|||
thumb_url = extra.get('thumb_url')
|
||||
if thumb_url:
|
||||
interest_elt['thumb_url'] = thumb_url
|
||||
|
||||
file_sharing_elt = interest_elt.addElement("file_sharing")
|
||||
file_sharing_elt["service"] = service.full()
|
||||
if repos_type is not None:
|
||||
|
|
@ -191,7 +206,6 @@ class ListInterest(object):
|
|||
file_sharing_elt["namespace"] = namespace
|
||||
if path is not None:
|
||||
file_sharing_elt["path"] = path
|
||||
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]
|
||||
|
|
@ -285,6 +299,14 @@ class ListInterest(object):
|
|||
d.addCallback(lambda __: None)
|
||||
return d
|
||||
|
||||
async def get(self, client: SatXMPPEntity, item_id: str) -> dict:
|
||||
"""Retrieve a specific interest in profile's list"""
|
||||
items_data = await self._p.getItems(client, None, NS_LIST_INTEREST, item_ids=[item_id])
|
||||
try:
|
||||
return self._listInterestsSerialise(items_data)[0]
|
||||
except IndexError:
|
||||
raise exceptions.NotFound
|
||||
|
||||
|
||||
@implementer(iwokkel.IDisco)
|
||||
class ListInterestHandler(XMPPHandler):
|
||||
|
|
|
|||
Loading…
Reference in a new issue