diff --git a/apps/threads.lua b/apps/threads.lua index a51cece..4ff7d6e 100644 --- a/apps/threads.lua +++ b/apps/threads.lua @@ -135,4 +135,38 @@ app:post("thread", "/:slug", function(self) return {redirect_to = self:url_for("thread", {slug = thread.slug}, {page = last_page}) .. "#latest-post"} end) +app:post("thread_lock", "/:slug/lock", function(self) + local user = util.get_logged_in_user(self) + if not user then + return {redirect_to = self:url_for("thread", {slug = self.params.slug})} + end + local thread = Threads:find({slug = self.params.slug}) + if not ((thread.user_id == user.id) or user:is_mod()) then + return {redirect_to = self:url_for("thread", {slug = self.params.slug})} + end + local target_op = util.form_bool_to_sqlite(self.params.target_op) + thread:update({ + is_locked = target_op, + }) + return {redirect_to = self:url_for("thread", {slug = self.params.slug})} +end) + +app:post("thread_sticky", "/:slug/sticky", function(self) + local user = util.get_logged_in_user(self) + if not user then + return {redirect_to = self:url_for("thread", {slug = self.params.slug})} + end + + if not user:is_mod() then + return {redirect_to = self:url_for("thread", {slug = self.params.slug})} + end + + local thread = Threads:find({slug = self.params.slug}) + local target_op = util.form_bool_to_sqlite(self.params.target_op) + thread:update({ + is_stickied = target_op, + }) + return {redirect_to = self:url_for("thread", {slug = self.params.slug})} +end) + return app diff --git a/util.lua b/util.lua index 64a9a81..e08d67c 100644 --- a/util.lua +++ b/util.lua @@ -137,12 +137,7 @@ function util.bton(b) end function util.stob(s) - if s == "true" then - return true - end - if s == "false" then - return false - end + return s == "true" end function util.form_bool_to_sqlite(s) diff --git a/views/threads/thread.etlua b/views/threads/thread.etlua index b3f06bd..8e850a4 100644 --- a/views/threads/thread.etlua +++ b/views/threads/thread.etlua @@ -1,6 +1,8 @@ <% local is_locked = ntob(thread.is_locked) + local is_stickied = ntob(thread.is_stickied) local can_post = (not is_locked and not me:is_guest()) or me:is_mod() + local can_lock = me.id == thread.user_id or me:is_mod() %> <% if infobox then %> <% render("views.common.infobox", infobox) %> @@ -8,7 +10,24 @@
<% for i, post in ipairs(posts) do %> <% render("views.threads.post", {post = post, render_sig = true, is_latest = i == #posts}) %>