mirror of
https://github.com/discourse/discourse.git
synced 2024-12-15 11:43:40 +08:00
35 lines
865 B
Ruby
35 lines
865 B
Ruby
require_dependency 'gap_serializer'
|
|
require_dependency 'post_serializer'
|
|
|
|
module PostStreamSerializerMixin
|
|
|
|
def self.included(klass)
|
|
klass.attributes :post_stream
|
|
end
|
|
|
|
def post_stream
|
|
result = { posts: posts, stream: object.filtered_post_ids }
|
|
result[:gaps] = GapSerializer.new(object.gaps, root: false) if object.gaps.present?
|
|
result
|
|
end
|
|
|
|
def posts
|
|
return @posts if @posts.present?
|
|
@posts = []
|
|
highest_number_in_posts = 0
|
|
if object.posts
|
|
object.posts.each_with_index do |p, idx|
|
|
highest_number_in_posts = p.post_number if p.post_number > highest_number_in_posts
|
|
ps = PostSerializer.new(p, scope: scope, root: false)
|
|
ps.add_raw = true if @options[:include_raw]
|
|
ps.topic_view = object
|
|
p.topic = object.topic
|
|
|
|
@posts << ps.as_json
|
|
end
|
|
end
|
|
@posts
|
|
end
|
|
|
|
end
|