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
|
|
|
|
|
|
|
|
def post_stream
|
2013-12-05 04:56:09 +08:00
|
|
|
result = { posts: posts, stream: object.filtered_post_ids }
|
|
|
|
result[:gaps] = GapSerializer.new(object.gaps, root: false) if object.gaps.present?
|
|
|
|
result
|
2013-06-21 05:20:08 +08:00
|
|
|
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
|
|
|
|
return @posts if @posts.present?
|
|
|
|
@posts = []
|
2013-10-04 16:06:32 +08:00
|
|
|
if object.posts
|
2016-04-18 23:55:23 +08:00
|
|
|
object.posts.each do |p|
|
2013-09-04 05:19:29 +08:00
|
|
|
ps = PostSerializer.new(p, scope: scope, root: false)
|
2014-11-02 05:30:08 +08:00
|
|
|
ps.add_raw = true if @options[:include_raw]
|
2013-09-04 05:19:29 +08:00
|
|
|
ps.topic_view = object
|
|
|
|
p.topic = object.topic
|
2013-06-21 05:20:08 +08:00
|
|
|
|
2013-09-04 05:19:29 +08:00
|
|
|
@posts << ps.as_json
|
2013-06-21 05:20:08 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
@posts
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|