[Comments] Simplify hidden method

Instead of having the cognitive load of checking if this is indeed the inverse of `visible`, just wrap it all in sql not
I'd love to have rails take care of this but haven't found something for that
This commit is contained in:
Earlopain 2024-01-22 19:20:40 +01:00
parent c4bd8e961f
commit 9ec5ab3e1d
No known key found for this signature in database
GPG Key ID: 48860312319ADF61

View File

@ -36,9 +36,9 @@ class Comment < ApplicationRecord
def hidden(user)
if user.is_moderator?
where("score < ? and is_sticky = false", user.comment_threshold)
where("not(score >= ? or is_sticky = true)", user.comment_threshold)
else
where("(score < ? and is_sticky = false) or (is_hidden = true and creator_id != ?)", user.comment_threshold, user.id)
where("not((score >= ? or is_sticky = true) and (is_hidden = false or creator_id = ?))", user.comment_threshold, user.id)
end
end