Cancel unnecessary subscription tasks
This commit is contained in:
parent
8e43db2533
commit
256aa8f315
2 changed files with 9 additions and 0 deletions
|
@ -111,6 +111,9 @@ class NtfyBot(Plugin):
|
||||||
await evt.reply("This room is not subscribed to %s/%s", server, topic)
|
await evt.reply("This room is not subscribed to %s/%s", server, topic)
|
||||||
return
|
return
|
||||||
await self.db.remove_subscription(db_topic.id, evt.room_id)
|
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.reply("Unsubscribed this room from %s/%s", server, topic)
|
||||||
await evt.react(WHITE_CHECK_MARK)
|
await evt.react(WHITE_CHECK_MARK)
|
||||||
|
|
||||||
|
|
|
@ -111,6 +111,12 @@ class DB:
|
||||||
"""
|
"""
|
||||||
await self.db.execute(query, topic_id, event_id)
|
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:
|
async def create_topic(self, topic: Topic) -> Topic:
|
||||||
query = """
|
query = """
|
||||||
INSERT INTO topics (server, topic, last_event_id)
|
INSERT INTO topics (server, topic, last_event_id)
|
||||||
|
|
Loading…
Reference in a new issue