ActivityPub: Remove `reject`, move everything to the Pipeline.
authorlain <lain@soykaf.club>
Wed, 12 Aug 2020 13:07:46 +0000 (15:07 +0200)
committerlain <lain@soykaf.club>
Wed, 12 Aug 2020 13:07:46 +0000 (15:07 +0200)
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/activity_pub/side_effects.ex
lib/pleroma/web/common_api/common_api.ex

index 6dd94119b910ce7b2ea0830c40700d41c7372d0b..bde1fe708a35a8f0ac310cc18a1eb3fe6d156d9a 100644 (file)
@@ -285,27 +285,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
     end
   end
 
-  @spec reject(map()) :: {:ok, Activity.t()} | {:error, any()}
-  def reject(params) do
-    accept_or_reject("Reject", params)
-  end
-
-  @spec accept_or_reject(String.t(), map()) :: {:ok, Activity.t()} | {:error, any()}
-  defp accept_or_reject(type, %{to: to, actor: actor, object: object} = params) do
-    local = Map.get(params, :local, true)
-    activity_id = Map.get(params, :activity_id, nil)
-
-    data =
-      %{"to" => to, "type" => type, "actor" => actor.ap_id, "object" => object}
-      |> Maps.put_if_present("id", activity_id)
-
-    with {:ok, activity} <- insert(data, local),
-         _ <- notify_and_stream(activity),
-         :ok <- maybe_federate(activity) do
-      {:ok, activity}
-    end
-  end
-
   @spec unfollow(User.t(), User.t(), String.t() | nil, boolean()) ::
           {:ok, Activity.t()} | nil | {:error, any()}
   def unfollow(follower, followed, activity_id \\ nil, local \\ true) do
index a4ad12d5372f494a537e90c6b21fcff6f25c74de..14a1da0c125d7d378e82d061189f2c2ad1160116 100644 (file)
@@ -55,6 +55,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
   # Task this handles
   # - Rejects all existing follow activities for this person
   # - Updates the follow state
+  # - Dismisses notificatios
   def handle(
         %{
           data: %{
@@ -71,6 +72,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
          %User{} = follower <- User.get_cached_by_ap_id(follower_id),
          {:ok, _follow_activity} <- Utils.update_follow_state_for_all(follow_activity, "reject") do
       FollowingRelationship.update(follower, followed, :follow_reject)
+      Notification.dismiss(follow_activity)
     end
 
     {:ok, object, meta}
@@ -100,19 +102,9 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
         {:ok, _activity, _} = Pipeline.common_pipeline(accept_data, local: true)
       end
     else
-      {:following, {:error, _}, follower, followed} ->
-        Utils.update_follow_state_for_all(object, "reject")
-        FollowingRelationship.update(follower, followed, :follow_reject)
-
-        if followed.local do
-          %{
-            to: [follower.ap_id],
-            actor: followed,
-            object: follow_id,
-            local: true
-          }
-          |> ActivityPub.reject()
-        end
+      {:following, {:error, _}, _follower, followed} ->
+        {:ok, reject_data, _} = Builder.reject(followed, object)
+        {:ok, _activity, _} = Pipeline.common_pipeline(reject_data, local: true)
 
       _ ->
         nil
index 7b08c19a8ec3a6401c030d37625309f6ec966343..a8141b28f45666bedfcdd7ed10b47bf4ee1aa919 100644 (file)
@@ -6,9 +6,7 @@ defmodule Pleroma.Web.CommonAPI do
   alias Pleroma.Activity
   alias Pleroma.ActivityExpiration
   alias Pleroma.Conversation.Participation
-  alias Pleroma.FollowingRelationship
   alias Pleroma.Formatter
-  alias Pleroma.Notification
   alias Pleroma.Object
   alias Pleroma.ThreadMute
   alias Pleroma.User
@@ -130,16 +128,8 @@ defmodule Pleroma.Web.CommonAPI do
 
   def reject_follow_request(follower, followed) do
     with %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed),
-         {:ok, follow_activity} <- Utils.update_follow_state_for_all(follow_activity, "reject"),
-         {:ok, _relationship} <- FollowingRelationship.update(follower, followed, :follow_reject),
-         {:ok, _notifications} <- Notification.dismiss(follow_activity),
-         {:ok, _activity} <-
-           ActivityPub.reject(%{
-             to: [follower.ap_id],
-             actor: followed,
-             object: follow_activity.data["id"],
-             type: "Reject"
-           }) do
+         {:ok, reject_data, _} <- Builder.reject(followed, follow_activity),
+         {:ok, _activity, _} <- Pipeline.common_pipeline(reject_data, local: true) do
       {:ok, follower}
     end
   end