1
0
mirror of https://github.com/funamitech/mastodon synced 2024-12-15 23:28:31 +09:00

Add custom_emoji to reacted?

Signed-off-by: Plastikmensch <plastikmensch@users.noreply.github.com>
This commit is contained in:
Plastikmensch 2023-05-14 23:49:18 +02:00 committed by Jeremy Kescher
parent 029e18f9b8
commit 762d9bbb97
No known key found for this signature in database
GPG Key ID: 80A419A7A613DFA4
4 changed files with 19 additions and 6 deletions

View File

@ -6,8 +6,7 @@ class ActivityPub::Activity::EmojiReact < ActivityPub::Activity
name = @json['content']
return if original_status.nil? ||
!original_status.account.local? ||
delete_arrived_first?(@json['id']) ||
@account.reacted?(original_status, name)
delete_arrived_first?(@json['id'])
custom_emoji = nil
if /^:.*:$/.match?(name)
@ -18,6 +17,8 @@ class ActivityPub::Activity::EmojiReact < ActivityPub::Activity
return if custom_emoji.nil?
end
return if @account.reacted?(original_status, name, custom_emoji)
reaction = original_status.status_reactions.create!(account: @account, name: name, custom_emoji: custom_emoji)
LocalNotificationWorker.perform_async(original_status.account_id, reaction.id, 'StatusReaction', 'reaction')

View File

@ -29,7 +29,7 @@ class ActivityPub::Activity::Like < ActivityPub::Activity
custom_emoji = CustomEmoji.find_by(shortcode: name, domain: @account.domain)
return false if custom_emoji.nil? # invalid custom emoji, treat it as a regular like
end
return true if @account.reacted?(original_status, name)
return true if @account.reacted?(original_status, name, custom_emoji)
reaction = original_status.status_reactions.create!(account: @account, name: name, custom_emoji: custom_emoji)
LocalNotificationWorker.perform_async(original_status.account_id, reaction.id, 'StatusReaction', 'reaction')

View File

@ -117,13 +117,25 @@ class ActivityPub::Activity::Undo < ActivityPub::Activity
def undo_emoji_react
name = @object['content']
tags = @object['tag']
return if name.nil?
status = status_from_uri(target_uri)
name.delete! ':'
return if status.nil? || !status.account.local?
if @account.reacted?(status, name.delete(':'))
custom_emoji = nil
emoji_tag = as_array(tags).find { |tag| tag['type'] == 'Emoji' }
if emoji_tag
custom_emoji_parser = ActivityPub::Parser::CustomEmojiParser.new(emoji_tag)
return if custom_emoji_parser.shortcode.blank? || custom_emoji_parser.image_remote_url.blank?
custom_emoji = CustomEmoji.find_by(shortcode: custom_emoji_parser.shortcode, domain: @account.domain)
end
if @account.reacted?(status, name, custom_emoji)
reaction = status.status_reactions.where(account: @account, name: name).first
reaction&.destroy
else

View File

@ -243,8 +243,8 @@ module AccountInteractions
status.proper.favourites.where(account: self).exists?
end
def reacted?(status, name)
status.proper.status_reactions.where(account: self, name: name).exists?
def reacted?(status, name, custom_emoji = nil)
status.proper.status_reactions.where(account: self, name: name, custom_emoji: custom_emoji).exists?
end
def bookmarked?(status)