From 55e741df7dfba0b094a353887a0aded155521be5 Mon Sep 17 00:00:00 2001 From: fef Date: Sun, 4 Dec 2022 10:52:02 +0000 Subject: [PATCH] serialize custom emoji reactions properly for AP Akkoma and possibly others expect the `tag` field in an EmojiReact activity to be an array, not just a single object, so it's being wrapped into one now. I'm not entirely sure whether this is the idiomatic way of doing it tbh, but it works fine. --- app/serializers/activitypub/emoji_reaction_serializer.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/serializers/activitypub/emoji_reaction_serializer.rb b/app/serializers/activitypub/emoji_reaction_serializer.rb index 50f3efa3c..f8887f15b 100644 --- a/app/serializers/activitypub/emoji_reaction_serializer.rb +++ b/app/serializers/activitypub/emoji_reaction_serializer.rb @@ -3,8 +3,7 @@ class ActivityPub::EmojiReactionSerializer < ActivityPub::Serializer attributes :id, :type, :actor, :content attribute :virtual_object, key: :object - - has_one :custom_emoji, key: :tag, serializer: ActivityPub::EmojiSerializer, unless: -> { object.custom_emoji.nil? } + attribute :custom_emoji, key: :tag, unless: -> { object.custom_emoji.nil? } def id [ActivityPub::TagManager.instance.uri_for(object.account), '#emoji_reactions/', object.id].join @@ -31,4 +30,10 @@ class ActivityPub::EmojiReactionSerializer < ActivityPub::Serializer end alias reaction content + + # Akkoma (and possibly others) expect `tag` to be an array, so we can't just + # use the has_one shorthand because we need to wrap it into an array manually + def custom_emoji + [ActivityPub::EmojiSerializer.new(object.custom_emoji).serializable_hash] + end end