From c2209aca124e9f93940cee0dfa94f7c1ae4f3833 Mon Sep 17 00:00:00 2001 From: fef Date: Wed, 7 Dec 2022 12:19:36 +0000 Subject: [PATCH] support reacting with foreign custom emojis --- app/models/status_reaction.rb | 7 +------ app/serializers/rest/reaction_serializer.rb | 16 +++++++++++----- app/validators/status_reaction_validator.rb | 4 ---- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/app/models/status_reaction.rb b/app/models/status_reaction.rb index 4793ff9aa3..0833a7eafd 100644 --- a/app/models/status_reaction.rb +++ b/app/models/status_reaction.rb @@ -24,11 +24,6 @@ class StatusReaction < ApplicationRecord private def set_custom_emoji - return if name.blank? - self.custom_emoji = if account.local? - CustomEmoji.local.find_by(disabled: false, shortcode: name) - else - CustomEmoji.find_by(shortcode: name, domain: account.domain) - end + self.custom_emoji = CustomEmoji.find_by(shortcode: name, domain: account.domain) if name.blank? end end diff --git a/app/serializers/rest/reaction_serializer.rb b/app/serializers/rest/reaction_serializer.rb index 007d3b5015..b0f0732bf7 100644 --- a/app/serializers/rest/reaction_serializer.rb +++ b/app/serializers/rest/reaction_serializer.rb @@ -3,7 +3,7 @@ class REST::ReactionSerializer < ActiveModel::Serializer include RoutingHelper - attributes :name, :count, :extern + attributes :name, :count attribute :me, if: :current_user? attribute :url, if: :custom_emoji? @@ -21,11 +21,11 @@ class REST::ReactionSerializer < ActiveModel::Serializer object.custom_emoji.present? end - def extern - if custom_emoji? - object.custom_emoji.domain.present? + def name + if extern? + [object.name, '@', object.custom_emoji.domain].join else - false + object.name end end @@ -36,4 +36,10 @@ class REST::ReactionSerializer < ActiveModel::Serializer 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 diff --git a/app/validators/status_reaction_validator.rb b/app/validators/status_reaction_validator.rb index a60271dd84..d85d48e4c7 100644 --- a/app/validators/status_reaction_validator.rb +++ b/app/validators/status_reaction_validator.rb @@ -18,10 +18,6 @@ class StatusReactionValidator < ActiveModel::Validator SUPPORTED_EMOJIS.include?(name) end - def new_reaction?(reaction) - !reaction.status.status_reactions.where(name: reaction.name).exists? - end - def limit_reached?(reaction) reaction.status.status_reactions.where(status: reaction.status, account: reaction.account).count >= LIMIT end