From 83a6d475a98844a65abac29ca1e6bac5a3fe01e5 Mon Sep 17 00:00:00 2001 From: Goffi Date: Fri, 17 Jun 2022 14:15:23 +0200 Subject: [PATCH] plugin XEP-0060: do not raise an error when not subscribed on unsubscribe: when an error is received on unsubscribe because user was not subscribed, a warning is logged, but no exception is raised anymore, as the expected result is reached. --- sat/plugins/plugin_xep_0060.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/sat/plugins/plugin_xep_0060.py b/sat/plugins/plugin_xep_0060.py index 54679cee..7127c0ca 100644 --- a/sat/plugins/plugin_xep_0060.py +++ b/sat/plugins/plugin_xep_0060.py @@ -1196,13 +1196,24 @@ class XEP_0060(object): subscriptionIdentifier, sender ): return - await client.pubsub_client.unsubscribe( + try: + await client.pubsub_client.unsubscribe( service, nodeIdentifier, sub_jid or client.jid.userhostJID(), subscriptionIdentifier, sender, ) + except error.StanzaError as e: + try: + next(e.getElement().elements(pubsub.NS_PUBSUB_ERRORS, "not-subscribed")) + except StopIteration: + raise e + else: + log.info( + f"{sender.full() if sender else client.jid.full()} was not " + f"subscribed to node {nodeIdentifier!s} at {service.full()}" + ) @utils.ensure_deferred async def _subscriptions(