activitypub transmogrifier: clean up accept/reject handling a bit
authorWilliam Pitcock <nenolod@dereferenced.org>
Fri, 25 May 2018 09:38:07 +0000 (09:38 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Fri, 25 May 2018 09:40:11 +0000 (09:40 +0000)
lib/pleroma/web/activity_pub/transmogrifier.ex

index 525b741352f435bb4676345fc68551bc75d70736..519548788feada97bfc8f789471db295462a91ef 100644 (file)
@@ -171,7 +171,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
     with %User{} = followed <- User.get_or_fetch_by_ap_id(actor),
          {:ok, follow_activity} <- get_follow_activity(follow_object),
          %User{local: true} = follower <- User.get_cached_by_ap_id(follow_activity["actor"]) do
-      User.follow(follower, followed)
+      if not User.following?(follower, followed) do
+        User.follow(follower, followed)
+      end
 
       {:ok, data}
     end
@@ -182,10 +184,10 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
       ) do
     with %User{} = followed <- User.get_or_fetch_by_ap_id(actor),
          {:ok, follow_activity} <- get_follow_activity(follow_object),
-         %User{local: true} = follower <- User.get_cached_by_ap_id(follow_activity["actor"]),
-         {:ok, follow_activity} <- Utils.fetch_latest_follow(follower, followed),
-         {:ok, activity} <- ActivityPub.delete(follow_activity, false) do
-      {:ok, activity}
+         %User{local: true} = follower <- User.get_cached_by_ap_id(follow_activity["actor"]) do
+      User.unfollow(follower, followed)
+
+      {:ok, data}
     end
   end