From 51eadc20ec02b74b74cc15e601e55ef40534d78a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Mon, 2 Jun 2025 23:12:29 +0300 Subject: [PATCH] on post create, update subscription if subscribed --- apps/threads.lua | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/apps/threads.lua b/apps/threads.lua index 5f8b5e8..1932594 100644 --- a/apps/threads.lua +++ b/apps/threads.lua @@ -145,13 +145,12 @@ app:post("thread", "/:slug", function(self) return {redirect_to = self:url_for("thread", {slug = thread.slug}, {page = last_page}) .. "#latest-post"} end - if self.params.subscribe == "on" then - 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 + local subscription = Subscriptions:find({user_id = user.id, thread_id = thread.id}) + if subscription then + subscription:update({last_seen = os.time}) + end + if self.params.subscribe == "on" and not subscription then + Subscriptions:create({user_id = user.id, thread_id = thread.id, last_seen = os.time()}) end return {redirect_to = self:url_for("thread", {slug = thread.slug}, {page = last_page}) .. "#latest-post"}