chuckya/app/serializers/rest/status_reaction_serializer.rb

51 lines
960 B
Ruby
Raw Normal View History

2024-01-25 13:03:51 +09:00
# frozen_string_literal: true
class REST::StatusReactionSerializer < ActiveModel::Serializer
include RoutingHelper
attributes :name
attribute :me, if: :current_user?
attribute :url, if: :custom_emoji?
attribute :static_url, if: :custom_emoji?
attribute :count, if: :respond_to_count?
belongs_to :account, serializer: REST::AccountSerializer, unless: :respond_to_count?
delegate :count, to: :object
def respond_to_count?
object.respond_to?(:count)
end
def current_user?
!current_user.nil?
end
def custom_emoji?
object.custom_emoji.present?
end
def name
if extern?
[object.name, '@', object.custom_emoji.domain].join
else
object.name
end
end
def url
full_asset_url(object.custom_emoji.image.url)
end
def static_url
full_asset_url(object.custom_emoji.image.url(:static))
end
private
def extern?
custom_emoji? && object.custom_emoji.domain.present?
end
end