1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.MastodonAPI.ScheduledActivityView do
8 alias Pleroma.ScheduledActivity
9 alias Pleroma.Web.CommonAPI
10 alias Pleroma.Web.MastodonAPI.StatusView
12 def render("index.json", %{scheduled_activities: scheduled_activities}) do
13 render_many(scheduled_activities, __MODULE__, "show.json")
16 def render("show.json", %{scheduled_activity: %ScheduledActivity{} = scheduled_activity}) do
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)
22 |> with_media_attachments(scheduled_activity)
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)
30 defp with_media_attachments(data, _), do: data
32 defp status_params(params) do
34 text: params["status"],
35 sensitive: params["sensitive"],
36 spoiler_text: params["spoiler_text"],
37 visibility: params["visibility"],
38 scheduled_at: params["scheduled_at"],
40 in_reply_to_id: params["in_reply_to_id"]
42 |> Pleroma.Maps.put_if_present(:media_ids, params["media_ids"])