Notices should show entire thread from context.
[akkoma] / lib / pleroma / web / static_fe / static_fe_controller.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.StaticFE.StaticFEController do
6 use Pleroma.Web, :controller
7
8 alias Pleroma.Web.ActivityPub.ActivityPub
9 alias Pleroma.Web.StaticFE.ActivityRepresenter
10 alias Pleroma.Web.StaticFE.UserRepresenter
11
12 require Logger
13
14 def show_notice(conn, %{"notice_id" => notice_id}) do
15 with {:ok, data} <- ActivityRepresenter.represent(notice_id) do
16 context = data.object.data["context"]
17 activities = ActivityPub.fetch_activities_for_context(context, %{})
18
19 data =
20 for a <- Enum.reverse(activities) do
21 ActivityRepresenter.prepare_activity(data.user, a)
22 |> Map.put(:selected, a.object.id == data.object.id)
23 end
24
25 conn
26 |> put_layout(:static_fe)
27 |> put_status(200)
28 |> put_view(Pleroma.Web.StaticFE.StaticFEView)
29 |> render("conversation.html", %{data: data})
30 else
31 {:error, nil} ->
32 conn
33 |> put_status(404)
34 |> text("Not found")
35 end
36 end
37
38 def show_user(conn, %{"username_or_id" => username_or_id}) do
39 with {:ok, data} <- UserRepresenter.represent(username_or_id) do
40 conn
41 |> put_layout(:static_fe)
42 |> put_status(200)
43 |> put_view(Pleroma.Web.StaticFE.StaticFEView)
44 |> render("profile.html", %{data: data})
45 else
46 {:error, nil} ->
47 conn
48 |> put_status(404)
49 |> text("Not found")
50 end
51 end
52
53 def show(%{path_info: ["notice", notice_id]} = conn, _params),
54 do: show_notice(conn, %{"notice_id" => notice_id})
55
56 def show(%{path_info: ["users", user_id]} = conn, _params),
57 do: show_user(conn, %{"username_or_id" => user_id})
58
59 def show(%{path_info: [user_id]} = conn, _params),
60 do: show_user(conn, %{"username_or_id" => user_id})
61
62 # Fallback for unhandled types
63 def show(conn, _params) do
64 conn
65 |> put_status(404)
66 |> text("Not found")
67 end
68 end