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, %{})
|> 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")
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