Class: ActivityPub::CommentSerializer

Inherits:
BaseSerializer
  • Object
show all
Defined in:
app/serializers/activitypub/comment_serializer.rb

Constant Summary

Constants inherited from BaseSerializer

BaseSerializer::CONTEXT

Instance Attribute Summary

Attributes inherited from BaseSerializer

#options

Instance Method Summary collapse

Methods inherited from BaseSerializer

#as_json, #initialize, #to_json

Constructor Details

This class inherits a constructor from ActivityPub::BaseSerializer

Instance Method Details

#attributed_toObject



22
23
24
25
26
# File 'app/serializers/activitypub/comment_serializer.rb', line 22

def attributed_to
  [
    { type: 'Person', id: (object..username) }
  ]
end

#dataObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/serializers/activitypub/comment_serializer.rb', line 3

def data
  {
    id: ActivityPub::TagManager.instance.uri_for(object),
    type: object.object_type.to_s.capitalize,
    published: object.created_at.iso8601,
    url: url,
    votes: object.votes_count,
    attributedTo: attributed_to,
    to: [ActivityPub::TagManager::COLLECTIONS[:public]],
    inReplyTo: in_reply_to,
    content: object.body_html,
    source: source,
  }
end

#in_reply_toObject



28
29
30
31
32
33
34
# File 'app/serializers/activitypub/comment_serializer.rb', line 28

def in_reply_to
  if object.parent_id.present?
    ActivityPub::TagManager.instance.uri_for(object.parent)
  else
    ActivityPub::TagManager.instance.uri_for(object.story)
  end
end

#sourceObject



36
37
38
39
40
41
# File 'app/serializers/activitypub/comment_serializer.rb', line 36

def source
  {
    content: object.body,
    mediaType: 'text/markdown'
  }
end

#urlObject



18
19
20
# File 'app/serializers/activitypub/comment_serializer.rb', line 18

def url
  { type: 'Link', mediaType: 'text/html', href: comment_url(object) }
end