metadata: [:request_id]
config :mime, :types, %{
- "application/xrd+xml" => ["xrd+xml"]
+ "application/xrd+xml" => ["xrd+xml"],
+ "application/activity+json" => ["activity+json"]
}
config :pleroma, :websub, Pleroma.Web.Websub
--- /dev/null
+defmodule Pleroma.Web.ActivityPub.ActivityPubController do
+ use Pleroma.Web, :controller
+ alias Pleroma.{User, Repo}
+ alias Pleroma.Web.ActivityPub.UserView
+ alias Pleroma.Web.ActivityPub.ActivityPub
+
+ def user(conn, %{"nickname" => nickname}) do
+ with %User{} = user <- User.get_cached_by_nickname(nickname) do
+ json(conn, UserView.render("user.json", %{user: user}))
+ end
+ end
+
+ def inbox(conn, params) do
+ {:ok, activity} = ActivityPub.insert(params, false)
+ json(conn, "ok")
+ end
+end
--- /dev/null
+defmodule Pleroma.Web.ActivityPub.UserView do
+ use Pleroma.Web, :view
+ alias Pleroma.Web.Salmon
+ alias Pleroma.User
+
+ def render("user.json", %{user: user}) do
+ {:ok, _, public_key} = Salmon.keys_from_pem(user.info["keys"])
+ 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",
+ "followers": "#{user.ap_id}/followers",
+ "inbox": "#{user.ap_id}/inbox",
+ "outbox": "#{user.ap_id}/outbox",
+ "preferredUsername": user.nickname,
+ "name": user.name,
+ "summary": user.bio,
+ "url": user.ap_id,
+ "manuallyApprovesFollowers": false,
+ "publicKey": %{
+ "id": "#{user.ap_id}#main-key",
+ "owner": user.ap_id,
+ "publicKeyPem": public_key
+ },
+ "endpoints": %{
+ "sharedInbox": "#{Pleroma.Web.Endpoint.url}/inbox"
+ },
+ "icon": %{
+ "type": "Image",
+ "url": User.avatar_url(user)
+ }
+ }
+ end
+end
alias Pleroma.Repo
alias Pleroma.Web.{OStatus, Federator}
alias Pleroma.Web.XML
+ alias Pleroma.Web.ActivityPub.ActivityPubController
import Ecto.Query
- def feed_redirect(conn, %{"nickname" => nickname}) do
+ def feed_redirect(conn, %{"nickname" => nickname} = params) do
user = User.get_cached_by_nickname(nickname)
case get_format(conn) do
"html" -> Fallback.RedirectController.redirector(conn, nil)
+ "activity+json" -> ActivityPubController.user(conn, params)
_ -> redirect conn, external: OStatus.feed_path(user)
end
end
end
pipeline :ostatus do
- plug :accepts, ["xml", "atom", "html"]
+ plug :accepts, ["xml", "atom", "html", "activity+json"]
end
scope "/", Pleroma.Web do
post "/push/subscriptions/:id", Websub.WebsubController, :websub_incoming
end
+ pipeline :activitypub do
+ plug :accepts, ["activity+json"]
+ end
+
+ scope "/", Pleroma.Web.ActivityPub do
+ post "/users/:nickname/inbox", ActivityPubController, :inbox
+ end
+
scope "/.well-known", Pleroma.Web do
pipe_through :well_known