Make many of the improvements suggested in review.

This commit is contained in:
Phil Hagelberg 2019-11-04 22:02:10 -08:00
parent e8bee35578
commit 8969c5522d
6 changed files with 25 additions and 20 deletions

View file

@ -3,17 +3,24 @@
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Plugs.StaticFEPlug do defmodule Pleroma.Plugs.StaticFEPlug do
import Plug.Conn
alias Pleroma.Web.StaticFE.StaticFEController
def init(options), do: options def init(options), do: options
def accepts_html?({"accept", a}), do: String.contains?(a, "text/html")
def accepts_html?({_, _}), do: false
def call(conn, _) do def call(conn, _) do
with true <- Pleroma.Config.get([:instance, :static_fe], false), if enabled?() and accepts_html?(conn) do
{_, _} <- Enum.find(conn.req_headers, &accepts_html?/1) do conn
Pleroma.Web.StaticFE.StaticFEController.call(conn, :show) |> StaticFEController.call(:show)
|> halt()
else else
_ -> conn conn
end end
end end
defp enabled?, do: Pleroma.Config.get([:instance, :static_fe], false)
defp accepts_html?(conn) do
conn |> get_req_header("accept") |> List.first() |> String.contains?("text/html")
end
end end

View file

@ -58,28 +58,24 @@ defmodule Pleroma.Web.StaticFE.StaticFEController do
end end
def show(%{assigns: %{notice_id: notice_id}} = conn, _params) do def show(%{assigns: %{notice_id: notice_id}} = conn, _params) do
instance_name = Pleroma.Config.get([:instance, :name], "Pleroma")
activity = Activity.get_by_id_with_object(notice_id) activity = Activity.get_by_id_with_object(notice_id)
context = activity.object.data["context"]
activities = ActivityPub.fetch_activities_for_context(context, %{})
timeline = timeline =
for a <- Enum.reverse(activities) do activity.object.data["context"]
represent(a, a.object.id == activity.object.id) |> ActivityPub.fetch_activities_for_context(%{})
end |> Enum.reverse()
|> Enum.map(&represent(&1, &1.object.id == activity.object.id))
render(conn, "conversation.html", %{activities: timeline, instance_name: instance_name}) render(conn, "conversation.html", %{activities: timeline})
end end
def show(%{assigns: %{username_or_id: username_or_id}} = conn, _params) do def show(%{assigns: %{username_or_id: username_or_id}} = conn, _params) do
instance_name = Pleroma.Config.get([:instance, :name], "Pleroma")
%User{} = user = User.get_cached_by_nickname_or_id(username_or_id) %User{} = user = User.get_cached_by_nickname_or_id(username_or_id)
timeline = timeline =
ActivityPub.fetch_user_activities(user, nil, %{}) ActivityPub.fetch_user_activities(user, nil, %{})
|> Enum.map(&represent/1) |> Enum.map(&represent/1)
render(conn, "profile.html", %{user: user, timeline: timeline, instance_name: instance_name}) render(conn, "profile.html", %{user: user, timeline: timeline})
end end
def assign_id(%{path_info: ["notice", notice_id]} = conn, _opts), def assign_id(%{path_info: ["notice", notice_id]} = conn, _opts),

View file

@ -36,4 +36,6 @@ defmodule Pleroma.Web.StaticFE.StaticFEView do
{:ok, date, _} = DateTime.from_iso8601(date) {:ok, date, _} = DateTime.from_iso8601(date)
Strftime.strftime!(date, "%Y/%m/%d %l:%M:%S %p UTC") Strftime.strftime!(date, "%Y/%m/%d %l:%M:%S %p UTC")
end end
def instance_name, do: Pleroma.Config.get([:instance, :name], "Pleroma")
end end

View file

@ -4,7 +4,7 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1,minimal-ui" /> <meta name="viewport" content="width=device-width,initial-scale=1,minimal-ui" />
<title> <title>
<%= Application.get_env(:pleroma, :instance)[:name] %> <%= Pleroma.Config.get([:instance, :name]) %>
</title> </title>
<link rel="stylesheet" href="/static/static-fe.css"> <link rel="stylesheet" href="/static/static-fe.css">
</head> </head>

View file

@ -1,5 +1,5 @@
<header> <header>
<h1><%= link @instance_name, to: "/" %></h1> <h1><%= link instance_name(), to: "/" %></h1>
</header> </header>
<main> <main>

View file

@ -1,5 +1,5 @@
<header> <header>
<h1><%= link @instance_name, to: "/" %></h1> <h1><%= link instance_name(), to: "/" %></h1>
<h3> <h3>
<form class="pull-right collapse" method="POST" action="<%= Helpers.util_path(@conn, :remote_subscribe) %>"> <form class="pull-right collapse" method="POST" action="<%= Helpers.util_path(@conn, :remote_subscribe) %>">