2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-02-17 17:54:43 -05:00
|
|
|
# This is used on a topic page
|
2014-05-12 03:32:49 -04:00
|
|
|
class TopicParticipantsSummary
|
|
|
|
attr_reader :topic, :options
|
|
|
|
|
|
|
|
def initialize(topic, options = {})
|
|
|
|
@topic = topic
|
|
|
|
@options = options
|
|
|
|
@user = options[:user]
|
|
|
|
end
|
|
|
|
|
|
|
|
def summary
|
|
|
|
top_participants.compact.map(&method(:new_topic_poster_for))
|
|
|
|
end
|
|
|
|
|
|
|
|
def new_topic_poster_for(user)
|
|
|
|
TopicPoster.new.tap do |topic_poster|
|
|
|
|
topic_poster.user = user
|
|
|
|
topic_poster.extras = 'latest' if is_latest_poster?(user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def is_latest_poster?(user)
|
|
|
|
topic.last_post_user_id == user.id
|
|
|
|
end
|
|
|
|
|
|
|
|
def top_participants
|
2019-01-25 09:11:49 -05:00
|
|
|
user_ids.map { |id| avatar_lookup[id] }.compact.uniq.take(4)
|
2014-05-12 03:32:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def user_ids
|
|
|
|
return [] unless @user
|
|
|
|
[topic.user_id] + topic.allowed_user_ids - [@user.id]
|
|
|
|
end
|
|
|
|
|
|
|
|
def avatar_lookup
|
|
|
|
@avatar_lookup ||= options[:avatar_lookup] || AvatarLookup.new(user_ids)
|
|
|
|
end
|
|
|
|
end
|