From 5fc29d03ddc81c1cbbd520492740414868e0ce95 Mon Sep 17 00:00:00 2001 From: KMY Date: Mon, 27 Feb 2023 14:53:30 +0900 Subject: [PATCH] Fix custom emoji in notification --- .../rest/notification_serializer.rb | 2 +- .../rest/notify_emoji_reaction_serializer.rb | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 app/serializers/rest/notify_emoji_reaction_serializer.rb diff --git a/app/serializers/rest/notification_serializer.rb b/app/serializers/rest/notification_serializer.rb index 15c62476d..f3235b3b1 100644 --- a/app/serializers/rest/notification_serializer.rb +++ b/app/serializers/rest/notification_serializer.rb @@ -6,7 +6,7 @@ class REST::NotificationSerializer < ActiveModel::Serializer belongs_to :from_account, key: :account, serializer: REST::AccountSerializer belongs_to :target_status, key: :status, if: :status_type?, serializer: REST::StatusSerializer belongs_to :report, if: :report_type?, serializer: REST::ReportSerializer - belongs_to :emoji_reaction, if: :emoji_reaction_type?, serializer: REST::EmojiReactionSerializer + belongs_to :emoji_reaction, if: :emoji_reaction_type?, serializer: REST::NotifyEmojiReactionSerializer def id object.id.to_s diff --git a/app/serializers/rest/notify_emoji_reaction_serializer.rb b/app/serializers/rest/notify_emoji_reaction_serializer.rb new file mode 100644 index 000000000..a78740d56 --- /dev/null +++ b/app/serializers/rest/notify_emoji_reaction_serializer.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +class REST::NotifyEmojiReactionSerializer < ActiveModel::Serializer + include RoutingHelper + + attributes :name + + attribute :count, if: :count? + attribute :url, if: :custom_emoji? + attribute :static_url, if: :custom_emoji? + attribute :domain, if: :custom_emoji? + + def count? + object.respond_to?(:count) + end + + def custom_emoji? + object.respond_to?(:custom_emoji) && object.custom_emoji.present? + end + + def account_ids? + object.respond_to?(:account_ids) + end + + def url + full_asset_url(object.custom_emoji.image.url) + end + + def static_url + full_asset_url(object.custom_emoji.image.url(:static)) + end + + def domain + object.custom_emoji.domain + end +end