Include requested_by in relationship (#260)
authorfloatingghost <hannah@coffee-and-dreams.uk>
Thu, 10 Nov 2022 03:16:32 +0000 (03:16 +0000)
committerfloatingghost <hannah@coffee-and-dreams.uk>
Thu, 10 Nov 2022 03:16:32 +0000 (03:16 +0000)
Co-authored-by: FloatingGhost <hannah@coffee-and-dreams.uk>
Reviewed-on: https://akkoma.dev/AkkomaGang/akkoma/pulls/260

lib/pleroma/web/mastodon_api/views/account_view.ex
test/pleroma/web/mastodon_api/views/account_view_test.exs

index cbb57aee663219e475ccaaeeeac48bd4cc97fedf..a04ffaaf3a7d9d85a069f635ce16769f8efc0cf1 100644 (file)
@@ -94,12 +94,12 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
 
     followed_by =
       if following_relationships do
-        case FollowingRelationship.find(following_relationships, target, reading_user) do
-          %{state: :follow_accept} -> true
-          _ -> false
-        end
+        target_to_user_following_relation =
+          FollowingRelationship.find(following_relationships, target, reading_user)
+
+        User.get_follow_state(target, reading_user, target_to_user_following_relation)
       else
-        User.following?(target, reading_user)
+        User.get_follow_state(target, reading_user)
       end
 
     subscribing =
@@ -115,7 +115,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
     %{
       id: to_string(target.id),
       following: follow_state == :follow_accept,
-      followed_by: followed_by,
+      followed_by: followed_by == :follow_accept,
       blocking:
         UserRelationship.exists?(
           user_relationships,
@@ -151,6 +151,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
       subscribing: subscribing,
       notifying: subscribing,
       requested: follow_state == :follow_pending,
+      requested_by: followed_by == :follow_pending,
       domain_blocking: User.blocks_domain?(reading_user, target),
       showing_reblogs:
         not UserRelationship.exists?(
index d1903af801676402676091185f0aa9dafc18aba5..f4a5f4d50326673eec6e9549e5e0145aa85526a5 100644 (file)
@@ -347,6 +347,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
       subscribing: false,
       notifying: false,
       requested: false,
+      requested_by: false,
       domain_blocking: false,
       showing_reblogs: true,
       endorsed: false,
@@ -432,6 +433,24 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
     end
   end
 
+  test "represent a relationship for a user with an inbound pending follow request" do
+    follower = insert(:user)
+    followed = insert(:user, is_locked: true)
+
+    {:ok, follower, followed, _} = CommonAPI.follow(follower, followed)
+
+    follower = User.get_cached_by_id(follower.id)
+    followed = User.get_cached_by_id(followed.id)
+
+    expected =
+      Map.merge(
+        @blank_response,
+        %{requested_by: true, followed_by: false, id: to_string(follower.id)}
+      )
+
+    test_relationship_rendering(followed, follower, expected)
+  end
+
   test "returns the settings store if the requesting user is the represented user and it's requested specifically" do
     user = insert(:user, pleroma_settings_store: %{fe: "test"})