From 933485dcecb0e89500bf9150c6d224f7d09b9854 Mon Sep 17 00:00:00 2001 From: noellabo Date: Tue, 8 Jun 2021 07:19:09 +0900 Subject: [PATCH] =?UTF-8?q?Change=20to=20interpret=20emoji=20reaction=20?= =?UTF-8?q?=E2=AD=90=20as=20favorite?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/lib/activitypub/activity/like.rb | 14 +++++++++++++- app/lib/activitypub/activity/undo.rb | 14 ++++++++++++-- .../activitypub/emoji_reaction_serializer.rb | 5 ----- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/app/lib/activitypub/activity/like.rb b/app/lib/activitypub/activity/like.rb index b01d646b2..ef27cce89 100644 --- a/app/lib/activitypub/activity/like.rb +++ b/app/lib/activitypub/activity/like.rb @@ -52,7 +52,19 @@ class ActivityPub::Activity::Like < ActivityPub::Activity def shortcode return @shortcode if defined?(@shortcode) - @shortcode = @json['_misskey_reaction']&.delete(':') + @shortcode = begin + if @json['_misskey_reaction'] == '⭐' + nil + else + @json['content']&.delete(':') + end + end + end + + def misskey_favourite? + misskey_shortcode = @json['_misskey_reaction']&.delete(':') + + return misskey_shortcode == shortcode && misskey_shortcode == '⭐' end def emoji_tag diff --git a/app/lib/activitypub/activity/undo.rb b/app/lib/activitypub/activity/undo.rb index ed7e85626..fbb07cd51 100644 --- a/app/lib/activitypub/activity/undo.rb +++ b/app/lib/activitypub/activity/undo.rb @@ -112,8 +112,6 @@ class ActivityPub::Activity::Undo < ActivityPub::Activity return if status.nil? || !status.account.local? - shortcode = @object['_misskey_reaction']&.delete(':') - if shortcode.present? emoji_tag = @object['tag'].is_a?(Array) ? @object['tag']&.first : @object['tag'] @@ -135,6 +133,18 @@ class ActivityPub::Activity::Undo < ActivityPub::Activity end end + def shortcode + return @shortcode if defined?(@shortcode) + + @shortcode = begin + if @object['_misskey_reaction'] == '⭐' + nil + else + @object['content']&.delete(':') + end + end + end + def undo_react @account.emoji_reactions.find_by(uri: object_uri)&.destroy end diff --git a/app/serializers/activitypub/emoji_reaction_serializer.rb b/app/serializers/activitypub/emoji_reaction_serializer.rb index 75ca36430..59ec8d6e6 100644 --- a/app/serializers/activitypub/emoji_reaction_serializer.rb +++ b/app/serializers/activitypub/emoji_reaction_serializer.rb @@ -3,7 +3,6 @@ class ActivityPub::EmojiReactionSerializer < ActivityPub::Serializer attributes :id, :type, :actor, :content attribute :virtual_object, key: :object - attribute :misskey_reaction, key: :_misskey_reaction has_one :custom_emoji ,key: :tag, serializer: ActivityPub::EmojiSerializer, unless: -> { object.custom_emoji.nil? } @@ -26,8 +25,4 @@ class ActivityPub::EmojiReactionSerializer < ActivityPub::Serializer def content object.custom_emoji.nil? ? object.name : ":#{object.name}:" end - - def misskey_reaction - object.custom_emoji.nil? ? object.name : ":#{object.name}:" - end end