Change to interpret emoji reaction as favorite

This commit is contained in:
noellabo 2021-06-08 07:19:09 +09:00
parent 4803329dce
commit 933485dcec
3 changed files with 25 additions and 8 deletions

View file

@ -52,7 +52,19 @@ class ActivityPub::Activity::Like < ActivityPub::Activity
def shortcode def shortcode
return @shortcode if defined?(@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 end
def emoji_tag def emoji_tag

View file

@ -112,8 +112,6 @@ class ActivityPub::Activity::Undo < ActivityPub::Activity
return if status.nil? || !status.account.local? return if status.nil? || !status.account.local?
shortcode = @object['_misskey_reaction']&.delete(':')
if shortcode.present? if shortcode.present?
emoji_tag = @object['tag'].is_a?(Array) ? @object['tag']&.first : @object['tag'] emoji_tag = @object['tag'].is_a?(Array) ? @object['tag']&.first : @object['tag']
@ -135,6 +133,18 @@ class ActivityPub::Activity::Undo < ActivityPub::Activity
end end
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 def undo_react
@account.emoji_reactions.find_by(uri: object_uri)&.destroy @account.emoji_reactions.find_by(uri: object_uri)&.destroy
end end

View file

@ -3,7 +3,6 @@
class ActivityPub::EmojiReactionSerializer < ActivityPub::Serializer class ActivityPub::EmojiReactionSerializer < ActivityPub::Serializer
attributes :id, :type, :actor, :content attributes :id, :type, :actor, :content
attribute :virtual_object, key: :object 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? } 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 def content
object.custom_emoji.nil? ? object.name : ":#{object.name}:" object.custom_emoji.nil? ? object.name : ":#{object.name}:"
end end
def misskey_reaction
object.custom_emoji.nil? ? object.name : ":#{object.name}:"
end
end end