end
end
+ # GET /relay/following
+ def following(%{assigns: %{relay: true}} = conn, _params) do
+ conn
+ |> put_resp_header("content-type", "application/activity+json")
+ |> json(UserView.render("following.json", %{user: Relay.get_actor()}))
+ end
+
def following(%{assigns: %{user: for_user}} = conn, %{"nickname" => nickname, "page" => page}) do
with %User{} = user <- User.get_cached_by_nickname(nickname),
{user, for_user} <- ensure_user_keys_present_and_maybe_refresh_for_user(user, for_user),
end
end
+ # GET /relay/followers
+ def followers(%{assigns: %{relay: true}} = conn, _params) do
+ conn
+ |> put_resp_header("content-type", "application/activity+json")
+ |> json(UserView.render("followers.json", %{user: Relay.get_actor()}))
+ end
+
def followers(%{assigns: %{user: for_user}} = conn, %{"nickname" => nickname, "page" => page}) do
with %User{} = user <- User.get_cached_by_nickname(nickname),
{user, for_user} <- ensure_user_keys_present_and_maybe_refresh_for_user(user, for_user),
def unfollow(target_instance) do
with %User{} = local_user <- get_actor(),
{:ok, %User{} = target_user} <- User.get_or_fetch_by_ap_id(target_instance),
- {:ok, activity} <- ActivityPub.unfollow(local_user, target_user) do
+ {:ok, activity} <- ActivityPub.unfollow(local_user, target_user),
+ {:ok, _, _} <- User.unfollow(local_user, target_user) do
Logger.info("relay: unfollowed instance: #{target_instance}: id=#{activity.data["id"]}")
{:ok, activity}
else
get("/", ActivityPubController, :relay)
post("/inbox", ActivityPubController, :inbox)
+
+ get("/following", ActivityPubController, :following, assigns: %{relay: true})
+ get("/followers", ActivityPubController, :followers, assigns: %{relay: true})
end
scope "/internal/fetch", Pleroma.Web.ActivityPub do
alias Pleroma.Web.ActivityPub.ObjectView
alias Pleroma.Web.ActivityPub.UserView
alias Pleroma.Web.ActivityPub.Utils
+ alias Pleroma.Web.ActivityPub.Relay
alias Pleroma.Web.CommonAPI
setup_all do
end
end
+ describe "/relay/followers" do
+ test "it returns relay followers", %{conn: conn} do
+ relay_actor = Relay.get_actor()
+ user = insert(:user)
+ User.follow(user, relay_actor)
+
+ result =
+ conn
+ |> assign(:relay, true)
+ |> get("/relay/followers")
+ |> json_response(200)
+
+ assert result["first"]["orderedItems"] == [user.ap_id]
+ end
+ end
+
+ describe "/relay/following" do
+ test "it returns relay following", %{conn: conn} do
+ result =
+ conn
+ |> assign(:relay, true)
+ |> get("/relay/following")
+ |> json_response(200)
+
+ assert result["first"]["orderedItems"] == []
+ end
+ end
+
describe "/users/:nickname/followers" do
test "it returns the followers in a collection", %{conn: conn} do
user = insert(:user)