end
end
+ def following(conn, %{"nickname" => nickname, "page" => page}) do
+ with %User{} = user <- User.get_cached_by_nickname(nickname),
+ {:ok, user} <- Pleroma.Web.WebFinger.ensure_keys_present(user) do
+ {page, _} = Integer.parse(page)
+ conn
+ |> put_resp_header("content-type", "application/activity+json")
+ |> json(UserView.render("following.json", %{user: user, page: page}))
+ end
+ end
+
+ def following(conn, %{"nickname" => nickname}) 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("following.json", %{user: user}))
+ end
+ end
+
+ def followers(conn, %{"nickname" => nickname, "page" => page}) do
+ with %User{} = user <- User.get_cached_by_nickname(nickname),
+ {:ok, user} <- Pleroma.Web.WebFinger.ensure_keys_present(user) do
+ {page, _} = Integer.parse(page)
+ conn
+ |> put_resp_header("content-type", "application/activity+json")
+ |> json(UserView.render("followers.json", %{user: user, page: page}))
+ end
+ end
+
+ def followers(conn, %{"nickname" => nickname}) 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("followers.json", %{user: user}))
+ end
+ 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 Ecto.{Changeset, UUID}
import Ecto.Query
+ def make_json_ld_header do
+ %{
+ "@context" => [
+ "https://www.w3.org/ns/activitystreams",
+ "https://w3id.org/security/v1",
+ %{
+ "manuallyApprovesFollowers" => "as:manuallyApprovesFollowers",
+ "sensitive" => "as:sensitive",
+ "Hashtag" => "as:Hashtag",
+ "ostatus" => "http://ostatus.org#",
+ "atomUri" => "ostatus:atomUri",
+ "inReplyToAtomUri" => "ostatus:inReplyToAtomUri",
+ "conversation" => "ostatus:conversation",
+ "toot" => "http://joinmastodon.org/ns#",
+ "Emoji" => "toot:Emoji"
+ }
+ ]
+ }
+ end
+
def make_date do
DateTime.utc_now() |> DateTime.to_iso8601
end
alias Pleroma.Web.Salmon
alias Pleroma.Web.WebFinger
alias Pleroma.User
+ alias Pleroma.Web.ActivityPub.Utils
def render("user.json", %{user: user}) do
{:ok, user} = WebFinger.ensure_keys_present(user)
public_key = :public_key.pem_entry_encode(:RSAPublicKey, public_key)
public_key = :public_key.pem_encode([public_key])
%{
- "@context" => [
- "https://www.w3.org/ns/activitystreams",
- "https://w3id.org/security/v1",
- %{
- "manuallyApprovesFollowers" => "as:manuallyApprovesFollowers",
- "sensitive" => "as:sensitive",
- "Hashtag" => "as:Hashtag",
- "ostatus" => "http://ostatus.org#",
- "atomUri" => "ostatus:atomUri",
- "inReplyToAtomUri" => "ostatus:inReplyToAtomUri",
- "conversation" => "ostatus:conversation",
- "toot" => "http://joinmastodon.org/ns#",
- "Emoji" => "toot:Emoji"
- }
- ],
"id" => user.ap_id,
"type" => "Person",
"following" => "#{user.ap_id}/following",
"url" => User.banner_url(user)
}
}
+ |> Map.merge(Utils.make_json_ld_header())
+ end
+
+ def collection(collection, iri, page) do
+ offset = (page - 1) * 10
+ items = Enum.slice(collection, offset, 10)
+ items = Enum.map(items, fn (user) -> user.ap_id end)
+ map = %{
+ "id" => "#{iri}?page=#{page}",
+ "type" => "OrderedCollectionPage",
+ "partOf" => iri,
+ "totalItems" => length(collection),
+ "orderedItems" => items
+ }
+ if offset < length(collection) do
+ Map.put(map, "next", "#{iri}?page=#{page+1}")
+ end
+ end
+
+ def render("following.json", %{user: user, page: page}) do
+ {:ok, following} = User.get_friends(user)
+ collection(following, "#{user.ap_id}/following", page)
+ |> Map.merge(Utils.make_json_ld_header())
+ end
+
+ def render("following.json", %{user: user}) do
+ {:ok, following} = User.get_friends(user)
+ %{
+ "id" => "#{user.ap_id}/following",
+ "type" => "OrderedCollection",
+ "totalItems" => length(following),
+ "first" => collection(following, "#{user.ap_id}/following", 1)
+ }
+ |> Map.merge(Utils.make_json_ld_header())
+ end
+
+ def render("followers.json", %{user: user, page: page}) do
+ {:ok, followers} = User.get_followers(user)
+ collection(followers, "#{user.ap_id}/followers", page)
+ |> Map.merge(Utils.make_json_ld_header())
+ end
+
+ def render("followers.json", %{user: user}) do
+ {:ok, followers} = User.get_followers(user)
+ %{
+ "id" => "#{user.ap_id}/following",
+ "type" => "OrderedCollection",
+ "totalItems" => length(followers),
+ "first" => collection(followers, "#{user.ap_id}/followers", 1)
+ }
+ |> Map.merge(Utils.make_json_ld_header())
end
end