do not create duplicate subscriptions

This commit is contained in:
yagich committed 2025-06-02 23:11:12 +03:00
1 parent 22526c953e
commit 303e032673
1 file changed
+6 -1
+6 -1
View File
@@ -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"}