2013-12-05 04:56:09 +08:00
|
|
|
require_dependency 'gap_serializer'
|
|
|
|
require_dependency 'post_serializer'
|
2016-05-18 01:03:08 +08:00
|
|
|
require_dependency 'timeline_lookup'
|
2013-12-05 04:56:09 +08:00
|
|
|
|
2013-06-21 05:20:08 +08:00
|
|
|
module PostStreamSerializerMixin
|
|
|
|
def self.included(klass)
|
|
|
|
klass.attributes :post_stream
|
2016-05-18 01:03:08 +08:00
|
|
|
klass.attributes :timeline_lookup
|
2013-06-21 05:20:08 +08:00
|
|
|
end
|
|
|
|
|
2018-06-22 10:38:31 +08:00
|
|
|
def include_stream?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2018-07-02 13:58:02 +08:00
|
|
|
def include_gaps?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2013-06-21 05:20:08 +08:00
|
|
|
def post_stream
|
2018-06-22 10:38:31 +08:00
|
|
|
result = { posts: posts }
|
2018-07-11 15:41:26 +08:00
|
|
|
|
|
|
|
if include_stream?
|
|
|
|
if !object.is_mega_topic?
|
|
|
|
result[:stream] = object.filtered_post_ids
|
|
|
|
else
|
|
|
|
result[:isMegaTopic] = true
|
|
|
|
result[:firstId] = object.first_post_id
|
|
|
|
result[:lastId] = object.last_post_id
|
|
|
|
end
|
|
|
|
end
|
2018-07-02 13:58:02 +08:00
|
|
|
|
|
|
|
if include_gaps? && object.gaps.present?
|
|
|
|
result[:gaps] = GapSerializer.new(object.gaps, root: false)
|
|
|
|
end
|
|
|
|
|
2013-12-05 04:56:09 +08:00
|
|
|
result
|
2013-06-21 05:20:08 +08:00
|
|
|
end
|
|
|
|
|
2018-07-11 15:41:26 +08:00
|
|
|
def include_timeline_lookup?
|
|
|
|
!object.is_mega_topic?
|
|
|
|
end
|
|
|
|
|
2016-05-18 01:03:08 +08:00
|
|
|
def timeline_lookup
|
|
|
|
TimelineLookup.build(object.filtered_post_stream)
|
|
|
|
end
|
|
|
|
|
2013-06-21 05:20:08 +08:00
|
|
|
def posts
|
2017-08-12 10:18:04 +08: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
|
2013-06-21 05:20:08 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|