Update
This commit is contained in:
parent
188bc08494
commit
4af88f3e1d
44 changed files with 1041 additions and 34 deletions
57
lib/nulla_web/controllers/activitypub/outbox_controller.ex
Normal file
57
lib/nulla_web/controllers/activitypub/outbox_controller.ex
Normal file
|
@ -0,0 +1,57 @@
|
|||
defmodule NullaWeb.ActivityPub.OutboxController do
|
||||
use NullaWeb, :controller
|
||||
alias NullaWeb.ActivityPub.OutboxJSON
|
||||
alias Nulla.Actors
|
||||
alias Nulla.Activities
|
||||
alias Nulla.Actors.Actor
|
||||
|
||||
def index(conn, %{"username" => username, "page" => "true"} = params) do
|
||||
domain = NullaWeb.Endpoint.host()
|
||||
actor = Actors.get_actor_by(acct: "#{username}@#{domain}")
|
||||
|
||||
max_id = params["max_id"] && String.to_integer(params["max_id"])
|
||||
|
||||
activities =
|
||||
if max_id do
|
||||
Activities.get_before_activities(actor.ap_id, max_id)
|
||||
else
|
||||
Activities.get_latest_activities(actor.ap_id)
|
||||
end
|
||||
|
||||
next_max_id =
|
||||
case List.last(activities) do
|
||||
nil -> 0
|
||||
last -> last.id
|
||||
end
|
||||
|
||||
min_id =
|
||||
case List.first(activities) do
|
||||
nil -> 0
|
||||
first -> first.id
|
||||
end
|
||||
|
||||
conn
|
||||
|> put_resp_content_type("application/activity+json")
|
||||
|> send_resp(
|
||||
200,
|
||||
Jason.encode!(OutboxJSON.show(actor, activities, next_max_id, min_id))
|
||||
)
|
||||
end
|
||||
|
||||
def index(conn, %{"username" => username}) do
|
||||
domain = NullaWeb.Endpoint.host()
|
||||
actor = Actors.get_actor_by(acct: "#{username}@#{domain}")
|
||||
|
||||
case actor do
|
||||
%Actor{} = actor ->
|
||||
total = Activities.get_total_activities_count(actor.ap_id)
|
||||
|
||||
conn
|
||||
|> put_resp_content_type("application/activity+json")
|
||||
|> send_resp(200, Jason.encode!(OutboxJSON.index(actor, total)))
|
||||
|
||||
_ ->
|
||||
send_resp(conn, 404, "")
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue