forked from AkkomaGang/akkoma
activitypub: add outbox endpoint
This commit is contained in:
parent
381ba256bf
commit
3fcdfb75d0
3 changed files with 63 additions and 0 deletions
|
@ -65,6 +65,17 @@ def followers(conn, %{"nickname" => nickname}) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def outbox(conn, %{"nickname" => nickname, "max_id" => max_id}) do
|
||||||
|
with %User{} = user <- User.get_cached_by_nickname(nickname),
|
||||||
|
{:ok, user} <- Pleroma.Web.WebFinger.ensure_keys_present(user) do
|
||||||
|
conn
|
||||||
|
|> put_resp_header("content-type", "application/activity+json")
|
||||||
|
|> json(UserView.render("outbox.json", %{user: user, max_id: max_id}))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def outbox(conn, %{"nickname" => nickname}) do outbox(conn, %{"nickname" => nickname, "max_id" => nil}) end
|
||||||
|
|
||||||
# TODO: Ensure that this inbox is a recipient of the message
|
# TODO: Ensure that this inbox is a recipient of the message
|
||||||
def inbox(%{assigns: %{valid_signature: true}} = conn, params) do
|
def inbox(%{assigns: %{valid_signature: true}} = conn, params) do
|
||||||
Federator.enqueue(:incoming_ap_doc, params)
|
Federator.enqueue(:incoming_ap_doc, params)
|
||||||
|
|
|
@ -3,6 +3,8 @@ defmodule Pleroma.Web.ActivityPub.UserView do
|
||||||
alias Pleroma.Web.Salmon
|
alias Pleroma.Web.Salmon
|
||||||
alias Pleroma.Web.WebFinger
|
alias Pleroma.Web.WebFinger
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
|
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||||
alias Pleroma.Web.ActivityPub.Utils
|
alias Pleroma.Web.ActivityPub.Utils
|
||||||
|
|
||||||
def render("user.json", %{user: user}) do
|
def render("user.json", %{user: user}) do
|
||||||
|
@ -91,4 +93,53 @@ def render("followers.json", %{user: user}) do
|
||||||
}
|
}
|
||||||
|> Map.merge(Utils.make_json_ld_header())
|
|> Map.merge(Utils.make_json_ld_header())
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def render("outbox.json", %{user: user, max_id: max_qid}) do
|
||||||
|
# XXX: technically note_count is wrong for this, but it's better than nothing
|
||||||
|
info = User.user_info(user)
|
||||||
|
|
||||||
|
params = %{
|
||||||
|
"type" => ["Create", "Announce"],
|
||||||
|
"actor_id" => user.ap_id,
|
||||||
|
"whole_db" => true,
|
||||||
|
"limit" => "10"
|
||||||
|
}
|
||||||
|
|
||||||
|
if max_qid != nil do
|
||||||
|
params = Map.put(params, "max_id", max_qid)
|
||||||
|
end
|
||||||
|
|
||||||
|
activities = ActivityPub.fetch_public_activities(params)
|
||||||
|
min_id = Enum.at(activities, 0).id
|
||||||
|
|
||||||
|
activities = Enum.reverse(activities)
|
||||||
|
max_id = Enum.at(activities, 0).id
|
||||||
|
|
||||||
|
collection = Enum.map(activities, fn (act) ->
|
||||||
|
{:ok, data} = Transmogrifier.prepare_outgoing(act.data)
|
||||||
|
data
|
||||||
|
end)
|
||||||
|
|
||||||
|
iri = "#{user.ap_id}/outbox"
|
||||||
|
page = %{
|
||||||
|
"id" => "#{iri}?max_id=#{max_id}",
|
||||||
|
"type" => "OrderedCollectionPage",
|
||||||
|
"partOf" => iri,
|
||||||
|
"totalItems" => info.note_count,
|
||||||
|
"orderedItems" => collection,
|
||||||
|
"next" => "#{iri}?max_id=#{min_id-1}",
|
||||||
|
}
|
||||||
|
|
||||||
|
if max_qid == nil do
|
||||||
|
%{
|
||||||
|
"id" => iri,
|
||||||
|
"type" => "OrderedCollection",
|
||||||
|
"totalItems" => info.note_count,
|
||||||
|
"first" => page
|
||||||
|
}
|
||||||
|
|> Map.merge(Utils.make_json_ld_header())
|
||||||
|
else
|
||||||
|
page |> Map.merge(Utils.make_json_ld_header())
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -255,6 +255,7 @@ def user_fetcher(username) do
|
||||||
|
|
||||||
get "/users/:nickname/followers", ActivityPubController, :followers
|
get "/users/:nickname/followers", ActivityPubController, :followers
|
||||||
get "/users/:nickname/following", ActivityPubController, :following
|
get "/users/:nickname/following", ActivityPubController, :following
|
||||||
|
get "/users/:nickname/outbox", ActivityPubController, :outbox
|
||||||
end
|
end
|
||||||
|
|
||||||
if @federating do
|
if @federating do
|
||||||
|
|
Loading…
Reference in a new issue