Page MenuHomePhorge

No OneTemporary

Size
8 KB
Referenced Files
None
Subscribers
None
diff --git a/lib/pleroma/plugs/static_fe_plug.ex b/lib/pleroma/plugs/static_fe_plug.ex
index dcbabc9df..2af45e52a 100644
--- a/lib/pleroma/plugs/static_fe_plug.ex
+++ b/lib/pleroma/plugs/static_fe_plug.ex
@@ -1,19 +1,26 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Plugs.StaticFEPlug do
- def init(options), do: options
+ import Plug.Conn
+ alias Pleroma.Web.StaticFE.StaticFEController
- def accepts_html?({"accept", a}), do: String.contains?(a, "text/html")
- def accepts_html?({_, _}), do: false
+ def init(options), do: options
def call(conn, _) do
- with true <- Pleroma.Config.get([:instance, :static_fe], false),
- {_, _} <- Enum.find(conn.req_headers, &accepts_html?/1) do
- Pleroma.Web.StaticFE.StaticFEController.call(conn, :show)
+ if enabled?() and accepts_html?(conn) do
+ conn
+ |> StaticFEController.call(:show)
+ |> halt()
else
- _ -> conn
+ conn
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
diff --git a/lib/pleroma/web/static_fe/static_fe_controller.ex b/lib/pleroma/web/static_fe/static_fe_controller.ex
index 96e30f317..a00c6db4f 100644
--- a/lib/pleroma/web/static_fe/static_fe_controller.ex
+++ b/lib/pleroma/web/static_fe/static_fe_controller.ex
@@ -1,92 +1,88 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.StaticFE.StaticFEController do
use Pleroma.Web, :controller
alias Pleroma.Activity
alias Pleroma.Object
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.Router.Helpers
plug(:put_layout, :static_fe)
plug(:put_view, Pleroma.Web.StaticFE.StaticFEView)
plug(:assign_id)
defp get_title(%Object{data: %{"name" => name}}) when is_binary(name),
do: name
defp get_title(%Object{data: %{"summary" => summary}}) when is_binary(summary),
do: summary
defp get_title(_), do: nil
def get_counts(%Activity{} = activity) do
%Object{data: data} = Object.normalize(activity)
%{
likes: data["like_count"] || 0,
replies: data["repliesCount"] || 0,
announces: data["announcement_count"] || 0
}
end
def represent(%Activity{} = activity), do: represent(activity, false)
def represent(%Activity{object: %Object{data: data}} = activity, selected) do
{:ok, user} = User.get_or_fetch(activity.object.data["actor"])
link =
case user.local do
true -> Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, activity)
_ -> data["url"] || data["external_url"] || data["id"]
end
%{
user: user,
title: get_title(activity.object),
content: data["content"] || nil,
attachment: data["attachment"],
link: link,
published: data["published"],
sensitive: data["sensitive"],
selected: selected,
counts: get_counts(activity)
}
end
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)
- context = activity.object.data["context"]
- activities = ActivityPub.fetch_activities_for_context(context, %{})
-
timeline =
- for a <- Enum.reverse(activities) do
- represent(a, a.object.id == activity.object.id)
- end
+ activity.object.data["context"]
+ |> ActivityPub.fetch_activities_for_context(%{})
+ |> 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
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)
timeline =
ActivityPub.fetch_user_activities(user, nil, %{})
|> 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
def assign_id(%{path_info: ["notice", notice_id]} = conn, _opts),
do: assign(conn, :notice_id, notice_id)
def assign_id(%{path_info: ["users", user_id]} = conn, _opts),
do: assign(conn, :username_or_id, user_id)
def assign_id(conn, _opts), do: conn
end
diff --git a/lib/pleroma/web/static_fe/static_fe_view.ex b/lib/pleroma/web/static_fe/static_fe_view.ex
index 160261af9..5612a06bb 100644
--- a/lib/pleroma/web/static_fe/static_fe_view.ex
+++ b/lib/pleroma/web/static_fe/static_fe_view.ex
@@ -1,39 +1,41 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.StaticFE.StaticFEView do
use Pleroma.Web, :view
alias Calendar.Strftime
alias Pleroma.Emoji.Formatter
alias Pleroma.User
alias Pleroma.Web.Endpoint
alias Pleroma.Web.Gettext
alias Pleroma.Web.MediaProxy
alias Pleroma.Formatter
alias Pleroma.Web.Metadata.Utils
alias Pleroma.Web.Router.Helpers
use Phoenix.HTML
@media_types ["image", "audio", "video"]
def emoji_for_user(%User{} = user) do
user.source_data
|> Map.get("tag", [])
|> Enum.filter(fn %{"type" => t} -> t == "Emoji" end)
|> Enum.map(fn %{"icon" => %{"url" => url}, "name" => name} ->
{String.trim(name, ":"), url}
end)
end
def fetch_media_type(%{"mediaType" => mediaType}) do
Utils.fetch_media_type(@media_types, mediaType)
end
def format_date(date) do
{:ok, date, _} = DateTime.from_iso8601(date)
Strftime.strftime!(date, "%Y/%m/%d %l:%M:%S %p UTC")
end
+
+ def instance_name, do: Pleroma.Config.get([:instance, :name], "Pleroma")
end
diff --git a/lib/pleroma/web/templates/layout/static_fe.html.eex b/lib/pleroma/web/templates/layout/static_fe.html.eex
index 62b59f17c..4b889bb19 100644
--- a/lib/pleroma/web/templates/layout/static_fe.html.eex
+++ b/lib/pleroma/web/templates/layout/static_fe.html.eex
@@ -1,16 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1,minimal-ui" />
<title>
- <%= Application.get_env(:pleroma, :instance)[:name] %>
+ <%= Pleroma.Config.get([:instance, :name]) %>
</title>
<link rel="stylesheet" href="/static/static-fe.css">
</head>
<body>
<div class="container">
<%= render @view_module, @view_template, assigns %>
</div>
</body>
</html>
diff --git a/lib/pleroma/web/templates/static_fe/static_fe/conversation.html.eex b/lib/pleroma/web/templates/static_fe/static_fe/conversation.html.eex
index 7ac4a9e5f..2acd84828 100644
--- a/lib/pleroma/web/templates/static_fe/static_fe/conversation.html.eex
+++ b/lib/pleroma/web/templates/static_fe/static_fe/conversation.html.eex
@@ -1,11 +1,11 @@
<header>
- <h1><%= link @instance_name, to: "/" %></h1>
+ <h1><%= link instance_name(), to: "/" %></h1>
</header>
<main>
<div class="conversation">
<%= for activity <- @activities do %>
<%= render("_notice.html", activity) %>
<% end %>
</div>
</main>
diff --git a/lib/pleroma/web/templates/static_fe/static_fe/profile.html.eex b/lib/pleroma/web/templates/static_fe/static_fe/profile.html.eex
index 9b3d0509e..fa3df3b4e 100644
--- a/lib/pleroma/web/templates/static_fe/static_fe/profile.html.eex
+++ b/lib/pleroma/web/templates/static_fe/static_fe/profile.html.eex
@@ -1,22 +1,22 @@
<header>
- <h1><%= link @instance_name, to: "/" %></h1>
+ <h1><%= link instance_name(), to: "/" %></h1>
<h3>
<form class="pull-right collapse" method="POST" action="<%= Helpers.util_path(@conn, :remote_subscribe) %>">
<input type="hidden" name="nickname" value="<%= @user.nickname %>">
<input type="hidden" name="profile" value="">
<button type="submit" class="collapse">Remote follow</button>
</form>
<%= raw Formatter.emojify(@user.name, emoji_for_user(@user)) %> |
<%= link "@#{@user.nickname}@#{Endpoint.host()}", to: User.profile_url(@user) %>
</h3>
<p><%= raw @user.bio %></p>
</header>
<main>
<div class="activity-stream">
<%= for activity <- @timeline do %>
<%= render("_notice.html", Map.put(activity, :selected, false)) %>
<% end %>
</div>
</main>

File Metadata

Mime Type
text/x-diff
Expires
Fri, Sep 18, 11:03 PM (4 h, 50 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1768420
Default Alt Text
(8 KB)

Event Timeline