Added limits and media attachments for scheduled activities.
[akkoma] / lib / pleroma / web / mastodon_api / views / scheduled_activity_view.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 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.ScheduledActivityView
11 alias Pleroma.Web.MastodonAPI.StatusView
12
13 def render("index.json", %{scheduled_activities: scheduled_activities}) do
14 render_many(scheduled_activities, ScheduledActivityView, "show.json")
15 end
16
17 def render("show.json", %{scheduled_activity: %ScheduledActivity{} = scheduled_activity}) do
18 %{
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)
22 }
23 |> with_media_attachments(scheduled_activity)
24 end
25
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)
29 end
30
31 defp with_media_attachments(data, _), do: data
32
33 defp status_params(params) do
34 data = %{
35 text: params["status"],
36 sensitive: params["sensitive"],
37 spoiler_text: params["spoiler_text"],
38 visibility: params["visibility"],
39 scheduled_at: params["scheduled_at"],
40 poll: params["poll"],
41 in_reply_to_id: params["in_reply_to_id"]
42 }
43
44 data =
45 if media_ids = params["media_ids"] do
46 Map.put(data, :media_ids, media_ids)
47 else
48 data
49 end
50
51 data
52 end
53 end