# frozen_string_literal: true
class ActivityPub::NoteSerializer < ActiveModel::Serializer
attributes :id, :type, :summary, :content,
:in_reply_to, :published, :url,
:attributed_to, :to, :cc, :sensitive,
:atom_uri, :in_reply_to_atom_uri,
:conversation
has_many :media_attachments, key: :attachment
has_many :virtual_tags, key: :tag
def id
ActivityPub::TagManager.instance.uri_for(object)
end
def type
'Note'
def summary
object.spoiler_text.presence
def content
Formatter.instance.format(object)
def in_reply_to
return unless object.reply? && !object.thread.nil?
if object.thread.uri.nil? || object.thread.uri.start_with?('http')
ActivityPub::TagManager.instance.uri_for(object.thread)
else
object.thread.url
def published
object.created_at.iso8601
def url
ActivityPub::TagManager.instance.url_for(object)
def attributed_to
ActivityPub::TagManager.instance.uri_for(object.account)
def to
ActivityPub::TagManager.instance.to(object)
def cc
ActivityPub::TagManager.instance.cc(object)
def virtual_tags
object.mentions + object.tags
def atom_uri
return unless object.local?
::TagManager.instance.uri_for(object)
def in_reply_to_atom_uri
::TagManager.instance.uri_for(object.thread)
def conversation
return if object.conversation.nil?
if object.conversation.uri?
object.conversation.uri
TagManager.instance.unique_tag(object.conversation.created_at, object.conversation.id, 'Conversation')
def local?
object.account.local?
class MediaAttachmentSerializer < ActiveModel::Serializer
include RoutingHelper
attributes :type, :media_type, :url
'Document'
def media_type
object.file_content_type
object.local? ? full_asset_url(object.file.url(:original, false)) : object.remote_url
class MentionSerializer < ActiveModel::Serializer
attributes :type, :href, :name
'Mention'
def href
def name
"@#{object.account.acct}"
class TagSerializer < ActiveModel::Serializer
'Hashtag'
tag_url(object)
"##{object.name}"