changeset 3791:c61233f51b86

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.
author Goffi <goffi@goffi.org>
date Fri, 17 Jun 2022 14:15:23 +0200
parents 24f70a29e382
children 865167c34b82
files sat/plugins/plugin_xep_0060.py
diffstat 1 files changed, 12 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0060.py	Fri Jun 17 14:15:23 2022 +0200
+++ b/sat/plugins/plugin_xep_0060.py	Fri Jun 17 14:15:23 2022 +0200
@@ -1196,13 +1196,24 @@
             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(