total rebase
[anni] / lib / pleroma / web / mastodon_api / views / scheduled_activity_view.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.MastodonAPI.ScheduledActivityView do
6   use Pleroma.Web, :view
7
8   alias Pleroma.ScheduledActivity
9   alias Pleroma.Web.CommonAPI
10   alias Pleroma.Web.MastodonAPI.StatusView
11
12   def render("index.json", %{scheduled_activities: scheduled_activities}) do
13     render_many(scheduled_activities, __MODULE__, "show.json")
14   end
15
16   def render("show.json", %{scheduled_activity: %ScheduledActivity{} = scheduled_activity}) do
17     %{
18       id: to_string(scheduled_activity.id),
19       scheduled_at: CommonAPI.Utils.to_masto_date(scheduled_activity.scheduled_at),
20       params: status_params(scheduled_activity.params)
21     }
22     |> with_media_attachments(scheduled_activity)
23   end
24
25   defp with_media_attachments(data, %{params: %{"media_attachments" => media_attachments}}) do
26     attachments = render_many(media_attachments, StatusView, "attachment.json", as: :attachment)
27     Map.put(data, :media_attachments, attachments)
28   end
29
30   defp with_media_attachments(data, _), do: data
31
32   defp status_params(params) do
33     %{
34       text: params["status"],
35       sensitive: params["sensitive"],
36       spoiler_text: params["spoiler_text"],
37       visibility: params["visibility"],
38       scheduled_at: params["scheduled_at"],
39       poll: params["poll"],
40       in_reply_to_id: params["in_reply_to_id"],
41       expires_in: params["expires_in"]
42     }
43     |> Pleroma.Maps.put_if_present(:media_ids, params["media_ids"])
44   end
45 end