- def read_inbox(%{assigns: %{user: user}} = conn, %{"nickname" => nickname} = params) do
- if nickname == user.nickname do
- conn
- |> put_resp_header("content-type", "application/activity+json")
- |> json(UserView.render("inbox.json", %{user: user, max_id: params["max_id"]}))
- else
+ defp represent_service_actor(nil, _), do: {:error, :not_found}
+
+ def relay(conn, _params) do
+ Relay.get_actor()
+ |> represent_service_actor(conn)
+ end
+
+ def internal_fetch(conn, _params) do
+ InternalFetchActor.get_actor()
+ |> represent_service_actor(conn)
+ end
+
+ @doc "Returns the authenticated user's ActivityPub User object or a 404 Not Found if non-authenticated"
+ def whoami(%{assigns: %{user: %User{} = user}} = conn, _params) do
+ conn
+ |> put_resp_content_type("application/activity+json")
+ |> put_view(UserView)
+ |> render("user.json", %{user: user})
+ end
+
+ def whoami(_conn, _params), do: {:error, :not_found}
+
+ def read_inbox(
+ %{assigns: %{user: %{nickname: nickname} = user}} = conn,
+ %{"nickname" => nickname, "page" => page?} = params
+ )
+ when page? in [true, "true"] do
+ activities =
+ if params["max_id"] do
+ ActivityPub.fetch_activities([user.ap_id | User.following(user)], %{
+ "max_id" => params["max_id"],
+ "limit" => 10
+ })
+ else
+ ActivityPub.fetch_activities([user.ap_id | User.following(user)], %{"limit" => 10})
+ end
+
+ conn
+ |> put_resp_content_type("application/activity+json")
+ |> put_view(UserView)
+ |> render("activity_collection_page.json", %{
+ activities: activities,
+ iri: "#{user.ap_id}/inbox"
+ })
+ end
+
+ def read_inbox(%{assigns: %{user: %{nickname: nickname} = user}} = conn, %{
+ "nickname" => nickname
+ }) do
+ with {:ok, user} <- User.ensure_keys_present(user) do