From 92268f5da77fb72e7b2190215ecbb7154a7ce6e9 Mon Sep 17 00:00:00 2001 From: Jeremy Kescher Date: Mon, 18 Jul 2022 06:48:08 +0200 Subject: [PATCH] Revert "Temporarily undo tag_serializer changes due to an error" This reverts commit dc03059a7b4a853583dcc3b10c19e6d29b9a4d67. --- app/serializers/rest/tag_serializer.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/serializers/rest/tag_serializer.rb b/app/serializers/rest/tag_serializer.rb index 52bfaa4ce4..7801e77d1f 100644 --- a/app/serializers/rest/tag_serializer.rb +++ b/app/serializers/rest/tag_serializer.rb @@ -5,6 +5,8 @@ class REST::TagSerializer < ActiveModel::Serializer attributes :name, :url, :history + attribute :following, if: :current_user? + def url tag_url(object) end @@ -12,4 +14,16 @@ class REST::TagSerializer < ActiveModel::Serializer def name object.display_name end + + def following + if instance_options && instance_options[:relationships] + instance_options[:relationships].following_map[object.id] || false + else + TagFollow.where(tag_id: object.id, account_id: current_user.account_id).exists? + end + end + + def current_user? + !current_user.nil? + end end