2013-12-04 15:56:09 -05:00
|
|
|
require_dependency 'gap_serializer'
|
|
|
|
require_dependency 'post_serializer'
|
|
|
|
|
2013-06-20 17:20:08 -04:00
|
|
|
module PostStreamSerializerMixin
|
|
|
|
|
|
|
|
def self.included(klass)
|
|
|
|
klass.attributes :post_stream
|
|
|
|
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
|
|
|
|
|
|
|
|
def posts
|
|
|
|
return @posts if @posts.present?
|
|
|
|
@posts = []
|
2013-12-04 15:56:09 -05:00
|
|
|
highest_number_in_posts = 0
|
2013-10-04 04:06:32 -04:00
|
|
|
if object.posts
|
2013-06-20 17:20:08 -04:00
|
|
|
object.posts.each_with_index do |p, idx|
|
2013-12-04 15:56:09 -05:00
|
|
|
highest_number_in_posts = p.post_number if p.post_number > highest_number_in_posts
|
2013-09-03 17:19:29 -04:00
|
|
|
ps = PostSerializer.new(p, scope: scope, root: false)
|
2014-11-01 17:30:08 -04:00
|
|
|
ps.add_raw = true if @options[:include_raw]
|
2013-09-03 17:19:29 -04:00
|
|
|
ps.topic_view = object
|
|
|
|
p.topic = object.topic
|
2013-06-20 17:20:08 -04:00
|
|
|
|
2013-09-03 17:19:29 -04:00
|
|
|
@posts << ps.as_json
|
2013-06-20 17:20:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
@posts
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|