logo

pleroma

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

timelines.ex (1129B)


  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.Preload.Providers.Timelines do
  5. alias Pleroma.Web.ActivityPub.ActivityPub
  6. alias Pleroma.Web.MastodonAPI.StatusView
  7. alias Pleroma.Web.Preload.Providers.Provider
  8. @behaviour Provider
  9. @public_url "/api/v1/timelines/public"
  10. @impl Provider
  11. def generate_terms(params) do
  12. build_public_tag(%{}, params)
  13. end
  14. def build_public_tag(acc, params) do
  15. if Pleroma.Config.restrict_unauthenticated_access?(:timelines, :federated) do
  16. acc
  17. else
  18. Map.put(acc, @public_url, public_timeline(params))
  19. end
  20. end
  21. defp public_timeline(%{"path" => ["main", "all"]}), do: get_public_timeline(false)
  22. defp public_timeline(_params), do: get_public_timeline(true)
  23. defp get_public_timeline(local_only) do
  24. activities =
  25. ActivityPub.fetch_public_activities(%{
  26. type: ["Create"],
  27. local_only: local_only
  28. })
  29. StatusView.render("index.json", activities: activities, for: nil, as: :activity)
  30. end
  31. end