Update
This commit is contained in:
parent
188bc08494
commit
4af88f3e1d
44 changed files with 1041 additions and 34 deletions
64
lib/nulla_web/controllers/activitypub/follow_controller.ex
Normal file
64
lib/nulla_web/controllers/activitypub/follow_controller.ex
Normal file
|
@ -0,0 +1,64 @@
|
|||
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
|
Loading…
Add table
Add a link
Reference in a new issue