mirror of
https://github.com/discourse/discourse.git
synced 2026-09-05 04:40:41 -05:00
Cleaned up TopicUserSpec, introduces clearing of pinned topics
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
# Helps us determine whether a topic should be displayed as pinned or not,
|
||||
# taking into account anonymous users and users who have dismissed it
|
||||
class PinnedCheck
|
||||
|
||||
def initialize(topic, topic_user=nil)
|
||||
@topic, @topic_user = topic, topic_user
|
||||
end
|
||||
|
||||
def pinned?
|
||||
|
||||
# If the topic isn't pinned the answer is false
|
||||
return false if @topic.pinned_at.blank?
|
||||
|
||||
# If the user is anonymous or hasn't entered the topic, the value is always true
|
||||
return true if @topic_user.blank?
|
||||
|
||||
# If the user hasn't cleared the pin, it's true
|
||||
return true if @topic_user.cleared_pinned_at.blank?
|
||||
|
||||
# The final check is to see whether the cleared the pin before or after it was last pinned
|
||||
@topic_user.cleared_pinned_at < @topic.pinned_at
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user