67 lines
2.2 KiB
Elixir
67 lines
2.2 KiB
Elixir
defmodule NullaWeb.ActivityPub.FollowController do
|
|
use NullaWeb, :controller
|
|
alias Nulla.ActivityPub
|
|
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 = NullaWeb.Endpoint.host()
|
|
limit = instance_settings.api_limit
|
|
actor = Actor.get_actor(preferredUsername: username, domain: domain)
|
|
total = Relation.count_following(actor.id)
|
|
|
|
page =
|
|
case Integer.parse(page_param) do
|
|
{int, _} when int > 0 -> int
|
|
_ -> 1
|
|
end
|
|
|
|
following_list = Enum.map(Relation.get_following(actor.id, page, limit), & &1.ap_id)
|
|
|
|
conn
|
|
|> put_resp_content_type("application/activity+json")
|
|
|> json(ActivityPub.following(actor, total, following_list, page, limit))
|
|
end
|
|
|
|
def following(conn, %{"username" => username}) do
|
|
domain = NullaWeb.Endpoint.host()
|
|
actor = Actor.get_actor(preferredUsername: username, domain: domain)
|
|
total = Relation.count_following(actor.id)
|
|
|
|
conn
|
|
|> put_resp_content_type("application/activity+json")
|
|
|> json(ActivityPub.following(actor, total))
|
|
end
|
|
|
|
def followers(conn, %{"username" => username, "page" => page_param}) do
|
|
instance_settings = InstanceSettings.get_instance_settings!()
|
|
domain = NullaWeb.Endpoint.host()
|
|
limit = instance_settings.api_limit
|
|
actor = Actor.get_actor(preferredUsername: username, domain: domain)
|
|
total = Relation.count_followers(actor.id)
|
|
|
|
page =
|
|
case Integer.parse(page_param) do
|
|
{int, _} when int > 0 -> int
|
|
_ -> 1
|
|
end
|
|
|
|
followers_list = Enum.map(Relation.get_followers(actor.id, page, limit), & &1.ap_id)
|
|
|
|
conn
|
|
|> put_resp_content_type("application/activity+json")
|
|
|> json(ActivityPub.followers(actor, total, followers_list, page, limit))
|
|
end
|
|
|
|
def followers(conn, %{"username" => username}) do
|
|
domain = NullaWeb.Endpoint.host()
|
|
actor = Actor.get_actor(preferredUsername: username, domain: domain)
|
|
total = Relation.count_followers(actor.id)
|
|
|
|
conn
|
|
|> put_resp_content_type("application/activity+json")
|
|
|> json(ActivityPub.followers(actor, total))
|
|
end
|
|
end
|