From e32b9c4b4953c70a5fe5ec4e04b8769201f9e287 Mon Sep 17 00:00:00 2001 From: Sophie Tauchert Date: Sun, 8 Jan 2023 17:50:24 +0100 Subject: [PATCH] Fix topic subscriptions --- ntfy/bot.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ntfy/bot.py b/ntfy/bot.py index 22244f3..2a79c3b 100644 --- a/ntfy/bot.py +++ b/ntfy/bot.py @@ -78,10 +78,9 @@ class NtfyBot(Plugin): return None server, topic = topic[0].split("/") db_topic = await self.db.get_topic(server, topic) - is_fresh_topic = False if not db_topic: db_topic = await self.db.create_topic(Topic(id=-1, server=server, topic=topic, last_event_id=None)) - is_fresh_topic = True + existing_subscriptions = await self.db.get_subscriptions(db_topic.id) sub, _ = await self.db.get_subscription(db_topic.id, evt.room_id) if sub: await evt.reply("This room is already subscribed to %s/%s", server, topic) @@ -89,7 +88,7 @@ class NtfyBot(Plugin): await self.db.add_subscription(db_topic.id, evt.room_id) await evt.reply("Subscribed this room to %s/%s", server, topic) await evt.react("✅") - if is_fresh_topic: + if not existing_subscriptions: await self.subscribe_to_topic(db_topic) @ntfy.subcommand("unsubscribe", aliases=("unsub"), help="Unsubscribe this room from a ntfy topic.")