honkoma/lib/pleroma/web/preload/providers/timelines.ex

40 lines
1.1 KiB
Elixir
Raw Normal View History

2020-05-12 15:08:00 +00:00
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
2020-05-12 15:08:00 +00:00
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Preload.Providers.Timelines do
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.MastodonAPI.StatusView
alias Pleroma.Web.Preload.Providers.Provider
@behaviour Provider
2020-06-29 09:41:00 +00:00
@public_url "/api/v1/timelines/public"
2020-05-12 15:08:00 +00:00
@impl Provider
2020-06-02 14:18:06 +00:00
def generate_terms(params) do
build_public_tag(%{}, params)
2020-05-12 15:08:00 +00:00
end
2020-06-02 14:18:06 +00:00
def build_public_tag(acc, params) do
if Pleroma.Config.restrict_unauthenticated_access?(:timelines, :federated) do
2020-05-12 15:08:00 +00:00
acc
else
2020-06-02 14:18:06 +00:00
Map.put(acc, @public_url, public_timeline(params))
2020-05-12 15:08:00 +00:00
end
end
2020-06-02 14:18:06 +00:00
defp public_timeline(%{"path" => ["main", "all"]}), do: get_public_timeline(false)
2020-05-12 15:08:00 +00:00
2020-06-02 14:18:06 +00:00
defp public_timeline(_params), do: get_public_timeline(true)
defp get_public_timeline(local_only) do
activities =
ActivityPub.fetch_public_activities(%{
2020-06-15 16:25:03 +00:00
type: ["Create"],
local_only: local_only
2020-06-02 14:18:06 +00:00
})
2020-05-12 15:08:00 +00:00
2020-06-02 14:18:06 +00:00
StatusView.render("index.json", activities: activities, for: nil, as: :activity)
2020-05-12 15:08:00 +00:00
end
end