a5c96afeac
Using an emoji map was completely unnecessary in the first place, because the reaction list from the API response includes URLs for every custom emoji anyway. The reaction list now also contains a boolean field indicating whether it is an external custom emoji, which is required because people should only be able to react with Unicode emojis and local custom ones, not with custom emojis from other servers.
40 lines
712 B
Ruby
40 lines
712 B
Ruby
# frozen_string_literal: true
|
|
|
|
class REST::ReactionSerializer < ActiveModel::Serializer
|
|
include RoutingHelper
|
|
|
|
attributes :name, :count, :extern
|
|
|
|
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
|
|
|
|
def extern
|
|
if custom_emoji?
|
|
object.custom_emoji.domain.present?
|
|
else
|
|
false
|
|
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
|
|
end
|