Class: ListableTopicSerializer

Inherits:
BasicTopicSerializer show all
Defined in:
app/serializers/listable_topic_serializer.rb

Instance Method Summary collapse

Methods inherited from ApplicationSerializer

expire_cache_fragment!, fragment_cache

Methods inherited from ActiveModel::Serializer

#include!

Instance Method Details

#bookmarkedObject



63
64
65
# File 'app/serializers/listable_topic_serializer.rb', line 63

def bookmarked
  object.user_data && object.user_data.bookmarked
end

#bumpedObject



71
72
73
# File 'app/serializers/listable_topic_serializer.rb', line 71

def bumped
  object.created_at < object.bumped_at
end

#excerptObject



112
113
114
# File 'app/serializers/listable_topic_serializer.rb', line 112

def excerpt
  object.excerpt
end

#has_user_dataObject Also known as: include_last_read_post_number?, include_unread?, include_new_posts?, include_unread_posts?



108
109
110
# File 'app/serializers/listable_topic_serializer.rb', line 108

def has_user_data
  !!object.user_data
end

#highest_post_numberObject



55
56
57
# File 'app/serializers/listable_topic_serializer.rb', line 55

def highest_post_number
  (scope.is_whisperer? && object.highest_staff_post_number) || object.highest_post_number
end

#image_urlObject



33
34
35
# File 'app/serializers/listable_topic_serializer.rb', line 33

def image_url
  object.image_url(enqueue_if_missing: true)
end

#include_excerpt?Boolean

Returns:

  • (Boolean)


137
138
139
140
# File 'app/serializers/listable_topic_serializer.rb', line 137

def include_excerpt?
  pinned || SiteSetting.always_include_topic_excerpts ||
    theme_modifier_helper.serialize_topic_excerpts
end

#include_is_warning?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'app/serializers/listable_topic_serializer.rb', line 87

def include_is_warning?
  is_warning
end

#include_last_poster?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'app/serializers/listable_topic_serializer.rb', line 67

def include_last_poster?
  object.include_last_poster
end

#include_notification_level?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'app/serializers/listable_topic_serializer.rb', line 99

def include_notification_level?
  object.user_data.present?
end

#include_thumbnails?Boolean

Returns:

  • (Boolean)


42
43
44
45
# File 'app/serializers/listable_topic_serializer.rb', line 42

def include_thumbnails?
  theme_modifier_helper.topic_thumbnail_sizes.present? ||
    DiscoursePluginRegistry.topic_thumbnail_sizes.present?
end

#include_unicode_title?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'app/serializers/listable_topic_serializer.rb', line 47

def include_unicode_title?
  object.title.match?(/:[\w\-+]+:/)
end

#include_unread_by_group_member?Boolean

Returns:

  • (Boolean)


158
159
160
# File 'app/serializers/listable_topic_serializer.rb', line 158

def include_unread_by_group_member?
  !!object.topic_list&.publish_read_state
end

#is_warningObject



83
84
85
# File 'app/serializers/listable_topic_serializer.rb', line 83

def is_warning
  object.subtype == TopicSubtype.moderator_warning
end

#last_read_post_numberObject



103
104
105
106
# File 'app/serializers/listable_topic_serializer.rb', line 103

def last_read_post_number
  return nil unless object.user_data
  object.user_data.last_read_post_number
end

#likedObject



59
60
61
# File 'app/serializers/listable_topic_serializer.rb', line 59

def liked
  object.user_data && object.user_data.liked
end

#new_postsObject

TODO: For backwards compatibility with themes,

Remove once Discourse 2.8 is released


127
128
129
# File 'app/serializers/listable_topic_serializer.rb', line 127

def new_posts
  unread_helper.unread_posts
end

#notification_levelObject



95
96
97
# File 'app/serializers/listable_topic_serializer.rb', line 95

def notification_level
  object.user_data.notification_level
end

#pinnedObject



142
143
144
# File 'app/serializers/listable_topic_serializer.rb', line 142

def pinned
  PinnedCheck.pinned?(object, object.user_data)
end

#seenObject



75
76
77
78
79
80
81
# File 'app/serializers/listable_topic_serializer.rb', line 75

def seen
  return true if !scope || !scope.user
  return true if object.user_data && !object.user_data.last_read_post_number.nil?
  return true if object.dismissed
  return true if object.created_at < scope.user.user_option.treat_as_new_topic_start_date
  false
end

#thumbnailsObject



37
38
39
40
# File 'app/serializers/listable_topic_serializer.rb', line 37

def thumbnails
  extra_sizes = theme_modifier_helper.topic_thumbnail_sizes
  object.thumbnail_info(enqueue_if_missing: true, extra_sizes: extra_sizes)
end

#unicode_titleObject



51
52
53
# File 'app/serializers/listable_topic_serializer.rb', line 51

def unicode_title
  Emoji.gsub_emoji_to_unicode(object.title)
end

#unpinnedObject



146
147
148
# File 'app/serializers/listable_topic_serializer.rb', line 146

def unpinned
  PinnedCheck.unpinned?(object, object.user_data)
end

#unreadObject

TODO: For backwards compatibility with themes,

Remove once Discourse 2.8 is released


120
121
122
# File 'app/serializers/listable_topic_serializer.rb', line 120

def unread
  0
end

#unread_by_group_memberObject



150
151
152
153
154
155
156
# File 'app/serializers/listable_topic_serializer.rb', line 150

def unread_by_group_member
  # object#last_read_post_number is an attribute selected from a joined table.
  # See TopicQuery#append_read_state for more information.
  return false unless object.respond_to?(:last_read_post_number)

  object.last_read_post_number < object.highest_post_number
end

#unread_postsObject



132
133
134
# File 'app/serializers/listable_topic_serializer.rb', line 132

def unread_posts
  unread_helper.unread_posts
end

#unseenObject



91
92
93
# File 'app/serializers/listable_topic_serializer.rb', line 91

def unseen
  !seen
end