dbd7db407ba0e52ae1a117881397e3d28a8adc11
[akkoma] / lib / pleroma / web / preload / timelines.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.Preload.Providers.Timelines do
6 alias Pleroma.Web.ActivityPub.ActivityPub
7 alias Pleroma.Web.MastodonAPI.StatusView
8 alias Pleroma.Web.Preload.Providers.Provider
9
10 @behaviour Provider
11 @public_url :"/api/v1/timelines/public"
12
13 @impl Provider
14 def generate_terms(_params) do
15 build_public_tag(%{})
16 end
17
18 def build_public_tag(acc) do
19 if Pleroma.Config.get([:restrict_unauthenticated, :timelines, :federated], true) do
20 acc
21 else
22 Map.put(acc, @public_url, public_timeline(nil))
23 end
24 end
25
26 defp public_timeline(user) do
27 activities =
28 create_timeline_params(user)
29 |> Map.put("local_only", false)
30 |> ActivityPub.fetch_public_activities()
31
32 StatusView.render("index.json", activities: activities, for: user, as: :activity)
33 end
34
35 defp create_timeline_params(user) do
36 %{}
37 |> Map.put("type", ["Create", "Announce"])
38 |> Map.put("blocking_user", user)
39 |> Map.put("muting_user", user)
40 |> Map.put("user", user)
41 end
42 end