Module: PostStreamSerializerMixin

Included in:
TopicViewPostsSerializer, TopicViewSerializer
Defined in:
app/serializers/post_stream_serializer_mixin.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



4
5
6
7
# File 'app/serializers/post_stream_serializer_mixin.rb', line 4

def self.included(klass)
  klass.attributes :post_stream
  klass.attributes :timeline_lookup
end

Instance Method Details

#include_gaps?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'app/serializers/post_stream_serializer_mixin.rb', line 13

def include_gaps?
  true
end

#include_stream?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'app/serializers/post_stream_serializer_mixin.rb', line 9

def include_stream?
  true
end

#include_timeline_lookup?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'app/serializers/post_stream_serializer_mixin.rb', line 36

def include_timeline_lookup?
  !object.is_mega_topic?
end

#post_streamObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/serializers/post_stream_serializer_mixin.rb', line 17

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[:lastId] = object.last_post_id
    end
  end

  if include_gaps? && object.gaps.present?
    result[:gaps] = GapSerializer.new(object.gaps, root: false)
  end

  result
end

#postsObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/serializers/post_stream_serializer_mixin.rb', line 44

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

#timeline_lookupObject



40
41
42
# File 'app/serializers/post_stream_serializer_mixin.rb', line 40

def timeline_lookup
  TimelineLookup.build(object.filtered_post_stream)
end