From fc89ecc6cace1362d40158e9614494a242a7b06a Mon Sep 17 00:00:00 2001 From: Claire Date: Wed, 17 Apr 2024 11:06:23 +0200 Subject: [PATCH] Change `/api/v1/announcements` to return regular `Status` entities (#26736) --- app/models/announcement.rb | 12 +++++++----- app/serializers/rest/announcement_serializer.rb | 14 +------------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/app/models/announcement.rb b/app/models/announcement.rb index 5ce382dc18..54923ed081 100644 --- a/app/models/announcement.rb +++ b/app/models/announcement.rb @@ -59,11 +59,13 @@ class Announcement < ApplicationRecord end def statuses - @statuses ||= if status_ids.nil? - [] - else - Status.where(id: status_ids).distributable_visibility - end + @statuses ||= begin + if status_ids.nil? + [] + else + Status.with_includes.distributable_visibility.where(id: status_ids) + end + end end def tags diff --git a/app/serializers/rest/announcement_serializer.rb b/app/serializers/rest/announcement_serializer.rb index 8cee271272..d1a011425d 100644 --- a/app/serializers/rest/announcement_serializer.rb +++ b/app/serializers/rest/announcement_serializer.rb @@ -9,7 +9,7 @@ class REST::AnnouncementSerializer < ActiveModel::Serializer attribute :read, if: :current_user? has_many :mentions - has_many :statuses + has_many :statuses, serializer: REST::StatusSerializer has_many :tags, serializer: REST::StatusSerializer::TagSerializer has_many :emojis, serializer: REST::CustomEmojiSerializer has_many :reactions, serializer: REST::ReactionSerializer @@ -49,16 +49,4 @@ class REST::AnnouncementSerializer < ActiveModel::Serializer object.pretty_acct end end - - class StatusSerializer < ActiveModel::Serializer - attributes :id, :url - - def id - object.id.to_s - end - - def url - ActivityPub::TagManager.instance.url_for(object) - end - end end