64 lines
2.1 KiB
Elixir
64 lines
2.1 KiB
Elixir
defmodule NullaWeb.ActivityPub.FollowController do
|
|
use NullaWeb, :controller
|
|
alias NullaWeb.ActivityPub.FollowJSON
|
|
alias Nulla.Actors
|
|
alias Nulla.Relations
|
|
|
|
def following(conn, %{"username" => username, "page" => page_param}) do
|
|
domain = NullaWeb.Endpoint.host()
|
|
limit = Application.get_env(:nulla, :instance)[:api_limit]
|
|
actor = Actors.get_actor_by(acct: "#{username}@#{domain}")
|
|
total = Relations.count_following(actor.id)
|
|
|
|
page =
|
|
case Integer.parse(page_param) do
|
|
{int, _} when int > 0 -> int
|
|
_ -> 1
|
|
end
|
|
|
|
following_list = Enum.map(Relations.get_following(actor.id, page, limit), & &1.ap_id)
|
|
|
|
conn
|
|
|> put_resp_content_type("application/activity+json")
|
|
|> json(FollowJSON.following(actor, total, following_list, page, limit))
|
|
end
|
|
|
|
def following(conn, %{"username" => username}) do
|
|
domain = NullaWeb.Endpoint.host()
|
|
actor = Actors.get_actor_by(acct: "#{username}@#{domain}")
|
|
total = Relations.count_following(actor.id)
|
|
|
|
conn
|
|
|> put_resp_content_type("application/activity+json")
|
|
|> json(FollowJSON.following(actor, total))
|
|
end
|
|
|
|
def followers(conn, %{"username" => username, "page" => page_param}) do
|
|
domain = NullaWeb.Endpoint.host()
|
|
limit = Application.get_env(:nulla, :instance)[:api_limit]
|
|
actor = Actors.get_actor_by(acct: "#{username}@#{domain}")
|
|
total = Relations.count_followers(actor.id)
|
|
|
|
page =
|
|
case Integer.parse(page_param) do
|
|
{int, _} when int > 0 -> int
|
|
_ -> 1
|
|
end
|
|
|
|
followers_list = Enum.map(Relations.get_followers(actor.id, page, limit), & &1.ap_id)
|
|
|
|
conn
|
|
|> put_resp_content_type("application/activity+json")
|
|
|> json(FollowJSON.followers(actor, total, followers_list, page, limit))
|
|
end
|
|
|
|
def followers(conn, %{"username" => username}) do
|
|
domain = NullaWeb.Endpoint.host()
|
|
actor = Actors.get_actor_by(acct: "#{username}@#{domain}")
|
|
total = Relations.count_followers(actor.id)
|
|
|
|
conn
|
|
|> put_resp_content_type("application/activity+json")
|
|
|> json(FollowJSON.followers(actor, total))
|
|
end
|
|
end
|