X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fweb%2Factivity_pub%2Frelay.ex;h=484178edd9e266098678dff3af0d8585309a7b36;hb=805ab86933d90d4284c83e4a8ebfd6bf4b0395b3;hp=de80612f172995285d7da651f40ecbf745bfa60a;hpb=6281e4795a51034f026aeb833093e47b47255799;p=akkoma
diff --git a/lib/pleroma/web/activity_pub/relay.ex b/lib/pleroma/web/activity_pub/relay.ex
index de80612f1..484178edd 100644
--- a/lib/pleroma/web/activity_pub/relay.ex
+++ b/lib/pleroma/web/activity_pub/relay.ex
@@ -1,23 +1,29 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
+# Copyright © 2017-2020 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.Relay do
alias Pleroma.Activity
- alias Pleroma.Object
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
+ alias Pleroma.Web.ActivityPub.Visibility
+ alias Pleroma.Web.CommonAPI
require Logger
+ @relay_nickname "relay"
+
def get_actor do
actor =
- "#{Pleroma.Web.Endpoint.url()}/relay"
- |> User.get_or_create_service_actor_by_ap_id()
+ relay_ap_id()
+ |> User.get_or_create_service_actor_by_ap_id(@relay_nickname)
- {:ok, actor} = User.update_info(actor, &User.Info.set_invisible(&1, true))
actor
end
+ def relay_ap_id do
+ "#{Pleroma.Web.Endpoint.url()}/relay"
+ end
+
@spec follow(String.t()) :: {:ok, Activity.t()} | {:error, any()}
def follow(target_instance) do
with %User{} = local_user <- get_actor(),
@@ -43,11 +49,11 @@ defmodule Pleroma.Web.ActivityPub.Relay do
end
end
- @spec publish(any()) :: {:ok, Activity.t(), Object.t()} | {:error, any()}
+ @spec publish(any()) :: {:ok, Activity.t()} | {:error, any()}
def publish(%Activity{data: %{"type" => "Create"}} = activity) do
with %User{} = user <- get_actor(),
- %Object{} = object <- Object.normalize(activity) do
- ActivityPub.announce(user, object, nil, true, false)
+ true <- Visibility.is_public?(activity) do
+ CommonAPI.repeat(activity.id, user)
else
error -> format_error(error)
end
@@ -55,14 +61,28 @@ defmodule Pleroma.Web.ActivityPub.Relay do
def publish(_), do: {:error, "Not implemented"}
- @spec list() :: {:ok, [String.t()]} | {:error, any()}
- def list do
- with %User{following: following} = _user <- get_actor() do
- list =
- following
+ @spec list(boolean()) :: {:ok, [String.t()]} | {:error, any()}
+ def list(with_not_accepted \\ false) do
+ with %User{} = user <- get_actor() do
+ accepted =
+ user
+ |> User.following()
|> Enum.map(fn entry -> URI.parse(entry).host end)
|> Enum.uniq()
+ list =
+ if with_not_accepted do
+ without_accept =
+ user
+ |> Pleroma.Activity.following_requests_for_actor()
+ |> Enum.map(fn a -> URI.parse(a.data["object"]).host <> " (no Accept received)" end)
+ |> Enum.uniq()
+
+ accepted ++ without_accept
+ else
+ accepted
+ end
+
{:ok, list}
else
error -> format_error(error)