forked from AkkomaGang/akkoma
ActivityPub: Add object routes / controller.
This commit is contained in:
parent
a89a613e4e
commit
64330d9455
2 changed files with 22 additions and 10 deletions
|
@ -1,15 +1,23 @@
|
||||||
defmodule Pleroma.Web.ActivityPub.ActivityPubController do
|
defmodule Pleroma.Web.ActivityPub.ActivityPubController do
|
||||||
use Pleroma.Web, :controller
|
use Pleroma.Web, :controller
|
||||||
alias Pleroma.{User, Repo}
|
alias Pleroma.{User, Repo, Object}
|
||||||
alias Pleroma.Web.ActivityPub.UserView
|
alias Pleroma.Web.ActivityPub.{ObjectView, UserView}
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
|
|
||||||
def user(conn, %{"nickname" => nickname}) do
|
def user(conn, %{"nickname" => nickname}) do
|
||||||
with %User{} = user <- User.get_cached_by_nickname(nickname) do
|
with %User{} = user <- User.get_cached_by_nickname(nickname),
|
||||||
|
{:ok, user} <- Pleroma.Web.WebFinger.ensure_keys_present(user) do
|
||||||
json(conn, UserView.render("user.json", %{user: user}))
|
json(conn, UserView.render("user.json", %{user: user}))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def object(conn, %{"uuid" => uuid}) do
|
||||||
|
with ap_id <- o_status_url(conn, :object, uuid),
|
||||||
|
%Object{} = object <- Object.get_cached_by_ap_id(ap_id) do
|
||||||
|
json(conn, ObjectView.render("object.json", %{object: object}))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def inbox(conn, params) do
|
def inbox(conn, params) do
|
||||||
{:ok, activity} = ActivityPub.insert(params, false)
|
{:ok, activity} = ActivityPub.insert(params, false)
|
||||||
json(conn, "ok")
|
json(conn, "ok")
|
||||||
|
|
|
@ -66,13 +66,17 @@ def salmon_incoming(conn, _) do
|
||||||
|> send_resp(200, "")
|
|> send_resp(200, "")
|
||||||
end
|
end
|
||||||
|
|
||||||
def object(conn, %{"uuid" => uuid}) do
|
def object(conn, %{"uuid" => uuid} = params) do
|
||||||
with id <- o_status_url(conn, :object, uuid),
|
if get_format(conn) == "activity+json" do
|
||||||
%Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id),
|
ActivityPubController.object(conn, params)
|
||||||
%User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do
|
else
|
||||||
case get_format(conn) do
|
with id <- o_status_url(conn, :object, uuid),
|
||||||
"html" -> redirect(conn, to: "/notice/#{activity.id}")
|
%Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id),
|
||||||
_ -> represent_activity(conn, activity, user)
|
%User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do
|
||||||
|
case get_format(conn) do
|
||||||
|
"html" -> redirect(conn, to: "/notice/#{activity.id}")
|
||||||
|
_ -> represent_activity(conn, activity, user)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue