activitypub transmogrifier: use fetch_latest_follow to verify a follow object exists
authorWilliam Pitcock <nenolod@dereferenced.org>
Sat, 26 May 2018 11:07:04 +0000 (11:07 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Sat, 26 May 2018 11:20:52 +0000 (11:20 +0000)
lib/pleroma/web/activity_pub/transmogrifier.ex

index 41198d4e60cfdd57b95c0b0991d4eab502c32c94..ff83dfd362530e268a7cabfea6d33de1a4331b00 100644 (file)
@@ -171,12 +171,16 @@ 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"]),
+         follow_activity <- Utils.fetch_latest_follow(follower, followed),
+         false <- is_nil(follow_activity),
          {:ok, activity} <- ActivityPub.insert(data, true) do
       if not User.following?(follower, followed) do
         {:ok, follower} = User.follow(follower, followed)
       end
 
       {:ok, activity}
+    else
+      _e -> :error
     end
   end
 
@@ -186,10 +190,14 @@ 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"]),
+         follow_activity <- Utils.fetch_latest_follow(follower, followed),
+         false <- is_nil(follow_activity),
          {:ok, activity} <- ActivityPub.insert(data, true) do
       User.unfollow(follower, followed)
 
       {:ok, activity}
+    else
+      _e -> :error
     end
   end