Change structure
This commit is contained in:
parent
01c2c57933
commit
ddfb58c041
16 changed files with 153 additions and 66 deletions
67
lib/nulla_web/controllers/activitypub/follow_controller.ex
Normal file
67
lib/nulla_web/controllers/activitypub/follow_controller.ex
Normal file
|
@ -0,0 +1,67 @@
|
|||
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
|
Loading…
Add table
Add a link
Reference in a new issue