diff --git a/lib/clacks_web/controllers/frontend_controller.ex b/lib/clacks_web/controllers/frontend_controller.ex index 2a9bd68..3f373ed 100644 --- a/lib/clacks_web/controllers/frontend_controller.ex +++ b/lib/clacks_web/controllers/frontend_controller.ex @@ -119,7 +119,7 @@ defmodule ClacksWeb.FrontendController do case User.get_by_username(username) do nil -> - put_status(conn, 404) + resp(conn, 404, "Not Found") user -> user = Repo.preload(user, :actor) @@ -132,6 +132,22 @@ defmodule ClacksWeb.FrontendController do end end + def actor(conn, %{"id" => id} = params) do + current_user = conn.assigns[:user] |> Repo.preload(:actor) + + case Repo.get(Actor, id) do + nil -> + resp(conn, 404, "Not Found") + + actor -> + render(conn, "profile.html", %{ + current_user: current_user, + actor: actor, + statuses: actor_statuses(actor, params, only_public: true) + }) + end + end + def search(conn, %{"q" => q}) when is_binary(q) do current_user = conn.assigns[:user] diff --git a/lib/clacks_web/router.ex b/lib/clacks_web/router.ex index bcdf092..4dc04ac 100644 --- a/lib/clacks_web/router.ex +++ b/lib/clacks_web/router.ex @@ -60,6 +60,7 @@ defmodule ClacksWeb.Router do post "/post", FrontendController, :post_status get "/status/:id/reply", FrontendController, :reply get "/search", FrontendController, :search + get "/actors/:id", FrontendController, :actor end scope "/", ClacksWeb do diff --git a/lib/clacks_web/templates/frontend/_status.html.eex b/lib/clacks_web/templates/frontend/_status.html.eex index de1d726..20886b3 100644 --- a/lib/clacks_web/templates/frontend/_status.html.eex +++ b/lib/clacks_web/templates/frontend/_status.html.eex @@ -1,7 +1,7 @@

- + <%= @author.data["preferredUsername"] %>

diff --git a/lib/clacks_web/templates/frontend/profile.html.eex b/lib/clacks_web/templates/frontend/profile.html.eex index 634fed8..28a0af3 100644 --- a/lib/clacks_web/templates/frontend/profile.html.eex +++ b/lib/clacks_web/templates/frontend/profile.html.eex @@ -1,5 +1,13 @@

<%= @actor.data["preferredUsername"] %>

-

@<%= @actor.data["name"] %>

+

+ <%= if @actor.local do %> + <%= display_username(@actor) %> + <% else %> + + <%= display_username(@actor) %> + + <% end %> +

<%= @actor.data["summary"] %>

<%= render "_timeline.html", conn: @conn, statuses_with_authors: Enum.map(@statuses, &({&1, @actor})) %> diff --git a/lib/clacks_web/views/frontend_view.ex b/lib/clacks_web/views/frontend_view.ex index 53a98af..0444d37 100644 --- a/lib/clacks_web/views/frontend_view.ex +++ b/lib/clacks_web/views/frontend_view.ex @@ -1,6 +1,8 @@ defmodule ClacksWeb.FrontendView do use ClacksWeb, :view alias Clacks.{Actor, Activity} + alias ClacksWeb.Router.Helpers, as: Routes + alias ClacksWeb.Endpoint @spec display_username(actor :: Actor.t()) :: String.t() @@ -13,6 +15,13 @@ defmodule ClacksWeb.FrontendView do "@" <> name <> "@" <> host end + def local_actor_link(%Actor{local: true, ap_id: ap_id}), do: ap_id + + def local_actor_link(%Actor{local: false, id: id}), + do: Routes.frontend_path(Endpoint, :actor, id) + + @spec display_timestamp(str :: String.t()) :: String.t() + def display_timestamp(str) when is_binary(str) do display_timestamp(Timex.parse!(str, "{ISO:Extended}")) end @@ -42,6 +51,9 @@ defmodule ClacksWeb.FrontendView do end end + @spec prev_page_path(conn :: Plug.Conn.t(), [Activity.t() | {Activity.t(), Actor.t()}]) :: + String.t() + def prev_page_path(conn, activities) do if Map.has_key?(conn.query_params, "max_id") do Phoenix.Controller.current_path(conn, %{ @@ -52,6 +64,9 @@ defmodule ClacksWeb.FrontendView do end end + @spec next_page_path(conn :: Plug.Conn.t(), [Activity.t() | {Activity.t(), Actor.t()}]) :: + String.t() + def next_page_path(conn, activities) do if length(activities) < 20 do nil