From 303e0326735163eb02dfd70be3bd2ebefd7a4d70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Mon, 2 Jun 2025 23:11:12 +0300 Subject: [PATCH] do not create duplicate subscriptions --- apps/threads.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/threads.lua b/apps/threads.lua index 611b1b6..5f8b5e8 100644 --- a/apps/threads.lua +++ b/apps/threads.lua @@ -146,7 +146,12 @@ app:post("thread", "/:slug", function(self) end if self.params.subscribe == "on" then - Subscriptions:create({user_id = user.id, thread_id = thread.id, last_seen = os.time()}) + local subscription = Subscriptions:find({user_id = user.id, thread_id = thread.id}) + if subscription then + subscription:update({last_seen = os.time}) + else + Subscriptions:create({user_id = user.id, thread_id = thread.id, last_seen = os.time()}) + end end return {redirect_to = self:url_for("thread", {slug = thread.slug}, {page = last_page}) .. "#latest-post"}