Class: TopicListItemSerializer

Inherits:
ListableTopicSerializer show all
Includes:
TopicTagsMixin
Defined in:
app/serializers/topic_list_item_serializer.rb

Instance Method Summary collapse

Methods included from TopicTagsMixin

#include_tags?, included, #tags, #tags_descriptions, #topic

Methods inherited from ListableTopicSerializer

#bookmarked, #bumped, #excerpt, #has_user_data, #highest_post_number, #image_url, #include_excerpt?, #include_is_warning?, #include_last_poster?, #include_notification_level?, #include_thumbnails?, #include_unicode_title?, #include_unread_by_group_member?, #is_warning, #last_read_post_number, #liked, #new_posts, #notification_level, #pinned, #seen, #thumbnails, #unicode_title, #unpinned, #unread, #unread_by_group_member, #unread_posts, #unseen

Methods inherited from ApplicationSerializer

expire_cache_fragment!, fragment_cache

Methods inherited from ActiveModel::Serializer

#include!

Instance Method Details

#allowed_user_countObject



88
89
90
91
# File 'app/serializers/topic_list_item_serializer.rb', line 88

def allowed_user_count
  # Don't use count as it will result in a query
  object.allowed_users.length
end

#category_idObject



39
40
41
42
43
44
45
46
# File 'app/serializers/topic_list_item_serializer.rb', line 39

def category_id
  # If it's a shared draft, show the destination topic instead
  if object.includes_destination_category && object.shared_draft
    return object.shared_draft.category_id
  end

  object.category_id
end

#include_allowed_user_count?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'app/serializers/topic_list_item_serializer.rb', line 93

def include_allowed_user_count?
  object.private_message?
end

Returns:

  • (Boolean)


80
81
82
# File 'app/serializers/topic_list_item_serializer.rb', line 80

def include_featured_link?
  SiteSetting.topic_featured_link_enabled
end

Returns:

  • (Boolean)


84
85
86
# File 'app/serializers/topic_list_item_serializer.rb', line 84

def include_featured_link_root_domain?
  SiteSetting.topic_featured_link_enabled && object.featured_link.present?
end

#include_liked_post_numbers?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'app/serializers/topic_list_item_serializer.rb', line 56

def include_liked_post_numbers?
  include_post_action? :like
end

#include_op_like_count?Boolean

Returns:

  • (Boolean)


73
74
75
76
77
78
# File 'app/serializers/topic_list_item_serializer.rb', line 73

def include_op_like_count?
  # PERF: long term we probably want a cheaper way of looking stuff up
  # this is rather odd code, but we need to have op_likes loaded somehow
  # simplest optimisation is adding a cache column on topic.
  object.association(:first_post).loaded?
end

#include_participant_groups?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'app/serializers/topic_list_item_serializer.rb', line 23

def include_participant_groups?
  object.private_message?
end

#include_participants?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'app/serializers/topic_list_item_serializer.rb', line 69

def include_participants?
  object.private_message?
end

#include_post_action?(action) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
63
# File 'app/serializers/topic_list_item_serializer.rb', line 60

def include_post_action?(action)
  object.user_data && object.user_data.post_action_data &&
    object.user_data.post_action_data.key?(PostActionType.types[action])
end

#last_poster_usernameObject



35
36
37
# File 'app/serializers/topic_list_item_serializer.rb', line 35

def last_poster_username
  posters.find { |poster| poster.user.id == object.last_post_user_id }.try(:user).try(:username)
end

#liked_post_numbersObject



65
66
67
# File 'app/serializers/topic_list_item_serializer.rb', line 65

def liked_post_numbers
  object.user_data.post_action_data[PostActionType.types[:like]]
end

#op_like_countObject



31
32
33
# File 'app/serializers/topic_list_item_serializer.rb', line 31

def op_like_count
  object.first_post && object.first_post.like_count
end

#participant_groupsObject



52
53
54
# File 'app/serializers/topic_list_item_serializer.rb', line 52

def participant_groups
  object.participant_groups_summary || []
end

#participantsObject



48
49
50
# File 'app/serializers/topic_list_item_serializer.rb', line 48

def participants
  object.participants_summary || []
end

#postersObject



27
28
29
# File 'app/serializers/topic_list_item_serializer.rb', line 27

def posters
  object.posters || object.posters_summary || []
end