Add outbox
This commit is contained in:
parent
b582c93bb1
commit
f05741edb5
4 changed files with 36 additions and 0 deletions
|
@ -304,4 +304,16 @@ defmodule Nulla.ActivityPub do
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@spec outbox(String.t(), String.t(), Integer.t()) :: Jason.OrderedObject.t()
|
||||||
|
def outbox(domain, username, total) do
|
||||||
|
Jason.OrderedObject.new(
|
||||||
|
"@context": "https://www.w3.org/ns/activitystreams",
|
||||||
|
id: "https://#{domain}/@#{username}/outbox",
|
||||||
|
type: "OrderedCollection",
|
||||||
|
totalItems: total,
|
||||||
|
first: "https://#{domain}/@#{username}/outbox?page=true",
|
||||||
|
last: "https://#{domain}/@#{username}/outbox?min_id=0&page=true"
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,4 +33,9 @@ defmodule Nulla.Models.Note do
|
||||||
def get_note!(id), do: Repo.get!(Note, id)
|
def get_note!(id), do: Repo.get!(Note, id)
|
||||||
|
|
||||||
def get_all_notes!(user_id), do: Repo.all(from n in Note, where: n.user_id == ^user_id)
|
def get_all_notes!(user_id), do: Repo.all(from n in Note, where: n.user_id == ^user_id)
|
||||||
|
|
||||||
|
def get_total_notes_count(user_id) do
|
||||||
|
from(n in Note, where: n.user_id == ^user_id)
|
||||||
|
|> Repo.aggregate(:count, :id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
18
lib/nulla_web/controllers/outbox_controller.ex
Normal file
18
lib/nulla_web/controllers/outbox_controller.ex
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
defmodule NullaWeb.OutboxController do
|
||||||
|
use NullaWeb, :controller
|
||||||
|
alias Nulla.ActivityPub
|
||||||
|
alias Nulla.Models.User
|
||||||
|
alias Nulla.Models.Note
|
||||||
|
alias Nulla.Models.InstanceSettings
|
||||||
|
|
||||||
|
def show(conn, %{"username" => username}) do
|
||||||
|
instance_settings = InstanceSettings.get_instance_settings!()
|
||||||
|
domain = instance_settings.domain
|
||||||
|
user = User.get_user_by_username!(username)
|
||||||
|
total = Note.get_total_notes_count(user.id)
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> put_resp_content_type("application/activity+json")
|
||||||
|
|> send_resp(200, Jason.encode!(ActivityPub.outbox(domain, username, total)))
|
||||||
|
end
|
||||||
|
end
|
|
@ -22,6 +22,7 @@ defmodule NullaWeb.Router do
|
||||||
get "/nodeinfo/2.0", NodeinfoController, :show
|
get "/nodeinfo/2.0", NodeinfoController, :show
|
||||||
|
|
||||||
get "/@:username", UserController, :show
|
get "/@:username", UserController, :show
|
||||||
|
get "/@:username/outbox", OutboxController, :show
|
||||||
get "/@:username/following", FollowController, :following
|
get "/@:username/following", FollowController, :following
|
||||||
get "/@:username/followers", FollowController, :followers
|
get "/@:username/followers", FollowController, :followers
|
||||||
get "/@:username/:note_id", NoteController, :show
|
get "/@:username/:note_id", NoteController, :show
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue