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
def inbox(%{assigns: %{valid_signature: true}} = conn, params) do
Federator.enqueue(:incoming_ap_doc, params)
alias Pleroma.Web.Salmon
alias Pleroma.Web.WebFinger
alias Pleroma.User
+ alias Pleroma.Web.ActivityPub.ActivityPub
+ alias Pleroma.Web.ActivityPub.Transmogrifier
alias Pleroma.Web.ActivityPub.Utils
def render("user.json", %{user: user}) do
}
|> Map.merge(Utils.make_json_ld_header())
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