support reacting with foreign custom emojis
This commit is contained in:
parent
66ade5c1fd
commit
1cb9c9dcca
|
@ -24,11 +24,6 @@ class StatusReaction < ApplicationRecord
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_custom_emoji
|
def set_custom_emoji
|
||||||
return if name.blank?
|
self.custom_emoji = CustomEmoji.find_by(shortcode: name, domain: account.domain) 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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
class REST::ReactionSerializer < ActiveModel::Serializer
|
class REST::ReactionSerializer < ActiveModel::Serializer
|
||||||
include RoutingHelper
|
include RoutingHelper
|
||||||
|
|
||||||
attributes :name, :count, :extern
|
attributes :name, :count
|
||||||
|
|
||||||
attribute :me, if: :current_user?
|
attribute :me, if: :current_user?
|
||||||
attribute :url, if: :custom_emoji?
|
attribute :url, if: :custom_emoji?
|
||||||
|
@ -21,11 +21,11 @@ class REST::ReactionSerializer < ActiveModel::Serializer
|
||||||
object.custom_emoji.present?
|
object.custom_emoji.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
def extern
|
def name
|
||||||
if custom_emoji?
|
if extern?
|
||||||
object.custom_emoji.domain.present?
|
[object.name, '@', object.custom_emoji.domain].join
|
||||||
else
|
else
|
||||||
false
|
object.name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -36,4 +36,10 @@ class REST::ReactionSerializer < ActiveModel::Serializer
|
||||||
def static_url
|
def static_url
|
||||||
full_asset_url(object.custom_emoji.image.url(:static))
|
full_asset_url(object.custom_emoji.image.url(:static))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def extern?
|
||||||
|
custom_emoji? && object.custom_emoji.domain.present?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,10 +18,6 @@ class StatusReactionValidator < ActiveModel::Validator
|
||||||
SUPPORTED_EMOJIS.include?(name)
|
SUPPORTED_EMOJIS.include?(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def new_reaction?(reaction)
|
|
||||||
!reaction.status.status_reactions.where(name: reaction.name).exists?
|
|
||||||
end
|
|
||||||
|
|
||||||
def limit_reached?(reaction)
|
def limit_reached?(reaction)
|
||||||
reaction.status.status_reactions.where(status: reaction.status, account: reaction.account).count >= LIMIT
|
reaction.status.status_reactions.where(status: reaction.status, account: reaction.account).count >= LIMIT
|
||||||
end
|
end
|
||||||
|
|
|
@ -442,8 +442,10 @@ Rails.application.routes.draw do
|
||||||
resource :favourite, only: :create
|
resource :favourite, only: :create
|
||||||
post :unfavourite, to: 'favourites#destroy'
|
post :unfavourite, to: 'favourites#destroy'
|
||||||
|
|
||||||
post '/react/:id', to: 'reactions#create'
|
# foreign custom emojis are encoded as shortcode@domain.tld
|
||||||
post '/unreact/:id', to: 'reactions#destroy'
|
# the constraint prevents rails from interpreting the ".tld" as a filename extension
|
||||||
|
post '/react/:id', to: 'reactions#create', constraints: { id: /[^\/]+/ }
|
||||||
|
post '/unreact/:id', to: 'reactions#destroy', constraints: { id: /[^\/]+/ }
|
||||||
|
|
||||||
resource :bookmark, only: :create
|
resource :bookmark, only: :create
|
||||||
post :unbookmark, to: 'bookmarks#destroy'
|
post :unbookmark, to: 'bookmarks#destroy'
|
||||||
|
|
Loading…
Reference in a new issue