Show remote actor profiles

This commit is contained in:
Shadowfacts 2020-04-26 14:45:51 -04:00
parent 00c51e4ad9
commit e7c19940b0
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
5 changed files with 43 additions and 3 deletions

View File

@ -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]

View File

@ -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

View File

@ -1,7 +1,7 @@
<div class="status">
<div class="status-meta">
<h2 class="status-author-nickname">
<a href="<%= @author.ap_id %>">
<a href="<%= local_actor_link(@author) %>">
<%= @author.data["preferredUsername"] %>
</a>
</h2>

View File

@ -1,5 +1,13 @@
<h1><%= @actor.data["preferredUsername"] %></h1>
<h2>@<%= @actor.data["name"] %></h2>
<h2>
<%= if @actor.local do %>
<%= display_username(@actor) %>
<% else %>
<a href="<%= @actor.ap_id %>">
<%= display_username(@actor) %>
</a>
<% end %>
</h2>
<p><%= @actor.data["summary"] %></p>
<%= render "_timeline.html", conn: @conn, statuses_with_authors: Enum.map(@statuses, &({&1, @actor})) %>

View File

@ -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