mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 08:18:18 +08:00
427d54b2b0
Zeitwerk simplifies working with dependencies in dev and makes it easier reloading class chains. We no longer need to use Rails "require_dependency" anywhere and instead can just use standard Ruby patterns to require files. This is a far reaching change and we expect some followups here.
60 lines
1.2 KiB
Ruby
60 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module PostStreamSerializerMixin
|
|
def self.included(klass)
|
|
klass.attributes :post_stream
|
|
klass.attributes :timeline_lookup
|
|
end
|
|
|
|
def include_stream?
|
|
true
|
|
end
|
|
|
|
def include_gaps?
|
|
true
|
|
end
|
|
|
|
def post_stream
|
|
result = { posts: posts }
|
|
|
|
if include_stream?
|
|
if !object.is_mega_topic?
|
|
result[:stream] = object.filtered_post_ids
|
|
else
|
|
result[:isMegaTopic] = true
|
|
result[:firstId] = object.first_post_id
|
|
result[:lastId] = object.last_post_id
|
|
end
|
|
end
|
|
|
|
if include_gaps? && object.gaps.present?
|
|
result[:gaps] = GapSerializer.new(object.gaps, root: false)
|
|
end
|
|
|
|
result
|
|
end
|
|
|
|
def include_timeline_lookup?
|
|
!object.is_mega_topic?
|
|
end
|
|
|
|
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
|