Fill properties of announcements from Mastodon API spec
This commit is contained in:
parent
d7af67012f
commit
c867d23250
3 changed files with 49 additions and 9 deletions
|
@ -48,4 +48,36 @@ defmodule Pleroma.Announcement do
|
||||||
:error
|
:error
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
|
@ -10,11 +10,6 @@ defmodule Pleroma.Web.AdminAPI.AnnouncementView do
|
||||||
end
|
end
|
||||||
|
|
||||||
def render("show.json", %{announcement: announcement}) do
|
def render("show.json", %{announcement: announcement}) do
|
||||||
%{
|
Pleroma.Announcement.render_json(announcement)
|
||||||
id: announcement.id,
|
|
||||||
content: announcement.data["content"],
|
|
||||||
published_at: announcement.inserted_at,
|
|
||||||
updated_at: announcement.updated_at
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,14 +9,27 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Announcement do
|
||||||
require OpenApiSpex
|
require OpenApiSpex
|
||||||
|
|
||||||
OpenApiSpex.schema(%{
|
OpenApiSpex.schema(%{
|
||||||
title: "Account",
|
title: "Announcement",
|
||||||
description: "Response schema for an account",
|
description: "Response schema for an announcement",
|
||||||
type: :object,
|
type: :object,
|
||||||
properties: %{
|
properties: %{
|
||||||
id: FlakeID,
|
id: FlakeID,
|
||||||
content: %Schema{type: :string},
|
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"},
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue