From 8b2cad56374b2dbb6e7a445e7917810935c45536 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Fri, 7 Jul 2017 04:02:06 +0200 Subject: Refactor JSON templates to be generated with ActiveModelSerializers instead of Rabl (#4090) --- app/serializers/rest/notification_serializer.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 app/serializers/rest/notification_serializer.rb (limited to 'app/serializers/rest/notification_serializer.rb') diff --git a/app/serializers/rest/notification_serializer.rb b/app/serializers/rest/notification_serializer.rb new file mode 100644 index 000000000..97fadf32e --- /dev/null +++ b/app/serializers/rest/notification_serializer.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class REST::NotificationSerializer < ActiveModel::Serializer + attributes :id, :type, :created_at + + belongs_to :from_account, key: :account, serializer: REST::AccountSerializer + belongs_to :status, if: :status_type?, serializer: REST::StatusSerializer + + def status_type? + [:favourite, :reblog, :mention].include?(object.type) + end +end -- cgit From 6e1261f277411300e4f1d24f8c1b14ad1a165915 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Fri, 7 Jul 2017 16:19:28 +0200 Subject: Fix notifications including wrong status in JSON (#4097) --- app/serializers/rest/notification_serializer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/serializers/rest/notification_serializer.rb') diff --git a/app/serializers/rest/notification_serializer.rb b/app/serializers/rest/notification_serializer.rb index 97fadf32e..f95d099a3 100644 --- a/app/serializers/rest/notification_serializer.rb +++ b/app/serializers/rest/notification_serializer.rb @@ -4,7 +4,7 @@ class REST::NotificationSerializer < ActiveModel::Serializer attributes :id, :type, :created_at belongs_to :from_account, key: :account, serializer: REST::AccountSerializer - belongs_to :status, if: :status_type?, serializer: REST::StatusSerializer + belongs_to :target_status, key: :status, if: :status_type?, serializer: REST::StatusSerializer def status_type? [:favourite, :reblog, :mention].include?(object.type) -- cgit