# frozen_string_literal: true
class ActivityPub::NoteSerializer < ActiveModel::Serializer
attributes :id, :type, :summary, :content,
:in_reply_to, :published, :url,
:attributed_to, :to, :cc, :sensitive
has_many :media_attachments, key: :attachment
has_many :virtual_tags, key: :tag
attribute :atom_uri, key: '_:atomUri', if: :local?
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?
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
::TagManager.instance.uri_for(object)
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}"