2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-06-20 17:20:08 -04:00
|
|
|
module PostStreamSerializerMixin
|
|
|
|
def self.included(klass)
|
|
|
|
klass.attributes :post_stream
|
2016-05-17 13:03:08 -04:00
|
|
|
klass.attributes :timeline_lookup
|
2024-10-17 10:16:16 -04:00
|
|
|
klass.attributes :user_badges
|
2013-06-20 17:20:08 -04:00
|
|
|
end
|
|
|
|
|
2018-06-21 22:38:31 -04:00
|
|
|
def include_stream?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2018-07-02 01:58:02 -04:00
|
|
|
def include_gaps?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2024-10-17 10:16:16 -04:00
|
|
|
def include_user_badges?
|
|
|
|
badges_to_include.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_badges
|
|
|
|
object.user_badges(badges_to_include)
|
|
|
|
end
|
|
|
|
|
|
|
|
def badges_to_include
|
|
|
|
@badges_to_include ||= theme_modifier_helper.serialize_post_user_badges
|
|
|
|
end
|
|
|
|
|
2013-06-20 17:20:08 -04:00
|
|
|
def post_stream
|
2018-06-21 22:38:31 -04:00
|
|
|
result = { posts: posts }
|
2018-07-11 03:41:26 -04:00
|
|
|
|
|
|
|
if include_stream?
|
|
|
|
if !object.is_mega_topic?
|
|
|
|
result[:stream] = object.filtered_post_ids
|
|
|
|
else
|
|
|
|
result[:isMegaTopic] = true
|
|
|
|
result[:lastId] = object.last_post_id
|
|
|
|
end
|
|
|
|
end
|
2018-07-02 01:58:02 -04:00
|
|
|
|
|
|
|
if include_gaps? && object.gaps.present?
|
|
|
|
result[:gaps] = GapSerializer.new(object.gaps, root: false)
|
|
|
|
end
|
|
|
|
|
2013-12-04 15:56:09 -05:00
|
|
|
result
|
2013-06-20 17:20:08 -04:00
|
|
|
end
|
|
|
|
|
2018-07-11 03:41:26 -04:00
|
|
|
def include_timeline_lookup?
|
|
|
|
!object.is_mega_topic?
|
|
|
|
end
|
|
|
|
|
2016-05-17 13:03:08 -04:00
|
|
|
def timeline_lookup
|
|
|
|
TimelineLookup.build(object.filtered_post_stream)
|
|
|
|
end
|
|
|
|
|
2013-06-20 17:20:08 -04:00
|
|
|
def posts
|
2017-08-11 22:18:04 -04:00
|
|
|
@posts ||=
|
|
|
|
begin
|
|
|
|
(object.posts || []).map do |post|
|
|
|
|
post.topic = object.topic
|
|
|
|
|
|
|
|
serializer = PostSerializer.new(post, scope: scope, root: false)
|
|
|
|
serializer.add_raw = true if @options[:include_raw]
|
|
|
|
serializer.topic_view = object
|
|
|
|
|
|
|
|
serializer.as_json
|
2023-01-09 07:20:10 -05:00
|
|
|
end
|
2013-06-20 17:20:08 -04:00
|
|
|
end
|
|
|
|
end
|
2024-10-17 10:16:16 -04:00
|
|
|
|
|
|
|
def theme_modifier_helper
|
|
|
|
@theme_modifier_helper ||= ThemeModifierHelper.new(request: scope.request)
|
|
|
|
end
|
2013-06-20 17:20:08 -04:00
|
|
|
end
|