mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-12-24 18:15:19 +00:00
Apply all suggested changes from reviewers.
This commit is contained in:
parent
cc1b07132f
commit
2d1897e8a7
|
@ -77,7 +77,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do
|
|||
|
||||
def notice(%{assigns: %{format: format}} = conn, %{"id" => id}) do
|
||||
if Pleroma.Config.get([:instance, :static_fe], false) do
|
||||
Pleroma.Web.StaticFE.StaticFEController.show(conn, %{"notice_id" => id})
|
||||
Pleroma.Web.StaticFE.StaticFEController.call(conn, :show_notice)
|
||||
else
|
||||
with {_, %Activity{} = activity} <- {:activity, Activity.get_by_id_with_object(id)},
|
||||
{_, true} <- {:public?, Visibility.is_public?(activity)},
|
||||
|
|
|
@ -62,8 +62,8 @@ defmodule Pleroma.Web.StaticFE.ActivityRepresenter do
|
|||
{:ok, %User{} = user} <- User.get_or_fetch(activity.data["actor"]) do
|
||||
{:ok, prepare_activity(user, activity)}
|
||||
else
|
||||
e ->
|
||||
{:error, e}
|
||||
{:error, reason} -> {:error, reason}
|
||||
_error -> {:error, "Not found"}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,9 +9,12 @@ defmodule Pleroma.Web.StaticFE.StaticFEController do
|
|||
alias Pleroma.Web.StaticFE.ActivityRepresenter
|
||||
alias Pleroma.Web.StaticFE.UserRepresenter
|
||||
|
||||
require Logger
|
||||
plug(:put_layout, :static_fe)
|
||||
plug(:put_view, Pleroma.Web.StaticFE.StaticFEView)
|
||||
plug(:assign_id)
|
||||
action_fallback(:not_found)
|
||||
|
||||
def show_notice(conn, %{"notice_id" => notice_id}) do
|
||||
def show_notice(%{assigns: %{notice_id: notice_id}} = conn, _params) do
|
||||
with {:ok, data} <- ActivityRepresenter.represent(notice_id) do
|
||||
context = data.object.data["context"]
|
||||
activities = ActivityPub.fetch_activities_for_context(context, %{})
|
||||
|
@ -22,45 +25,29 @@ defmodule Pleroma.Web.StaticFE.StaticFEController do
|
|||
|> Map.put(:selected, a.object.id == data.object.id)
|
||||
end
|
||||
|
||||
conn
|
||||
|> put_layout(:static_fe)
|
||||
|> put_status(200)
|
||||
|> put_view(Pleroma.Web.StaticFE.StaticFEView)
|
||||
|> render("conversation.html", %{data: data})
|
||||
else
|
||||
{:error, nil} ->
|
||||
conn
|
||||
|> put_status(404)
|
||||
|> text("Not found")
|
||||
render(conn, "conversation.html", data: data)
|
||||
end
|
||||
end
|
||||
|
||||
def show_user(conn, %{"username_or_id" => username_or_id}) do
|
||||
def show_user(%{assigns: %{username_or_id: username_or_id}} = conn, _params) do
|
||||
with {:ok, data} <- UserRepresenter.represent(username_or_id) do
|
||||
conn
|
||||
|> put_layout(:static_fe)
|
||||
|> put_status(200)
|
||||
|> put_view(Pleroma.Web.StaticFE.StaticFEView)
|
||||
|> render("profile.html", %{data: data})
|
||||
else
|
||||
{:error, nil} ->
|
||||
conn
|
||||
|> put_status(404)
|
||||
|> text("Not found")
|
||||
render(conn, "profile.html", data: data)
|
||||
end
|
||||
end
|
||||
|
||||
def show(%{path_info: ["notice", notice_id]} = conn, _params),
|
||||
do: show_notice(conn, %{"notice_id" => notice_id})
|
||||
def assign_id(%{path_info: ["notice", notice_id]} = conn, _opts),
|
||||
do: assign(conn, :notice_id, notice_id)
|
||||
|
||||
def show(%{path_info: ["users", user_id]} = conn, _params),
|
||||
do: show_user(conn, %{"username_or_id" => user_id})
|
||||
def assign_id(%{path_info: ["users", user_id]} = conn, _opts),
|
||||
do: assign(conn, :username_or_id, user_id)
|
||||
|
||||
def show(%{path_info: [user_id]} = conn, _params),
|
||||
do: show_user(conn, %{"username_or_id" => user_id})
|
||||
def assign_id(%{path_info: [user_id]} = conn, _opts),
|
||||
do: assign(conn, :username_or_id, user_id)
|
||||
|
||||
def assign_id(conn, _opts), do: conn
|
||||
|
||||
# Fallback for unhandled types
|
||||
def show(conn, _params) do
|
||||
def not_found(conn, _opts) do
|
||||
conn
|
||||
|> put_status(404)
|
||||
|> text("Not found")
|
||||
|
|
|
@ -11,19 +11,20 @@ defmodule Pleroma.Web.StaticFE.StaticFEView do
|
|||
alias Pleroma.Web.Metadata.Utils
|
||||
alias Pleroma.Web.Router.Helpers
|
||||
|
||||
import Phoenix.HTML
|
||||
use Phoenix.HTML
|
||||
|
||||
@media_types ["image", "audio", "video"]
|
||||
|
||||
def emoji_for_user(%User{} = user) do
|
||||
(user.source_data["tag"] || [])
|
||||
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(url) do
|
||||
Utils.fetch_media_type(@media_types, url["mediaType"])
|
||||
def fetch_media_type(%{"mediaType" => mediaType}) do
|
||||
Utils.fetch_media_type(@media_types, mediaType)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,12 +24,9 @@ defmodule Pleroma.Web.StaticFE.UserRepresenter do
|
|||
end
|
||||
|
||||
def represent(username_or_id) do
|
||||
with %User{} = user <- User.get_cached_by_nickname_or_id(username_or_id),
|
||||
data <- prepare_user(user) do
|
||||
{:ok, data}
|
||||
else
|
||||
e ->
|
||||
{:error, e}
|
||||
case User.get_cached_by_nickname_or_id(username_or_id) do
|
||||
%User{} = user -> {:ok, prepare_user(user)}
|
||||
nil -> {:error, "User not found"}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<div class="activity" <%= if @data[:selected] do %> id="selected" <% end %>>
|
||||
<p class="pull-right">
|
||||
<a href="<%= @data.link %>" class="activity-link"><%= @data.published %></a></p>
|
||||
<%= link @data.published, to: @data.link, class: "activity-link" %>
|
||||
</p>
|
||||
<%= render("user_card.html", %{user: @data.user}) %>
|
||||
<div class="activity-content">
|
||||
<%= if @data.title != "" do %>
|
||||
|
|
Loading…
Reference in a new issue