2020-01-24 06:00:13 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class REST::ReactionSerializer < ActiveModel::Serializer
|
|
|
|
include RoutingHelper
|
|
|
|
|
2022-12-07 21:19:36 +09:00
|
|
|
attributes :name, :count
|
2020-01-24 06:00:13 +09:00
|
|
|
|
|
|
|
attribute :me, if: :current_user?
|
|
|
|
attribute :url, if: :custom_emoji?
|
|
|
|
attribute :static_url, if: :custom_emoji?
|
|
|
|
|
|
|
|
def count
|
|
|
|
object.respond_to?(:count) ? object.count : 0
|
|
|
|
end
|
|
|
|
|
|
|
|
def current_user?
|
|
|
|
!current_user.nil?
|
|
|
|
end
|
|
|
|
|
|
|
|
def custom_emoji?
|
|
|
|
object.custom_emoji.present?
|
|
|
|
end
|
|
|
|
|
2022-12-07 21:19:36 +09:00
|
|
|
def name
|
|
|
|
if extern?
|
|
|
|
[object.name, '@', object.custom_emoji.domain].join
|
2022-12-03 20:57:00 +09:00
|
|
|
else
|
2022-12-07 21:19:36 +09:00
|
|
|
object.name
|
2022-12-03 20:57:00 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-24 06:00:13 +09:00
|
|
|
def url
|
|
|
|
full_asset_url(object.custom_emoji.image.url)
|
|
|
|
end
|
|
|
|
|
|
|
|
def static_url
|
|
|
|
full_asset_url(object.custom_emoji.image.url(:static))
|
|
|
|
end
|
2022-12-07 21:19:36 +09:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def extern?
|
|
|
|
custom_emoji? && object.custom_emoji.domain.present?
|
|
|
|
end
|
2020-01-24 06:00:13 +09:00
|
|
|
end
|