# 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 + object.emojis
def atom_uri
return unless object.local?
OStatus::TagManager.instance.uri_for(object)
def in_reply_to_atom_uri
OStatus::TagManager.instance.uri_for(object.thread)
def conversation
return if object.conversation.nil?
if object.conversation.uri?
object.conversation.uri
OStatus::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, :name
'Document'
def name
object.description
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
"@#{object.account.acct}"
class TagSerializer < ActiveModel::Serializer
'Hashtag'
tag_url(object)
"##{object.name}"
class CustomEmojiSerializer < ActiveModel::Serializer
'Emoji'
full_asset_url(object.image.url)
":#{object.shortcode}:"