Update
This commit is contained in:
parent
3a57d74357
commit
df548a4943
12 changed files with 137 additions and 179 deletions
|
@ -18,33 +18,37 @@ defmodule NullaWeb.ActorHTML do
|
|||
def format_registration_date(date) do
|
||||
now = Date.utc_today()
|
||||
formatted = Date.to_string(date) |> String.replace("-", "/")
|
||||
|
||||
|
||||
diff_days = Date.diff(now, date)
|
||||
|
||||
|
||||
cond do
|
||||
diff_days == 0 ->
|
||||
"#{formatted} (today)"
|
||||
|
||||
|
||||
diff_days == 1 ->
|
||||
"#{formatted} (1 day ago)"
|
||||
|
||||
|
||||
diff_days < 30 ->
|
||||
"#{formatted} (#{diff_days} days 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 ->
|
||||
year_diff = now.year - date.year
|
||||
years = if {now.month, now.day} < {date.month, date.day}, do: year_diff - 1, else: year_diff
|
||||
|
||||
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
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
<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={@actor.icon["url"]}}
|
||||
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">
|
||||
|
@ -81,7 +82,7 @@
|
|||
<%= for note <- @notes do %>
|
||||
<div class="p-4 border-b border-gray-300">
|
||||
<div class="flex items-start space-x-4">
|
||||
<img src={@actor.icon["url"]}} 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">
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
defmodule NullaWeb.FollowController do
|
||||
use NullaWeb, :controller
|
||||
alias Nulla.ActivityPub
|
||||
alias Nulla.Utils
|
||||
alias Nulla.Models.Actor
|
||||
alias Nulla.Models.Relation
|
||||
alias Nulla.Models.InstanceSettings
|
||||
|
||||
def following(conn, %{"username" => username, "page" => page_param}) do
|
||||
instance_settings = InstanceSettings.get_instance_settings!()
|
||||
domain = instance_settings.domain
|
||||
offset = instance_settings.offset
|
||||
limit = instance_settings.limit
|
||||
actor = Actor.get_actor(username, domain)
|
||||
total = Utils.count_following_by_username!(actor.preferredUsername)
|
||||
total = Relation.count_following(actor.id)
|
||||
|
||||
page =
|
||||
case Integer.parse(page_param) do
|
||||
|
@ -18,30 +18,30 @@ defmodule NullaWeb.FollowController do
|
|||
_ -> 1
|
||||
end
|
||||
|
||||
following_list = Utils.get_following_users_by_username!(actor.preferredUsername, page)
|
||||
following_list = Relation.get_following(actor.id, page, limit)
|
||||
|
||||
conn
|
||||
|> put_resp_content_type("application/activity+json")
|
||||
|> json(ActivityPub.following(domain, actor, total, following_list, page, offset))
|
||||
|> json(ActivityPub.following(actor, total, following_list, page, limit))
|
||||
end
|
||||
|
||||
def following(conn, %{"username" => username}) do
|
||||
instance_settings = InstanceSettings.get_instance_settings!()
|
||||
domain = instance_settings.domain
|
||||
actor = Actor.get_actor(username, domain)
|
||||
total = Utils.count_following_by_username!(actor.preferredUsername)
|
||||
total = Relation.count_following(actor.id)
|
||||
|
||||
conn
|
||||
|> put_resp_content_type("application/activity+json")
|
||||
|> json(ActivityPub.following(domain, actor, total))
|
||||
|> json(ActivityPub.following(actor, total))
|
||||
end
|
||||
|
||||
def followers(conn, %{"username" => username, "page" => page_param}) do
|
||||
instance_settings = InstanceSettings.get_instance_settings!()
|
||||
domain = instance_settings.domain
|
||||
offset = instance_settings.offset
|
||||
limit = instance_settings.limit
|
||||
actor = Actor.get_actor(username, domain)
|
||||
total = Utils.count_followers_by_username!(actor.preferredUsername)
|
||||
total = Relation.count_followers(actor.id)
|
||||
|
||||
page =
|
||||
case Integer.parse(page_param) do
|
||||
|
@ -49,21 +49,21 @@ defmodule NullaWeb.FollowController do
|
|||
_ -> 1
|
||||
end
|
||||
|
||||
followers_list = Utils.get_followers_by_username!(actor.preferredUsername, page)
|
||||
followers_list = Relation.get_followers(actor.id, page, limit)
|
||||
|
||||
conn
|
||||
|> put_resp_content_type("application/activity+json")
|
||||
|> json(ActivityPub.followers(domain, actor, total, followers_list, page, offset))
|
||||
|> json(ActivityPub.followers(actor, total, followers_list, page, limit))
|
||||
end
|
||||
|
||||
def followers(conn, %{"username" => username}) do
|
||||
instance_settings = InstanceSettings.get_instance_settings!()
|
||||
domain = instance_settings.domain
|
||||
actor = Actor.get_actor(username, domain)
|
||||
total = Utils.count_followers_by_username!(actor.preferredUsername)
|
||||
total = Relation.count_followers(actor.id)
|
||||
|
||||
conn
|
||||
|> put_resp_content_type("application/activity+json")
|
||||
|> json(ActivityPub.followers(domain, actor, total))
|
||||
|> json(ActivityPub.followers(actor, total))
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ defmodule NullaWeb.InboxController do
|
|||
conn,
|
||||
%{"id" => follow_id, "type" => "Follow", "actor" => actor_uri, "object" => target_uri}
|
||||
) do
|
||||
with {:ok, target_actor} <- Utils.resolve_local_actor(target_uri),
|
||||
with {:ok, local_actor} <- Utils.resolve_local_actor(target_uri),
|
||||
{:ok, remote_actor_json} <- Utils.fetch_remote_actor(actor_uri),
|
||||
:ok <- HTTPSignature.verify(conn, remote_actor_json),
|
||||
remote_actor <-
|
||||
|
@ -31,14 +31,15 @@ defmodule NullaWeb.InboxController do
|
|||
accept_activity <-
|
||||
Activity.create_activity(%{
|
||||
type: "Accept",
|
||||
actor: target_actor.id,
|
||||
actor: local_actor.id,
|
||||
object: follow_activity
|
||||
}),
|
||||
relation <- Relation.create_relation(%{
|
||||
followed_by: true,
|
||||
local_actor_id: target_actor.id,
|
||||
remote_actor_id: remote_actor.id
|
||||
}) do
|
||||
_ <-
|
||||
Relation.create_relation(%{
|
||||
followed_by: true,
|
||||
local_actor_id: local_actor.id,
|
||||
remote_actor_id: remote_actor.id
|
||||
}) do
|
||||
conn
|
||||
|> put_resp_content_type("application/activity+json")
|
||||
|> send_resp(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue