scheduled_activity_view.ex 1.5 KB
Newer Older
Eugenij's avatar
Eugenij committed
1
# Pleroma: A lightweight social networking server
feld's avatar
feld committed
2
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
Eugenij's avatar
Eugenij committed
3
4
5
6
7
8
9
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.Web.MastodonAPI.ScheduledActivityView do
  use Pleroma.Web, :view

  alias Pleroma.ScheduledActivity
  alias Pleroma.Web.CommonAPI
10
  alias Pleroma.Web.MastodonAPI.StatusView
Eugenij's avatar
Eugenij committed
11
12

  def render("index.json", %{scheduled_activities: scheduled_activities}) do
minibikini's avatar
minibikini committed
13
    render_many(scheduled_activities, __MODULE__, "show.json")
Eugenij's avatar
Eugenij committed
14
15
16
17
  end

  def render("show.json", %{scheduled_activity: %ScheduledActivity{} = scheduled_activity}) do
    %{
18
19
      id: to_string(scheduled_activity.id),
      scheduled_at: CommonAPI.Utils.to_masto_date(scheduled_activity.scheduled_at),
20
      params: status_params(scheduled_activity.params)
Eugenij's avatar
Eugenij committed
21
    }
22
23
24
25
    |> with_media_attachments(scheduled_activity)
  end

  defp with_media_attachments(data, %{params: %{"media_attachments" => media_attachments}}) do
minibikini's avatar
minibikini committed
26
27
    attachments = render_many(media_attachments, StatusView, "attachment.json", as: :attachment)
    Map.put(data, :media_attachments, attachments)
28
29
30
31
32
  end

  defp with_media_attachments(data, _), do: data

  defp status_params(params) do
33
    %{
34
35
36
37
38
39
40
41
      text: params["status"],
      sensitive: params["sensitive"],
      spoiler_text: params["spoiler_text"],
      visibility: params["visibility"],
      scheduled_at: params["scheduled_at"],
      poll: params["poll"],
      in_reply_to_id: params["in_reply_to_id"]
    }
42
    |> Pleroma.Maps.put_if_present(:media_ids, params["media_ids"])
Eugenij's avatar
Eugenij committed
43
44
  end
end