2013-12-04 15:56:09 -05:00
|
|
|
require_dependency 'gap_serializer'
|
|
|
|
require_dependency 'post_serializer'
|
2016-05-17 13:03:08 -04:00
|
|
|
require_dependency 'timeline_lookup'
|
2013-12-04 15:56:09 -05:00
|
|
|
|
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
|
2013-06-20 17:20:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def post_stream
|
2013-12-04 15:56:09 -05:00
|
|
|
result = { posts: posts, stream: object.filtered_post_ids }
|
|
|
|
result[:gaps] = GapSerializer.new(object.gaps, root: false) if object.gaps.present?
|
|
|
|
result
|
2013-06-20 17:20:08 -04:00
|
|
|
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
|
2013-06-20 17:20:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|