From c867d232505189d907e72d7501817e8a1f287f1c Mon Sep 17 00:00:00 2001 From: Tusooa Zhu Date: Tue, 8 Mar 2022 09:35:35 -0500 Subject: [PATCH] Fill properties of announcements from Mastodon API spec --- lib/pleroma/announcement.ex | 32 +++++++++++++++++++ .../web/admin_api/views/announcement_view.ex | 7 +--- .../web/api_spec/schemas/announcement.ex | 19 +++++++++-- 3 files changed, 49 insertions(+), 9 deletions(-) diff --git a/lib/pleroma/announcement.ex b/lib/pleroma/announcement.ex index 8cf917c9d..968136d16 100644 --- a/lib/pleroma/announcement.ex +++ b/lib/pleroma/announcement.ex @@ -48,4 +48,36 @@ def delete_by_id(id) do :error end end + + def read_by?(_announcement, _user) do + false + end + + def render_json(announcement, opts \\ []) do + extra_params = + case Keyword.fetch(opts, :for) do + {:ok, user} -> + %{read: read_by?(announcement, user)} + _ -> + %{} + end + + base = %{ + id: announcement.id, + content: announcement.data["content"], + starts_at: :null, + ends_at: :null, + all_day: false, + published_at: announcement.inserted_at, + updated_at: announcement.updated_at, + mentions: [], + statuses: [], + tags: [], + emojis: [], + reactions: [] + } + + base + |> Map.merge(extra_params) + end end diff --git a/lib/pleroma/web/admin_api/views/announcement_view.ex b/lib/pleroma/web/admin_api/views/announcement_view.ex index 5ad9a454a..8fbdc338a 100644 --- a/lib/pleroma/web/admin_api/views/announcement_view.ex +++ b/lib/pleroma/web/admin_api/views/announcement_view.ex @@ -10,11 +10,6 @@ def render("index.json", %{announcements: announcements}) do end def render("show.json", %{announcement: announcement}) do - %{ - id: announcement.id, - content: announcement.data["content"], - published_at: announcement.inserted_at, - updated_at: announcement.updated_at - } + Pleroma.Announcement.render_json(announcement) end end diff --git a/lib/pleroma/web/api_spec/schemas/announcement.ex b/lib/pleroma/web/api_spec/schemas/announcement.ex index 26f93c730..433437aac 100644 --- a/lib/pleroma/web/api_spec/schemas/announcement.ex +++ b/lib/pleroma/web/api_spec/schemas/announcement.ex @@ -9,14 +9,27 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Announcement do require OpenApiSpex OpenApiSpex.schema(%{ - title: "Account", - description: "Response schema for an account", + title: "Announcement", + description: "Response schema for an announcement", type: :object, properties: %{ id: FlakeID, content: %Schema{type: :string}, + starts_at: %Schema{ + oneOf: [%Schema{type: :null}, %Schema{type: :string, format: "date-time"}] + }, + ends_at: %Schema{ + oneOf: [%Schema{type: :null}, %Schema{type: :string, format: "date-time"}] + }, + all_day: %Schema{type: :boolean}, published_at: %Schema{type: :string, format: "date-time"}, - updated_at: %Schema{type: :string, format: "date-time"} + updated_at: %Schema{type: :string, format: "date-time"}, + read: %Schema{type: :boolean}, + mentions: %Schema{type: :array}, + statuses: %Schema{type: :array}, + tags: %Schema{type: :array}, + emojis: %Schema{type: :array}, + reactions: %Schema{type: :array} } }) end