2019-03-28 10:39:10 +01:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-13 07:49:20 +01:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2019-03-28 10:39:10 +01:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.MastodonAPI.ScheduledActivityView do
|
|
|
|
use Pleroma.Web, :view
|
|
|
|
|
|
|
|
alias Pleroma.ScheduledActivity
|
|
|
|
alias Pleroma.Web.CommonAPI
|
2019-04-02 00:31:01 +02:00
|
|
|
alias Pleroma.Web.MastodonAPI.StatusView
|
2019-03-28 10:39:10 +01:00
|
|
|
|
|
|
|
def render("index.json", %{scheduled_activities: scheduled_activities}) do
|
2019-09-27 06:46:20 +02:00
|
|
|
render_many(scheduled_activities, __MODULE__, "show.json")
|
2019-03-28 10:39:10 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def render("show.json", %{scheduled_activity: %ScheduledActivity{} = scheduled_activity}) do
|
|
|
|
%{
|
2019-04-03 17:55:04 +02:00
|
|
|
id: to_string(scheduled_activity.id),
|
|
|
|
scheduled_at: CommonAPI.Utils.to_masto_date(scheduled_activity.scheduled_at),
|
2019-04-02 00:31:01 +02:00
|
|
|
params: status_params(scheduled_activity.params)
|
2019-03-28 10:39:10 +01:00
|
|
|
}
|
2019-04-02 00:31:01 +02:00
|
|
|
|> with_media_attachments(scheduled_activity)
|
|
|
|
end
|
|
|
|
|
|
|
|
defp with_media_attachments(data, %{params: %{"media_attachments" => media_attachments}}) do
|
2019-09-27 06:46:20 +02:00
|
|
|
attachments = render_many(media_attachments, StatusView, "attachment.json", as: :attachment)
|
|
|
|
Map.put(data, :media_attachments, attachments)
|
2019-04-02 00:31:01 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
defp with_media_attachments(data, _), do: data
|
|
|
|
|
|
|
|
defp status_params(params) do
|
2020-06-05 16:48:02 +02:00
|
|
|
%{
|
2019-04-02 00:31:01 +02:00
|
|
|
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"]
|
|
|
|
}
|
2020-06-05 16:48:02 +02:00
|
|
|
|> Pleroma.Maps.put_if_present(:media_ids, params["media_ids"])
|
2019-03-28 10:39:10 +01:00
|
|
|
end
|
|
|
|
end
|