Class: TopicParticipantsSummary

Inherits:
Object
  • Object
show all
Defined in:
app/models/topic_participants_summary.rb

Overview

This is used on a topic page

Constant Summary collapse

PARTICIPANT_COUNT =

should match maxUserCount in topic list

5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(topic, options = {}) ⇒ TopicParticipantsSummary

Returns a new instance of TopicParticipantsSummary.



8
9
10
11
12
# File 'app/models/topic_participants_summary.rb', line 8

def initialize(topic, options = {})
  @topic = topic
  @options = options
  @user = options[:user]
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'app/models/topic_participants_summary.rb', line 5

def options
  @options
end

#topicObject (readonly)

Returns the value of attribute topic.



5
6
7
# File 'app/models/topic_participants_summary.rb', line 5

def topic
  @topic
end

Instance Method Details

#is_latest_poster?(user) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'app/models/topic_participants_summary.rb', line 25

def is_latest_poster?(user)
  topic.last_post_user_id == user.id
end

#new_topic_poster_for(user) ⇒ Object



18
19
20
21
22
23
# File 'app/models/topic_participants_summary.rb', line 18

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

#summaryObject



14
15
16
# File 'app/models/topic_participants_summary.rb', line 14

def summary
  top_participants.compact.map(&method(:new_topic_poster_for))
end

#top_participantsObject



29
30
31
# File 'app/models/topic_participants_summary.rb', line 29

def top_participants
  user_ids.map { |id| user_lookup[id] }.compact.uniq.take(PARTICIPANT_COUNT)
end

#user_idsObject



33
34
35
36
# File 'app/models/topic_participants_summary.rb', line 33

def user_ids
  return [] unless @user
  [topic.user_id] + topic.allowed_user_ids - [@user.id]
end

#user_lookupObject



38
39
40
# File 'app/models/topic_participants_summary.rb', line 38

def user_lookup
  @user_lookup ||= options[:user_lookup] || UserLookup.new(user_ids)
end