akkoma/lib/pleroma/web/mastodon_api/views/scheduled_activity_view.ex

49 lines
1.6 KiB
Elixir
Raw Normal View History

2019-03-28 03:39:10 -06:00
# Pleroma: A lightweight social networking server
2020-03-03 15:44:49 -07:00
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
2019-03-28 03:39:10 -06: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
alias Pleroma.Web.MastodonAPI.StatusView
2019-03-28 03:39:10 -06:00
def render("index.json", %{scheduled_activities: scheduled_activities}) do
2019-09-26 22:46:20 -06:00
render_many(scheduled_activities, __MODULE__, "show.json")
2019-03-28 03:39:10 -06:00
end
def render("show.json", %{scheduled_activity: %ScheduledActivity{} = scheduled_activity}) do
%{
id: to_string(scheduled_activity.id),
scheduled_at: CommonAPI.Utils.to_masto_date(scheduled_activity.scheduled_at),
params: status_params(scheduled_activity.params)
2019-03-28 03:39:10 -06:00
}
|> with_media_attachments(scheduled_activity)
end
defp with_media_attachments(data, %{params: %{"media_attachments" => media_attachments}}) do
2019-09-26 22:46:20 -06:00
attachments = render_many(media_attachments, StatusView, "attachment.json", as: :attachment)
Map.put(data, :media_attachments, attachments)
end
defp with_media_attachments(data, _), do: data
defp status_params(params) do
data = %{
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"]
}
2019-09-26 22:46:20 -06:00
case params["media_ids"] do
nil -> data
media_ids -> Map.put(data, :media_ids, media_ids)
end
2019-03-28 03:39:10 -06:00
end
end