Change structure
This commit is contained in:
parent
01c2c57933
commit
ddfb58c041
16 changed files with 153 additions and 66 deletions
51
lib/nulla_web/controllers/activitypub/outbox_controller.ex
Normal file
51
lib/nulla_web/controllers/activitypub/outbox_controller.ex
Normal file
|
@ -0,0 +1,51 @@
|
|||
defmodule NullaWeb.ActivityPub.OutboxController do
|
||||
use NullaWeb, :controller
|
||||
alias Nulla.ActivityPub
|
||||
alias Nulla.Models.Actor
|
||||
alias Nulla.Models.Note
|
||||
|
||||
def outbox(conn, %{"username" => username} = params) do
|
||||
domain = NullaWeb.Endpoint.host()
|
||||
actor = Actor.get_actor(preferredUsername: username, domain: domain)
|
||||
|
||||
case Map.get(params, "page") do
|
||||
"true" ->
|
||||
max_id = params["max_id"] && String.to_integer(params["max_id"])
|
||||
|
||||
notes =
|
||||
if max_id do
|
||||
Note.get_before_notes(actor.id, max_id)
|
||||
else
|
||||
Note.get_latest_notes(actor.id)
|
||||
end
|
||||
|
||||
items = Enum.map(notes, &ActivityPub.activity_note(&1))
|
||||
|
||||
next_max_id =
|
||||
case List.last(notes) do
|
||||
nil -> 0
|
||||
last -> last.id
|
||||
end
|
||||
|
||||
min_id =
|
||||
case List.first(notes) do
|
||||
nil -> 0
|
||||
first -> first.id
|
||||
end
|
||||
|
||||
conn
|
||||
|> put_resp_content_type("application/activity+json")
|
||||
|> send_resp(
|
||||
200,
|
||||
Jason.encode!(ActivityPub.outbox(actor, next_max_id, min_id || 0, items))
|
||||
)
|
||||
|
||||
_ ->
|
||||
total = Note.get_total_notes_count(actor.id)
|
||||
|
||||
conn
|
||||
|> put_resp_content_type("application/activity+json")
|
||||
|> send_resp(200, Jason.encode!(ActivityPub.outbox(actor, total)))
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue