discourse/app/serializers/post_stream_serializer_mixin.rb

41 lines
929 B
Ruby
Raw Normal View History

require_dependency 'gap_serializer'
require_dependency 'post_serializer'
2016-05-18 01:03:08 +08:00
require_dependency 'timeline_lookup'
module PostStreamSerializerMixin
def self.included(klass)
klass.attributes :post_stream
2016-05-18 01:03:08 +08:00
klass.attributes :timeline_lookup
end
def include_stream?
true
end
def post_stream
result = { posts: posts }
result[:stream] = object.filtered_post_ids if include_stream?
result[:gaps] = GapSerializer.new(object.gaps, root: false) if object.gaps.present?
result
end
2016-05-18 01:03:08 +08:00
def timeline_lookup
TimelineLookup.build(object.filtered_post_stream)
end
def posts
@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
end
end
end
end