diff --git a/sat/plugins/plugin_xep_0465.py b/sat/plugins/plugin_xep_0465.py index cda2b2ca..e927d02d 100644 --- a/sat/plugins/plugin_xep_0465.py +++ b/sat/plugins/plugin_xep_0465.py @@ -20,6 +20,7 @@ from typing import Optional, List, Dict, Union from twisted.words.protocols.jabber.xmlstream import XMPPHandler from twisted.words.protocols.jabber import jid +from twisted.words.protocols.jabber import error from twisted.words.xish import domish from zope.interface import implementer from wokkel import disco, iwokkel @@ -50,6 +51,10 @@ NS_PPS = "urn:xmpp:pps:0" NS_PPS_SUBSCRIPTIONS = "urn:xmpp:pps:subscriptions:0" NS_PPS_SUBSCRIBERS = "urn:xmpp:pps:subscribers:0" SUBSCRIBERS_NODE_PREFIX = f"{NS_PPS_SUBSCRIBERS}/" +NOT_IMPLEMENTED_MSG = ( + "The service at {service!s} doesn't seem to support Pubsub Public Subscriptions " + "(XEP-0465), please request support from your service administrator." +) class XEP_0465: @@ -139,9 +144,16 @@ class XEP_0465: """ if service is None: service = client.jid.userhostJID() - items, __ = await self.host.plugins["XEP-0060"].getItems( - client, service, NS_PPS_SUBSCRIPTIONS - ) + try: + items, __ = await self.host.plugins["XEP-0060"].getItems( + client, service, NS_PPS_SUBSCRIPTIONS + ) + except error.StanzaError as e: + if e.condition == "forbidden": + log.warning(NOT_IMPLEMENTED_MSG.format(service=service)) + return [] + else: + raise e ret = [] for item in items: try: @@ -204,9 +216,16 @@ class XEP_0465: subscribers_node = self.getPublicSubscribersNode(nodeIdentifier) - items, __ = await self.host.plugins["XEP-0060"].getItems( - client, service, subscribers_node - ) + try: + items, __ = await self.host.plugins["XEP-0060"].getItems( + client, service, subscribers_node + ) + except error.StanzaError as e: + if e.condition == "forbidden": + log.warning(NOT_IMPLEMENTED_MSG.format(service=service)) + return {} + else: + raise e ret = {} for item in items: try: