Fix topic subscriptions

This commit is contained in:
Sophie Tauchert 2023-01-08 17:50:24 +01:00
parent cd4349d63c
commit e32b9c4b49
No known key found for this signature in database
GPG key ID: 52701DE5F5F51125

View file

@ -78,10 +78,9 @@ class NtfyBot(Plugin):
return None return None
server, topic = topic[0].split("/") server, topic = topic[0].split("/")
db_topic = await self.db.get_topic(server, topic) db_topic = await self.db.get_topic(server, topic)
is_fresh_topic = False
if not db_topic: if not db_topic:
db_topic = await self.db.create_topic(Topic(id=-1, server=server, topic=topic, last_event_id=None)) 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) sub, _ = await self.db.get_subscription(db_topic.id, evt.room_id)
if sub: if sub:
await evt.reply("This room is already subscribed to %s/%s", server, topic) 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 self.db.add_subscription(db_topic.id, evt.room_id)
await evt.reply("Subscribed this room to %s/%s", server, topic) await evt.reply("Subscribed this room to %s/%s", server, topic)
await evt.react("") await evt.react("")
if is_fresh_topic: if not existing_subscriptions:
await self.subscribe_to_topic(db_topic) await self.subscribe_to_topic(db_topic)
@ntfy.subcommand("unsubscribe", aliases=("unsub"), help="Unsubscribe this room from a ntfy topic.") @ntfy.subcommand("unsubscribe", aliases=("unsub"), help="Unsubscribe this room from a ntfy topic.")