Cancel unnecessary subscription tasks

This commit is contained in:
Sophie Tauchert 2023-01-21 16:54:33 +01:00
parent 8e43db2533
commit 256aa8f315
No known key found for this signature in database
GPG Key ID: 52701DE5F5F51125
2 changed files with 9 additions and 0 deletions

View File

@ -111,6 +111,9 @@ class NtfyBot(Plugin):
await evt.reply("This room is not subscribed to %s/%s", server, topic)
return
await self.db.remove_subscription(db_topic.id, evt.room_id)
if not await self.db.get_subscriptions(db_topic.id):
self.tasks[db_topic.id].cancel()
await self.db.clear_topic_id(db_topic.id)
await evt.reply("Unsubscribed this room from %s/%s", server, topic)
await evt.react(WHITE_CHECK_MARK)

View File

@ -111,6 +111,12 @@ class DB:
"""
await self.db.execute(query, topic_id, event_id)
async def clear_topic_id(self, topic_id: int) -> None:
query = """
UPDATE topics SET last_event_id=NULL where id=$1
"""
await self.db.execute(query, topic_id)
async def create_topic(self, topic: Topic) -> Topic:
query = """
INSERT INTO topics (server, topic, last_event_id)