plugin lists: new listsList method to retrieve lists from personal interests

This commit is contained in:
Goffi 2021-02-19 15:53:20 +01:00
commit 60eab42b9e

View file

@ -257,6 +257,14 @@ class PubsubLists:
profile_key=profile_key),
async_=True,
)
host.bridge.addMethod(
"listsList",
".plugin",
in_sign="sss",
out_sign="s",
method=self._listsList,
async_=True,
)
host.bridge.addMethod(
"listTemplatesNamesGet",
".plugin",
@ -367,6 +375,51 @@ class PubsubLists:
client, service, node, values, schema, item_id, extra, deserialise, form_ns
)
def _listsList(self, service, node, profile):
service = jid.JID(service) if service else None
node = node or None
client = self.host.getClient(profile)
d = defer.ensureDeferred(self.listsList(client, service, node))
d.addCallback(data_format.serialise)
return d
async def listsList(
self, client, service: Optional[jid.JID], node: Optional[str]=None
) -> List[dict]:
"""Retrieve list of pubsub lists registered in personal interests
@return list: list of lists metadata
"""
items, metadata = await self.host.plugins['LIST_INTEREST'].listInterests(
client, service, node, namespace=APP_NS_TICKETS)
lists = []
for item in items:
interest_elt = item.interest
if interest_elt is None:
log.warning(f"invalid interest for {client.profile}: {item.toXml}")
continue
if interest_elt.getAttribute("namespace") != APP_NS_TICKETS:
continue
pubsub_elt = interest_elt.pubsub
list_data = {
"id": item["id"],
"name": interest_elt["name"],
"service": pubsub_elt["service"],
"node": pubsub_elt["node"],
"creator": C.bool(pubsub_elt.getAttribute("creator", C.BOOL_FALSE)),
}
try:
list_elt = next(pubsub_elt.elements(APP_NS_TICKETS, "list"))
except StopIteration:
pass
else:
list_type = list_data["type"] = list_elt["type"]
if list_type in TEMPLATES:
list_data["icon_name"] = TEMPLATES[list_type]["icon"]
lists.append(list_data)
return lists
def _getTemplatesNames(self, language, profile):
client = self.host.getClient(profile)
return data_format.serialise(self.getTemplatesNames(client, language))