chuckya/app/serializers/rest/status_reaction_serializer.rb

56 lines
1 KiB
Ruby
Raw Permalink Normal View History

2024-01-25 13:03:51 +09:00
# frozen_string_literal: true
class REST::StatusReactionSerializer < ActiveModel::Serializer
include RoutingHelper
attributes :name
2024-02-10 08:37:08 +09:00
attribute :id, unless: :no_id?
attribute :me, if: :current_user? # are this and count worth keeping?
2024-01-25 13:03:51 +09:00
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
2024-02-10 08:37:08 +09:00
def no_id?
object.id.nil?
end
2024-01-25 13:03:51 +09:00
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