Class: TopicViewSerializer
Constant Summary
TopicTagsMixin::DESCRIPTION_LIMIT
Class Method Summary
collapse
Instance Method Summary
collapse
#add_resource_preload_list, #admin?, #age_words, all_connectors, #allow_plugins?, #allow_third_party_plugins?, #anonymous_top_menu_items, #application_logo_dark_url, #application_logo_url, #authentication_data, #body_classes, #build_plugin_html, #can_sign_up?, #category_badge, #client_side_setup_data, #crawlable_meta_data, #crawler_layout?, #csp_nonce_placeholder, #current_homepage, #customization_disabled?, #dark_color_scheme?, #dark_scheme_id, #discourse_color_scheme_meta_tag, #discourse_color_scheme_stylesheets, #discourse_config_environment, #discourse_csrf_tags, #discourse_preload_color_scheme_stylesheets, #discourse_stylesheet_link_tag, #discourse_stylesheet_preload_tag, #discourse_theme_color_meta_tags, #escape_noscript, #escape_unicode, extra_body_classes, #format_topic_title, #ga_universal_json, #get_absolute_image_url, #google_tag_manager_json, #google_universal_analytics_json, #gsub_emoji_to_unicode, #guardian, #html_classes, #html_lang, #include_crawler_content?, #include_ios_native_app_banner?, #include_splash_screen?, #ios_app_argument, #ios_device?, #is_brotli_req?, #is_gzip_req?, #loading_admin?, #login_path, #manifest_url, #mobile_device?, #mobile_view?, #moderator?, #modern_mobile_device?, #normalized_safe_mode, #preload_script, #preload_script_url, #preloaded_json, #render_sitelinks_search_tag, #replace_plugin_html, #rss_creator, #rtl?, #scheme_id, #script_asset_path, #server_plugin_outlet, #shared_session_key, #short_date, #staff?, #stylesheet_manager, #text_size_class, #theme_id, #theme_js_lookup, #theme_lookup, #theme_translations_lookup, #topic_featured_link_domain, #waving_hand_url, #with_format
Methods included from GlobalPath
#cdn_path, #cdn_relative_path, #full_cdn_url, #path, #upload_cdn_path
#faq_path, #privacy_policy_url, #tos_url
#canonical_link_tag
#clear_current_user, #current_user, has_auth_cookie?, #is_api?, #is_user_api?, #log_off_user, #log_on_user, lookup_from_env, #refresh_session
#include_tags?, included, #tags, #tags_descriptions, #topic
#include_related_messages?, #include_suggested_group_name?, #include_suggested_topics?, included, #related_messages, #suggested_group_name, #suggested_topics
#badges_to_include, #include_gaps?, #include_stream?, #include_timeline_lookup?, #include_user_badges?, included, #post_stream, #posts, #theme_modifier_helper, #timeline_lookup, #user_badges
expire_cache_fragment!, fragment_cache
#include!
Class Method Details
.attributes_from_topic(*list) ⇒ Object
9
10
11
12
13
14
15
16
|
# File 'app/serializers/topic_view_serializer.rb', line 9
def self.attributes_from_topic(*list)
[list].flatten.each do |attribute|
attributes(attribute)
class_eval %{def #{attribute}
object.topic.#{attribute}
end}
end
end
|
Instance Method Details
#actions_summary ⇒ Object
179
180
181
|
# File 'app/serializers/topic_view_serializer.rb', line 179
def actions_summary
object.actions_summary
end
|
#bookmarked ⇒ Object
199
200
201
|
# File 'app/serializers/topic_view_serializer.rb', line 199
def bookmarked
object.has_bookmarks?
end
|
#chunk_size ⇒ Object
98
99
100
|
# File 'app/serializers/topic_view_serializer.rb', line 98
def chunk_size
object.chunk_size
end
|
#current_post_number ⇒ Object
143
144
145
|
# File 'app/serializers/topic_view_serializer.rb', line 143
def current_post_number
object.current_post_number
end
|
#deleted_by ⇒ Object
134
135
136
|
# File 'app/serializers/topic_view_serializer.rb', line 134
def deleted_by
BasicUserSerializer.new(object.topic.deleted_by, root: false).as_json
end
|
#destination_category_id ⇒ Object
243
244
245
|
# File 'app/serializers/topic_view_serializer.rb', line 243
def destination_category_id
object.topic.shared_draft.category_id
end
|
#details ⇒ Object
90
91
92
|
# File 'app/serializers/topic_view_serializer.rb', line 90
def details
object
end
|
#draft ⇒ Object
114
115
116
|
# File 'app/serializers/topic_view_serializer.rb', line 114
def draft
object.draft
end
|
#draft_key ⇒ Object
118
119
120
|
# File 'app/serializers/topic_view_serializer.rb', line 118
def draft_key
object.draft_key
end
|
#draft_sequence ⇒ Object
122
123
124
|
# File 'app/serializers/topic_view_serializer.rb', line 122
def draft_sequence
object.draft_sequence
end
|
#expandable_first_post ⇒ Object
191
192
193
|
# File 'app/serializers/topic_view_serializer.rb', line 191
def expandable_first_post
true
end
|
#has_deleted ⇒ Object
183
184
185
|
# File 'app/serializers/topic_view_serializer.rb', line 183
def has_deleted
object.has_deleted?
end
|
#has_topic_user? ⇒ Boolean
Also known as:
include_last_read_post_id?, include_last_read_post_number?, include_posted?
139
140
141
|
# File 'app/serializers/topic_view_serializer.rb', line 139
def has_topic_user?
object.topic_user.present?
end
|
#highest_post_number ⇒ Object
151
152
153
|
# File 'app/serializers/topic_view_serializer.rb', line 151
def highest_post_number
object.highest_post_number
end
|
#include_categories? ⇒ Boolean
313
314
315
|
# File 'app/serializers/topic_view_serializer.rb', line 313
def include_categories?
scope.can_lazy_load_categories?
end
|
#include_current_post_number? ⇒ Boolean
147
148
149
|
# File 'app/serializers/topic_view_serializer.rb', line 147
def include_current_post_number?
object.current_post_number.present?
end
|
#include_destination_category_id? ⇒ Boolean
Also known as:
include_is_shared_draft?
247
248
249
250
|
# File 'app/serializers/topic_view_serializer.rb', line 247
def include_destination_category_id?
scope.can_see_shared_draft? && SiteSetting.shared_drafts_enabled? &&
object.topic.shared_draft.present?
end
|
#include_expandable_first_post? ⇒ Boolean
195
196
197
|
# File 'app/serializers/topic_view_serializer.rb', line 195
def include_expandable_first_post?
object.topic.expandable_first_post?
end
|
#include_external_id? ⇒ Boolean
110
111
112
|
# File 'app/serializers/topic_view_serializer.rb', line 110
def include_external_id?
external_id
end
|
#include_featured_link? ⇒ Boolean
215
216
217
|
# File 'app/serializers/topic_view_serializer.rb', line 215
def include_featured_link?
SiteSetting.topic_featured_link_enabled
end
|
#include_featured_link_root_domain? ⇒ Boolean
219
220
221
|
# File 'app/serializers/topic_view_serializer.rb', line 219
def include_featured_link_root_domain?
SiteSetting.topic_featured_link_enabled && object.topic.featured_link
end
|
#include_has_deleted? ⇒ Boolean
187
188
189
|
# File 'app/serializers/topic_view_serializer.rb', line 187
def include_has_deleted?
object.guardian.can_see_deleted_posts?
end
|
#include_is_warning? ⇒ Boolean
106
107
108
|
# File 'app/serializers/topic_view_serializer.rb', line 106
def include_is_warning?
is_warning
end
|
#include_message_archived? ⇒ Boolean
126
127
128
|
# File 'app/serializers/topic_view_serializer.rb', line 126
def include_message_archived?
object.personal_message
end
|
#include_pending_posts? ⇒ Boolean
258
259
260
|
# File 'app/serializers/topic_view_serializer.rb', line 258
def include_pending_posts?
scope.authenticated? && object.queued_posts_enabled?
end
|
#include_pm_with_non_human_user? ⇒ Boolean
231
232
233
|
# File 'app/serializers/topic_view_serializer.rb', line 231
def include_pm_with_non_human_user?
object.personal_message
end
|
#include_published_page? ⇒ Boolean
291
292
293
294
|
# File 'app/serializers/topic_view_serializer.rb', line 291
def include_published_page?
SiteSetting.enable_page_publishing? && scope.is_staff? && object.published_page.present? &&
!SiteSetting.secure_uploads
end
|
#include_queued_posts_count? ⇒ Boolean
266
267
268
|
# File 'app/serializers/topic_view_serializer.rb', line 266
def include_queued_posts_count?
scope.is_staff? && object.queued_posts_enabled?
end
|
#include_requested_group_name? ⇒ Boolean
287
288
289
|
# File 'app/serializers/topic_view_serializer.rb', line 287
def include_requested_group_name?
object.personal_message && object.topic.custom_fields["requested_group_id"]
end
|
#include_unicode_title? ⇒ Boolean
223
224
225
|
# File 'app/serializers/topic_view_serializer.rb', line 223
def include_unicode_title?
object.topic.title.match?(/:[\w\-+]+:/)
end
|
#include_user_last_posted_at? ⇒ Boolean
305
306
307
|
# File 'app/serializers/topic_view_serializer.rb', line 305
def include_user_last_posted_at?
has_topic_user? && object.topic.slow_mode_seconds.to_i > 0
end
|
#include_visibility_reason_id? ⇒ Boolean
317
318
319
|
# File 'app/serializers/topic_view_serializer.rb', line 317
def include_visibility_reason_id?
object.topic.visibility_reason_id.present?
end
|
#is_shared_draft ⇒ Object
252
253
254
|
# File 'app/serializers/topic_view_serializer.rb', line 252
def is_shared_draft
include_destination_category_id?
end
|
#is_warning ⇒ Object
102
103
104
|
# File 'app/serializers/topic_view_serializer.rb', line 102
def is_warning
object.personal_message && object.topic.subtype == TopicSubtype.moderator_warning
end
|
#last_read_post_id ⇒ Object
155
156
157
158
|
# File 'app/serializers/topic_view_serializer.rb', line 155
def last_read_post_id
return nil unless last_read_post_number
object.filtered_post_id(last_read_post_number)
end
|
#last_read_post_number ⇒ Object
161
162
163
|
# File 'app/serializers/topic_view_serializer.rb', line 161
def last_read_post_number
@last_read_post_number ||= object.topic_user.last_read_post_number
end
|
#message_archived ⇒ Object
130
131
132
|
# File 'app/serializers/topic_view_serializer.rb', line 130
def message_archived
object.topic.message_archived?(scope.user)
end
|
#message_bus_last_id ⇒ Object
94
95
96
|
# File 'app/serializers/topic_view_serializer.rb', line 94
def message_bus_last_id
object.message_bus_last_id
end
|
#participant_count ⇒ Object
239
240
241
|
# File 'app/serializers/topic_view_serializer.rb', line 239
def participant_count
object.participant_count
end
|
#pinned ⇒ Object
171
172
173
|
# File 'app/serializers/topic_view_serializer.rb', line 171
def pinned
PinnedCheck.pinned?(object.topic, object.topic_user)
end
|
#pm_with_non_human_user ⇒ Object
235
236
237
|
# File 'app/serializers/topic_view_serializer.rb', line 235
def pm_with_non_human_user
object.topic.pm_with_non_human_user?
end
|
#posted ⇒ Object
166
167
168
|
# File 'app/serializers/topic_view_serializer.rb', line 166
def posted
object.topic_user.posted?
end
|
#queued_posts_count ⇒ Object
262
263
264
|
# File 'app/serializers/topic_view_serializer.rb', line 262
def queued_posts_count
object.queued_posts_count
end
|
#requested_group_name ⇒ Object
274
275
276
277
278
279
280
281
282
283
284
285
|
# File 'app/serializers/topic_view_serializer.rb', line 274
def requested_group_name
Group
.joins(:group_users)
.where(
id: object.topic.custom_fields["requested_group_id"].to_i,
group_users: {
user_id: scope.user.id,
owner: true,
},
)
.pick(:name)
end
|
#show_read_indicator ⇒ Object
270
271
272
|
# File 'app/serializers/topic_view_serializer.rb', line 270
def show_read_indicator
object.show_read_indicator?
end
|
#slow_mode_enabled_until ⇒ Object
309
310
311
|
# File 'app/serializers/topic_view_serializer.rb', line 309
def slow_mode_enabled_until
object.topic.slow_mode_topic_timer&.execute_at
end
|
#thumbnails ⇒ Object
296
297
298
299
|
# File 'app/serializers/topic_view_serializer.rb', line 296
def thumbnails
= ThemeModifierHelper.new(request: scope.request).topic_thumbnail_sizes
object.topic.thumbnail_info(enqueue_if_missing: true, extra_sizes: )
end
|
#topic_timer ⇒ Object
203
204
205
206
207
208
209
210
211
212
213
|
# File 'app/serializers/topic_view_serializer.rb', line 203
def topic_timer
topic_timer = object.topic.public_topic_timer
return nil if topic_timer.blank?
if topic_timer.publishing_to_category?
return nil if !scope.can_see_category?(Category.find_by(id: topic_timer.category_id))
end
TopicTimerSerializer.new(object.topic.public_topic_timer, root: false)
end
|
#unicode_title ⇒ Object
227
228
229
|
# File 'app/serializers/topic_view_serializer.rb', line 227
def unicode_title
Emoji.gsub_emoji_to_unicode(object.topic.title)
end
|
#unpinned ⇒ Object
175
176
177
|
# File 'app/serializers/topic_view_serializer.rb', line 175
def unpinned
PinnedCheck.unpinned?(object.topic, object.topic_user)
end
|
#user_last_posted_at ⇒ Object
301
302
303
|
# File 'app/serializers/topic_view_serializer.rb', line 301
def user_last_posted_at
object.topic_user.last_posted_at
end
|