Browse Source

Show remote actor profiles

master
Shadowfacts 1 year ago
parent
commit
e7c19940b0
Signed by: shadowfacts GPG Key ID: 94A5AB95422746E5
5 changed files with 43 additions and 3 deletions
  1. +17
    -1
      lib/clacks_web/controllers/frontend_controller.ex
  2. +1
    -0
      lib/clacks_web/router.ex
  3. +1
    -1
      lib/clacks_web/templates/frontend/_status.html.eex
  4. +9
    -1
      lib/clacks_web/templates/frontend/profile.html.eex
  5. +15
    -0
      lib/clacks_web/views/frontend_view.ex

+ 17
- 1
lib/clacks_web/controllers/frontend_controller.ex 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]


+ 1
- 0
lib/clacks_web/router.ex 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


+ 1
- 1
lib/clacks_web/templates/frontend/_status.html.eex 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>


+ 9
- 1
lib/clacks_web/templates/frontend/profile.html.eex 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})) %>

+ 15
- 0
lib/clacks_web/views/frontend_view.ex 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


Loading…
Cancel
Save