# frozen_string_literal: true
class REST::StatusSerializer < ActiveModel::Serializer
attributes :id, :created_at, :in_reply_to_id, :in_reply_to_account_id,
:sensitive, :spoiler_text, :visibility, :language,
:uri, :content, :url, :reblogs_count, :favourites_count
attribute :favourited, if: :current_user?
attribute :reblogged, if: :current_user?
attribute :muted, if: :current_user?
attribute :pinned, if: :pinnable?
belongs_to :reblog, serializer: REST::StatusSerializer
belongs_to :application
belongs_to :account, serializer: REST::AccountSerializer
has_many :media_attachments, serializer: REST::MediaAttachmentSerializer
has_many :mentions
has_many :tags
has_many :emojis, serializer: REST::CustomEmojiSerializer
def id
object.id.to_s
end
def in_reply_to_id
object.in_reply_to_id.to_s
def in_reply_to_account_id
object.in_reply_to_account_id.to_s
def current_user?
!current_user.nil?
def uri
OStatus::TagManager.instance.uri_for(object)
def content
Formatter.instance.format(object)
def url
TagManager.instance.url_for(object)
def favourited
if instance_options && instance_options[:relationships]
instance_options[:relationships].favourites_map[object.id] || false
else
current_user.account.favourited?(object)
def reblogged
instance_options[:relationships].reblogs_map[object.id] || false
current_user.account.reblogged?(object)
def muted
instance_options[:relationships].mutes_map[object.conversation_id] || false
current_user.account.muting_conversation?(object.conversation)
def pinned
instance_options[:relationships].pins_map[object.id] || false
current_user.account.pinned?(object)
def pinnable?
current_user? &&
current_user.account_id == object.account_id &&
!object.reblog? &&
%w(public unlisted).include?(object.visibility)
class ApplicationSerializer < ActiveModel::Serializer
attributes :name, :website
class MentionSerializer < ActiveModel::Serializer
attributes :id, :username, :url, :acct
object.account_id.to_s
def username
object.account_username
TagManager.instance.url_for(object.account)
def acct
object.account_acct
class TagSerializer < ActiveModel::Serializer
include RoutingHelper
attributes :name, :url
tag_url(object)