Compare commits

..

2 commits

Author SHA1 Message Date
f43b4bd038
Remove timex 2025-06-17 12:56:46 +02:00
10756907dc
Add actor/show.html.heex 2025-06-17 12:56:08 +02:00
4 changed files with 83 additions and 70 deletions

View file

@ -1,77 +1,92 @@
defmodule NullaWeb.UserHTML do
defmodule NullaWeb.ActorHTML do
use NullaWeb, :html
embed_templates "templates/user/*"
embed_templates "templates/actor/*"
def format_birthdate(date) do
formatted = Date.to_string(date) |> String.replace("-", "/")
age = Timex.diff(Timex.today(), date, :years)
today = Date.utc_today()
age =
today.year - date.year -
if {today.month, today.day} < {date.month, date.day}, do: 1, else: 0
"#{formatted} (#{age} years old)"
end
def format_registration_date(date) do
now = Timex.now()
now = Date.utc_today()
formatted = Date.to_string(date) |> String.replace("-", "/")
diff = Timex.diff(now, date, :days)
diff_days = Date.diff(now, date)
relative =
cond do
diff == 0 ->
"today"
cond do
diff_days == 0 ->
"#{formatted} (today)"
diff == 1 ->
"1 day ago"
diff_days == 1 ->
"#{formatted} (1 day ago)"
diff < 30 ->
"#{diff} days ago"
diff_days < 30 ->
"#{formatted} (#{diff_days} days ago)"
diff < 365 ->
months = Timex.diff(now, date, :months)
if months == 1, do: "1 month ago", else: "#{months} months ago"
diff_days < 365 ->
year_diff = now.year - date.year
month_diff = now.month - date.month
day_correction = if now.day < date.day, do: -1, else: 0
months = year_diff * 12 + month_diff + day_correction
if months == 1 do
"#{formatted} (1 month ago)"
else
"#{formatted} (#{months} months ago)"
end
true ->
years = Timex.diff(now, date, :years)
if years == 1, do: "1 year ago", else: "#{years} years ago"
end
"#{formatted} (#{relative})"
true ->
year_diff = now.year - date.year
years = if {now.month, now.day} < {date.month, date.day}, do: year_diff - 1, else: year_diff
if years == 1 do
"#{formatted} (1 year ago)"
else
"#{formatted} (#{years} years ago)"
end
end
end
def format_note_datetime(datetime) do
Timex.format!(datetime, "{0D} {Mfull} {YYYY}, {h24}:{m}", :strftime)
Calendar.strftime(datetime, "%d %B %Y, %H:%M")
end
def format_note_datetime_diff(datetime) do
now = Timex.now()
diff = Timex.diff(now, datetime, :seconds)
now = DateTime.utc_now()
diff_seconds = DateTime.diff(now, datetime)
cond do
diff < 60 ->
diff_seconds < 60 ->
"now"
diff < 3600 ->
minutes = div(diff, 60)
diff_seconds < 3600 ->
minutes = div(diff_seconds, 60)
"#{minutes}m ago"
diff < 86400 ->
hours = div(diff, 3600)
diff_seconds < 86400 ->
hours = div(diff_seconds, 3600)
"#{hours}h ago"
diff < 518_400 ->
days = div(diff, 86400)
diff_seconds < 604_800 ->
days = div(diff_seconds, 86400)
"#{days}d ago"
diff < 2_419_200 ->
weeks = div(diff, 604_800)
diff_seconds < 2_592_000 ->
weeks = div(diff_seconds, 604_800)
"#{weeks}w ago"
diff < 28_512_000 ->
months = Timex.diff(now, datetime, :months)
diff_seconds < 31_536_000 ->
months = div(diff_seconds, 2_592_000)
"#{months}mo ago"
true ->
years = Timex.diff(now, datetime, :years)
years = div(diff_seconds, 31_536_000)
"#{years}y ago"
end
end

View file

@ -16,10 +16,10 @@
</div>
<div class="relative border border-gray-300 shadow-md mt-5 rounded-t-xl overflow-hidden">
<div class="relative w-full aspect-[3/1]">
<img src={"/files/#{@user.banner}"} class="w-full h-full object-cover" />
<img src={@actor.image["url"]} class="w-full h-full object-cover" />
<div class="absolute inset-0 flex items-end justify-between px-4 pb-2 pointer-events-none">
<img
src={"/files/#{@user.avatar}"}
src={@actor.icon["url"]}}
class="translate-y-1/2 rounded-full border-4 border-white w-[8.33vw] h-[8.33vw] min-w-[80px] min-h-[80px] max-w-[160px] max-h-[160px] pointer-events-auto"
/>
<button class="px-8 py-2 rounded-full text-sm font-semibold border transition bg-black text-white border-black hover:bg-gray-900 pointer-events-auto">
@ -28,33 +28,33 @@
</div>
</div>
<div class="mt-[4.5vw] px-4 flex flex-col">
<span class="text-xl font-bold">{@user.realname}</span>
<span class="text-gray-500">@{@user.username}@{@domain}</span>
<span class="text-xl font-bold">{@actor.name}</span>
<span class="text-gray-500">@{@actor.preferredUsername}@{@actor.domain}</span>
<div class="text-sm pt-2">
<p>{@user.bio}</p>
<p>{@actor.summary}</p>
</div>
<dl class="mt-2 text-sm text-gray-700 grid grid-cols-[auto,1fr] gap-x-2 gap-y-1 items-center">
<%= if @user.location do %>
<%= if @actor.vcard_Address do %>
<dt class="flex items-center gap-2">
<.icon name="hero-map-pin" class="mt-0.5 h-5 w-5 flex-none" />
</dt>
<dd>{@user.location}</dd>
<dd>{@actor.vcard_Address}</dd>
<% end %>
<%= if @user.birthday do %>
<%= if @actor.vcard_bday do %>
<dt class="flex items-center gap-2">
<.icon name="hero-cake" class="mt-0.5 h-5 w-5 flex-none" />
</dt>
<dd>{format_birthdate(@user.birthday)}</dd>
<dd>{format_birthdate(@actor.vcard_bday)}</dd>
<% end %>
<dt class="flex items-center gap-2">
<.icon name="hero-calendar" class="mt-0.5 h-5 w-5 flex-none" />
</dt>
<dd>{format_registration_date(@user.inserted_at)}</dd>
<dd>{format_registration_date(@actor.published)}</dd>
</dl>
<%= if @user.fields do %>
<%= if @actor.attachment do %>
<dl class="mt-5 grid grid-cols-[max-content,1fr] gap-x-5 gap-y-2 items-center">
<%= for {key, value} <- @user.fields do %>
<dt>{key}</dt>
<%= for %{"type" => "PropertyValue", "name" => name, "value" => value} <- @actor.attachment do %>
<dt>{name}</dt>
<dd>
<%= if Regex.match?(~r{://}, value) do %>
<a href={value} class="text-[#1D9BF0]">{Regex.replace(~r{^\w+://}, value, "")}</a>
@ -66,30 +66,30 @@
</dl>
<% end %>
<div class="flex mt-5 gap-3">
<a href={~p"/@#{@user.username}"}>{length(@notes)} Posts</a>
<a href={~p"/@#{@user.username}/following"}>{@following} Following</a>
<a href={~p"/@#{@user.username}/followers"}>{@followers} Followers</a>
<a href={~p"/@#{@actor.preferredUsername}"}>{length(@notes)} Posts</a>
<a href={~p"/@#{@actor.preferredUsername}/following"}>{@following} Following</a>
<a href={~p"/@#{@actor.preferredUsername}/followers"}>{@followers} Followers</a>
</div>
</div>
<div class="flex justify-between px-20 py-2 mt-5 border-y border-gray-300">
<a href={~p"/@#{@user.username}/featured"}>Featured</a>
<a href={~p"/@#{@user.username}"}>Posts</a>
<a href={~p"/@#{@user.username}/with_replies"}>Posts and replies</a>
<a href={~p"/@#{@user.username}/media"}>Media</a>
<a href={~p"/@#{@actor.preferredUsername}/featured"}>Featured</a>
<a href={~p"/@#{@actor.preferredUsername}"}>Posts</a>
<a href={~p"/@#{@actor.preferredUsername}/with_replies"}>Posts and replies</a>
<a href={~p"/@#{@actor.preferredUsername}/media"}>Media</a>
</div>
<div>
<%= for note <- @notes do %>
<div class="p-4 border-b border-gray-300">
<div class="flex items-start space-x-4">
<img src={"/files/#{@user.avatar}"} class="rounded-full w-[58px] h-[58px]" />
<img src={@actor.icon["url"]}} class="rounded-full w-[58px] h-[58px]" />
<div class="flex-1">
<div class="flex justify-between items-start">
<div class="flex items-center space-x-2">
<span class="font-semibold text-gray-900 text-sm">
{@user.realname}
{@actor.name}
</span>
<span class="text-gray-500 text-sm">
@{@user.username}@{@domain}
@{@actor.preferredUsername}@{@actor.domain}
</span>
</div>
<div class="flex items-center space-x-2 text-sm text-gray-500">

View file

@ -24,13 +24,12 @@ defmodule NullaWeb.ActorController do
|> send_resp(200, Jason.encode!(ActivityPub.actor(actor)))
else
notes = Note.get_latest_notes(actor.id)
following = Utils.count_following_by_username!(actor.preferredUsername)
followers = Utils.count_followers_by_username!(actor.preferredUsername)
following = 0
followers = 0
render(
conn,
:show,
domain: domain,
actor: actor,
notes: notes,
following: following,

View file

@ -43,7 +43,6 @@ defmodule Nulla.MixProject do
{:phoenix_live_dashboard, "~> 0.8.3"},
{:esbuild, "~> 0.8", runtime: Mix.env() == :dev},
{:tailwind, "~> 0.2.0", runtime: Mix.env() == :dev},
{:timex, "~> 3.7"},
{:heroicons,
github: "tailwindlabs/heroicons",
tag: "v2.1.1",