logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/

scheduled_activity_view.ex (1581B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.MastodonAPI.ScheduledActivityView do
  5. use Pleroma.Web, :view
  6. alias Pleroma.ScheduledActivity
  7. alias Pleroma.Web.CommonAPI
  8. alias Pleroma.Web.MastodonAPI.StatusView
  9. def render("index.json", %{scheduled_activities: scheduled_activities}) do
  10. render_many(scheduled_activities, __MODULE__, "show.json")
  11. end
  12. def render("show.json", %{scheduled_activity: %ScheduledActivity{} = scheduled_activity}) do
  13. %{
  14. id: to_string(scheduled_activity.id),
  15. scheduled_at: CommonAPI.Utils.to_masto_date(scheduled_activity.scheduled_at),
  16. params: status_params(scheduled_activity.params)
  17. }
  18. |> with_media_attachments(scheduled_activity)
  19. end
  20. defp with_media_attachments(data, %{params: %{"media_attachments" => media_attachments}}) do
  21. attachments = render_many(media_attachments, StatusView, "attachment.json", as: :attachment)
  22. Map.put(data, :media_attachments, attachments)
  23. end
  24. defp with_media_attachments(data, _), do: data
  25. defp status_params(params) do
  26. %{
  27. text: params["status"],
  28. sensitive: params["sensitive"],
  29. spoiler_text: params["spoiler_text"],
  30. visibility: params["visibility"],
  31. scheduled_at: params["scheduled_at"],
  32. poll: params["poll"],
  33. in_reply_to_id: params["in_reply_to_id"],
  34. expires_in: params["expires_in"]
  35. }
  36. |> Pleroma.Maps.put_if_present(:media_ids, params["media_ids"])
  37. end
  38. end