mirror of
https://github.com/discourse/discourse.git
synced 2024-12-01 01:24:14 +08:00
b5eff93a9d
start work on user_tracking_state fix can_ban? in guardian expose protected scopes on topic_query we need move guardian spec to use build as opposed to creating topics / posts / users start work on user tracking spec
42 lines
916 B
Ruby
42 lines
916 B
Ruby
# this class is used to mirror unread and new status back to end users
|
|
# in JavaScript there is a mirror class that is kept in-sync using the mssage bus
|
|
# the allows end users to always know which topics have unread posts in them
|
|
# and which topics are new
|
|
|
|
class UserTrackingState
|
|
|
|
CHANNEL = "/user-tracking"
|
|
|
|
MessageBus.client_filter(CHANNEL) do |user_id, message|
|
|
if user_id
|
|
UserTrackingState.new(User.find(user_id)).filter(message)
|
|
else
|
|
nil
|
|
end
|
|
end
|
|
|
|
def self.trigger_change(topic_id, post_number, user_id=nil)
|
|
MessageBus.publish(CHANNEL, "CHANGE", user_ids: [user_id].compact)
|
|
end
|
|
|
|
def initialize(user)
|
|
@user = user
|
|
@query = TopicQuery.new(@user)
|
|
end
|
|
|
|
def new_list
|
|
@query
|
|
.new_results(limit: false)
|
|
.select(topics: [:id, :created_at])
|
|
.map{|t| [t.id, t.created_at]}
|
|
end
|
|
|
|
def unread_list
|
|
[]
|
|
end
|
|
|
|
def filter(message)
|
|
end
|
|
|
|
end
|