mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-23 08:36:29 +00:00
Apply all suggested changes from reviewers.
This commit is contained in:
parent
cc1b07132f
commit
2d1897e8a7
6 changed files with 30 additions and 44 deletions
|
@ -77,7 +77,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do
|
||||||
|
|
||||||
def notice(%{assigns: %{format: format}} = conn, %{"id" => id}) do
|
def notice(%{assigns: %{format: format}} = conn, %{"id" => id}) do
|
||||||
if Pleroma.Config.get([:instance, :static_fe], false) 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
|
else
|
||||||
with {_, %Activity{} = activity} <- {:activity, Activity.get_by_id_with_object(id)},
|
with {_, %Activity{} = activity} <- {:activity, Activity.get_by_id_with_object(id)},
|
||||||
{_, true} <- {:public?, Visibility.is_public?(activity)},
|
{_, 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, %User{} = user} <- User.get_or_fetch(activity.data["actor"]) do
|
||||||
{:ok, prepare_activity(user, activity)}
|
{:ok, prepare_activity(user, activity)}
|
||||||
else
|
else
|
||||||
e ->
|
{:error, reason} -> {:error, reason}
|
||||||
{:error, e}
|
_error -> {:error, "Not found"}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,9 +9,12 @@ defmodule Pleroma.Web.StaticFE.StaticFEController do
|
||||||
alias Pleroma.Web.StaticFE.ActivityRepresenter
|
alias Pleroma.Web.StaticFE.ActivityRepresenter
|
||||||
alias Pleroma.Web.StaticFE.UserRepresenter
|
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
|
with {:ok, data} <- ActivityRepresenter.represent(notice_id) do
|
||||||
context = data.object.data["context"]
|
context = data.object.data["context"]
|
||||||
activities = ActivityPub.fetch_activities_for_context(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)
|
|> Map.put(:selected, a.object.id == data.object.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
conn
|
render(conn, "conversation.html", data: data)
|
||||||
|> 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")
|
|
||||||
end
|
end
|
||||||
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
|
with {:ok, data} <- UserRepresenter.represent(username_or_id) do
|
||||||
conn
|
render(conn, "profile.html", data: data)
|
||||||
|> 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")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def show(%{path_info: ["notice", notice_id]} = conn, _params),
|
def assign_id(%{path_info: ["notice", notice_id]} = conn, _opts),
|
||||||
do: show_notice(conn, %{"notice_id" => notice_id})
|
do: assign(conn, :notice_id, notice_id)
|
||||||
|
|
||||||
def show(%{path_info: ["users", user_id]} = conn, _params),
|
def assign_id(%{path_info: ["users", user_id]} = conn, _opts),
|
||||||
do: show_user(conn, %{"username_or_id" => user_id})
|
do: assign(conn, :username_or_id, user_id)
|
||||||
|
|
||||||
def show(%{path_info: [user_id]} = conn, _params),
|
def assign_id(%{path_info: [user_id]} = conn, _opts),
|
||||||
do: show_user(conn, %{"username_or_id" => user_id})
|
do: assign(conn, :username_or_id, user_id)
|
||||||
|
|
||||||
|
def assign_id(conn, _opts), do: conn
|
||||||
|
|
||||||
# Fallback for unhandled types
|
# Fallback for unhandled types
|
||||||
def show(conn, _params) do
|
def not_found(conn, _opts) do
|
||||||
conn
|
conn
|
||||||
|> put_status(404)
|
|> put_status(404)
|
||||||
|> text("Not found")
|
|> text("Not found")
|
||||||
|
|
|
@ -11,19 +11,20 @@ defmodule Pleroma.Web.StaticFE.StaticFEView do
|
||||||
alias Pleroma.Web.Metadata.Utils
|
alias Pleroma.Web.Metadata.Utils
|
||||||
alias Pleroma.Web.Router.Helpers
|
alias Pleroma.Web.Router.Helpers
|
||||||
|
|
||||||
import Phoenix.HTML
|
use Phoenix.HTML
|
||||||
|
|
||||||
@media_types ["image", "audio", "video"]
|
@media_types ["image", "audio", "video"]
|
||||||
|
|
||||||
def emoji_for_user(%User{} = user) do
|
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.filter(fn %{"type" => t} -> t == "Emoji" end)
|
||||||
|> Enum.map(fn %{"icon" => %{"url" => url}, "name" => name} ->
|
|> Enum.map(fn %{"icon" => %{"url" => url}, "name" => name} ->
|
||||||
{String.trim(name, ":"), url}
|
{String.trim(name, ":"), url}
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_media_type(url) do
|
def fetch_media_type(%{"mediaType" => mediaType}) do
|
||||||
Utils.fetch_media_type(@media_types, url["mediaType"])
|
Utils.fetch_media_type(@media_types, mediaType)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,12 +24,9 @@ defmodule Pleroma.Web.StaticFE.UserRepresenter do
|
||||||
end
|
end
|
||||||
|
|
||||||
def represent(username_or_id) do
|
def represent(username_or_id) do
|
||||||
with %User{} = user <- User.get_cached_by_nickname_or_id(username_or_id),
|
case User.get_cached_by_nickname_or_id(username_or_id) do
|
||||||
data <- prepare_user(user) do
|
%User{} = user -> {:ok, prepare_user(user)}
|
||||||
{:ok, data}
|
nil -> {:error, "User not found"}
|
||||||
else
|
|
||||||
e ->
|
|
||||||
{:error, e}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<div class="activity" <%= if @data[:selected] do %> id="selected" <% end %>>
|
<div class="activity" <%= if @data[:selected] do %> id="selected" <% end %>>
|
||||||
<p class="pull-right">
|
<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}) %>
|
<%= render("user_card.html", %{user: @data.user}) %>
|
||||||
<div class="activity-content">
|
<div class="activity-content">
|
||||||
<%= if @data.title != "" do %>
|
<%= if @data.title != "" do %>
|
||||||
|
|
Loading…
Reference in a new issue