From 762d9bbb97ccb78532ba495c60d4e386619b727b Mon Sep 17 00:00:00 2001 From: Plastikmensch Date: Sun, 14 May 2023 23:49:18 +0200 Subject: [PATCH] Add `custom_emoji` to `reacted?` Signed-off-by: Plastikmensch --- app/lib/activitypub/activity/emoji_react.rb | 5 +++-- app/lib/activitypub/activity/like.rb | 2 +- app/lib/activitypub/activity/undo.rb | 14 +++++++++++++- app/models/concerns/account_interactions.rb | 4 ++-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/lib/activitypub/activity/emoji_react.rb b/app/lib/activitypub/activity/emoji_react.rb index 526f22803d..292ea6fd3a 100644 --- a/app/lib/activitypub/activity/emoji_react.rb +++ b/app/lib/activitypub/activity/emoji_react.rb @@ -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') diff --git a/app/lib/activitypub/activity/like.rb b/app/lib/activitypub/activity/like.rb index 8acc99b9db..37215c1799 100644 --- a/app/lib/activitypub/activity/like.rb +++ b/app/lib/activitypub/activity/like.rb @@ -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') diff --git a/app/lib/activitypub/activity/undo.rb b/app/lib/activitypub/activity/undo.rb index 54cda1947f..ba8d03703c 100644 --- a/app/lib/activitypub/activity/undo.rb +++ b/app/lib/activitypub/activity/undo.rb @@ -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 diff --git a/app/models/concerns/account_interactions.rb b/app/models/concerns/account_interactions.rb index 89edd50ed2..e3d2449733 100644 --- a/app/models/concerns/account_interactions.rb +++ b/app/models/concerns/account_interactions.rb @@ -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)