1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 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.ScheduledActivityView
11 alias Pleroma.Web.MastodonAPI.StatusView
13 def render("index.json", %{scheduled_activities: scheduled_activities}) do
14 render_many(scheduled_activities, ScheduledActivityView, "show.json")
17 def render("show.json", %{scheduled_activity: %ScheduledActivity{} = scheduled_activity}) do
19 id: scheduled_activity.id |> to_string,
20 scheduled_at: scheduled_activity.scheduled_at |> CommonAPI.Utils.to_masto_date(),
21 params: status_params(scheduled_activity.params)
23 |> with_media_attachments(scheduled_activity)
26 defp with_media_attachments(data, %{params: %{"media_attachments" => media_attachments}}) do
27 attachments = render_many(media_attachments, StatusView, "attachment.json", as: :attachment)
28 Map.put(data, :media_attachments, attachments)
31 defp with_media_attachments(data, _), do: data
33 defp status_params(params) do
35 text: params["status"],
36 sensitive: params["sensitive"],
37 spoiler_text: params["spoiler_text"],
38 visibility: params["visibility"],
39 scheduled_at: params["scheduled_at"],
41 in_reply_to_id: params["in_reply_to_id"]
45 if media_ids = params["media_ids"] do
46 Map.put(data, :media_ids, media_ids)