Stream follow updates
authorEgor Kislitsyn <egor@kislitsyn.com>
Tue, 1 Dec 2020 20:17:52 +0000 (00:17 +0400)
committerEgor Kislitsyn <egor@kislitsyn.com>
Tue, 1 Dec 2020 20:18:58 +0000 (00:18 +0400)
30 files changed:
benchmarks/load_testing/users.ex
benchmarks/mix/tasks/pleroma/benchmarks/timelines.ex
lib/pleroma/following_relationship.ex
lib/pleroma/user.ex
lib/pleroma/user/import.ex
lib/pleroma/web/activity_pub/side_effects.ex
lib/pleroma/web/streamer.ex
lib/pleroma/web/views/streamer_view.ex
test/mix/tasks/pleroma/database_test.exs
test/mix/tasks/pleroma/user_test.exs
test/pleroma/bbs/handler_test.exs
test/pleroma/notification_test.exs
test/pleroma/user/import_test.exs
test/pleroma/user_search_test.exs
test/pleroma/user_test.exs
test/pleroma/web/activity_pub/activity_pub_controller_test.exs
test/pleroma/web/activity_pub/activity_pub_test.exs
test/pleroma/web/activity_pub/publisher_test.exs
test/pleroma/web/activity_pub/transmogrifier/accept_handling_test.exs
test/pleroma/web/activity_pub/transmogrifier/block_handling_test.exs
test/pleroma/web/activity_pub/transmogrifier/reject_handling_test.exs
test/pleroma/web/activity_pub/visibility_test.exs
test/pleroma/web/mastodon_api/controllers/account_controller_test.exs
test/pleroma/web/mastodon_api/controllers/conversation_controller_test.exs
test/pleroma/web/mastodon_api/controllers/follow_request_controller_test.exs
test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs
test/pleroma/web/mastodon_api/mastodon_api_test.exs
test/pleroma/web/mastodon_api/views/account_view_test.exs
test/pleroma/web/pleroma_api/controllers/user_import_controller_test.exs
test/pleroma/web/streamer_test.exs

index 6cf3958c14c6674c3c57b53478d8a0cce5d779fa..34a904ac2475f8ca369b65441e7b7e6e1f8849d9 100644 (file)
@@ -109,8 +109,8 @@ defmodule Pleroma.LoadTesting.Users do
   end
 
   def make_friends(%User{} = main_user, %User{} = user) do
   end
 
   def make_friends(%User{} = main_user, %User{} = user) do
-    {:ok, _} = User.follow(main_user, user)
-    {:ok, _} = User.follow(user, main_user)
+    {:ok, _, _} = User.follow(main_user, user)
+    {:ok, _, _} = User.follow(user, main_user)
   end
 
   @spec get_users(User.t(), keyword()) :: [User.t()]
   end
 
   @spec get_users(User.t(), keyword()) :: [User.t()]
index 9b7ac6111fd935fc7cfdf8036dc0263ded2880e5..aed32f1946a58e5fc28e864d4e4103da169de729 100644 (file)
@@ -50,7 +50,7 @@ defmodule Mix.Tasks.Pleroma.Benchmarks.Timelines do
     )
 
     users
     )
 
     users
-    |> Enum.each(fn {:ok, follower} -> Pleroma.User.follow(follower, user) end)
+    |> Enum.each(fn {:ok, follower, user} -> Pleroma.User.follow(follower, user) end)
 
     Benchee.run(
       %{
 
     Benchee.run(
       %{
index 2039a259dd6e7be926e6b0f8ea77be2bbbeca1d6..bc6a7eaf9850abdc10490e888e0a3f64becdd369 100644 (file)
@@ -62,23 +62,47 @@ defmodule Pleroma.FollowingRelationship do
         follow(follower, following, state)
 
       following_relationship ->
         follow(follower, following, state)
 
       following_relationship ->
-        following_relationship
-        |> cast(%{state: state}, [:state])
-        |> validate_required([:state])
-        |> Repo.update()
+        with {:ok, _following_relationship} <-
+               following_relationship
+               |> cast(%{state: state}, [:state])
+               |> validate_required([:state])
+               |> Repo.update() do
+          after_update(state, follower, following)
+        end
     end
   end
 
   def follow(%User{} = follower, %User{} = following, state \\ :follow_accept) do
     end
   end
 
   def follow(%User{} = follower, %User{} = following, state \\ :follow_accept) do
-    %__MODULE__{}
-    |> changeset(%{follower: follower, following: following, state: state})
-    |> Repo.insert(on_conflict: :nothing)
+    with {:ok, _following_relationship} <-
+           %__MODULE__{}
+           |> changeset(%{follower: follower, following: following, state: state})
+           |> Repo.insert(on_conflict: :nothing) do
+      after_update(state, follower, following)
+    end
   end
 
   def unfollow(%User{} = follower, %User{} = following) do
     case get(follower, following) do
   end
 
   def unfollow(%User{} = follower, %User{} = following) do
     case get(follower, following) do
-      %__MODULE__{} = following_relationship -> Repo.delete(following_relationship)
-      _ -> {:ok, nil}
+      %__MODULE__{} = following_relationship ->
+        with {:ok, _following_relationship} <- Repo.delete(following_relationship) do
+          after_update(:unfollow, follower, following)
+        end
+
+      _ ->
+        {:ok, nil}
+    end
+  end
+
+  defp after_update(state, %User{} = follower, %User{} = following) do
+    with {:ok, following} <- User.update_follower_count(following),
+         {:ok, follower} <- User.update_following_count(follower) do
+      Pleroma.Web.Streamer.stream("relationships:update", %{
+        state: state,
+        following: following,
+        follower: follower
+      })
+
+      {:ok, follower, following}
     end
   end
 
     end
   end
 
index bcd5256c8e0d51203e6a00aab2ee974e2c6d1da3..676483540cfee3105703b9614c3dd64cf4a902b6 100644 (file)
@@ -882,7 +882,7 @@ defmodule Pleroma.User do
     if not ap_enabled?(followed) do
       follow(follower, followed)
     else
     if not ap_enabled?(followed) do
       follow(follower, followed)
     else
-      {:ok, follower}
+      {:ok, follower, followed}
     end
   end
 
     end
   end
 
@@ -908,11 +908,6 @@ defmodule Pleroma.User do
 
       true ->
         FollowingRelationship.follow(follower, followed, state)
 
       true ->
         FollowingRelationship.follow(follower, followed, state)
-
-        {:ok, _} = update_follower_count(followed)
-
-        follower
-        |> update_following_count()
     end
   end
 
     end
   end
 
@@ -936,11 +931,6 @@ defmodule Pleroma.User do
     case get_follow_state(follower, followed) do
       state when state in [:follow_pending, :follow_accept] ->
         FollowingRelationship.unfollow(follower, followed)
     case get_follow_state(follower, followed) do
       state when state in [:follow_pending, :follow_accept] ->
         FollowingRelationship.unfollow(follower, followed)
-        {:ok, followed} = update_follower_count(followed)
-
-        {:ok, follower} = update_following_count(follower)
-
-        {:ok, follower, followed}
 
       nil ->
         {:error, "Not subscribed!"}
 
       nil ->
         {:error, "Not subscribed!"}
index e458021c87b1fdb35a1369238bd96c3c4e002dec..86b49d8ae36cfdd08cfd0fc5362d3f7b96d69614 100644 (file)
@@ -45,7 +45,7 @@ defmodule Pleroma.User.Import do
       identifiers,
       fn identifier ->
         with {:ok, %User{} = followed} <- User.get_or_fetch(identifier),
       identifiers,
       fn identifier ->
         with {:ok, %User{} = followed} <- User.get_or_fetch(identifier),
-             {:ok, follower} <- User.maybe_direct_follow(follower, followed),
+             {:ok, follower, followed} <- User.maybe_direct_follow(follower, followed),
              {:ok, _, _, _} <- CommonAPI.follow(follower, followed) do
           followed
         else
              {:ok, _, _, _} <- CommonAPI.follow(follower, followed) do
           followed
         else
index 4d8fb721e9465dc4eb384d1bbe56f23e20e55b91..8556fca1db8cc5121efcb6f97f5942842970767c 100644 (file)
@@ -47,10 +47,9 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
          %User{} = followed <- User.get_cached_by_ap_id(actor),
          %User{} = follower <- User.get_cached_by_ap_id(follower_id),
          {:ok, follow_activity} <- Utils.update_follow_state_for_all(follow_activity, "accept"),
          %User{} = followed <- User.get_cached_by_ap_id(actor),
          %User{} = follower <- User.get_cached_by_ap_id(follower_id),
          {:ok, follow_activity} <- Utils.update_follow_state_for_all(follow_activity, "accept"),
-         {:ok, _relationship} <- FollowingRelationship.update(follower, followed, :follow_accept) do
+         {:ok, _follower, followed} <-
+           FollowingRelationship.update(follower, followed, :follow_accept) do
       Notification.update_notification_type(followed, follow_activity)
       Notification.update_notification_type(followed, follow_activity)
-      User.update_follower_count(followed)
-      User.update_following_count(follower)
     end
 
     {:ok, object, meta}
     end
 
     {:ok, object, meta}
@@ -99,7 +98,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
       ) do
     with %User{} = follower <- User.get_cached_by_ap_id(following_user),
          %User{} = followed <- User.get_cached_by_ap_id(followed_user),
       ) do
     with %User{} = follower <- User.get_cached_by_ap_id(following_user),
          %User{} = followed <- User.get_cached_by_ap_id(followed_user),
-         {_, {:ok, _}, _, _} <-
+         {_, {:ok, _, _}, _, _} <-
            {:following, User.follow(follower, followed, :follow_pending), follower, followed} do
       if followed.local && !followed.is_locked do
         {:ok, accept_data, _} = Builder.accept(followed, object)
            {:following, User.follow(follower, followed, :follow_pending), follower, followed} do
       if followed.local && !followed.is_locked do
         {:ok, accept_data, _} = Builder.accept(followed, object)
index 71fe27c894db72f86641e41d401851c6762b3d68..0b6cc89e906b4f2d8858fb68261b0d288062e686 100644 (file)
@@ -36,9 +36,8 @@ defmodule Pleroma.Web.Streamer do
         ) ::
           {:ok, topic :: String.t()} | {:error, :bad_topic} | {:error, :unauthorized}
   def get_topic_and_add_socket(stream, user, oauth_token, params \\ %{}) do
         ) ::
           {:ok, topic :: String.t()} | {:error, :bad_topic} | {:error, :unauthorized}
   def get_topic_and_add_socket(stream, user, oauth_token, params \\ %{}) do
-    case get_topic(stream, user, oauth_token, params) do
-      {:ok, topic} -> add_socket(topic, user)
-      error -> error
+    with {:ok, topic} <- get_topic(stream, user, oauth_token, params) do
+      add_socket(topic, user)
     end
   end
 
     end
   end
 
@@ -70,10 +69,10 @@ defmodule Pleroma.Web.Streamer do
   def get_topic(
         stream,
         %User{id: user_id} = user,
   def get_topic(
         stream,
         %User{id: user_id} = user,
-        %Token{user_id: token_user_id} = oauth_token,
+        %Token{user_id: user_id} = oauth_token,
         _params
       )
         _params
       )
-      when stream in @user_streams and user_id == token_user_id do
+      when stream in @user_streams do
     # Note: "read" works for all user streams (not mentioning it since it's an ancestor scope)
     required_scopes =
       if stream == "user:notification" do
     # Note: "read" works for all user streams (not mentioning it since it's an ancestor scope)
     required_scopes =
       if stream == "user:notification" do
@@ -97,10 +96,9 @@ defmodule Pleroma.Web.Streamer do
   def get_topic(
         "list",
         %User{id: user_id} = user,
   def get_topic(
         "list",
         %User{id: user_id} = user,
-        %Token{user_id: token_user_id} = oauth_token,
+        %Token{user_id: user_id} = oauth_token,
         %{"list" => id}
         %{"list" => id}
-      )
-      when user_id == token_user_id do
+      ) do
     cond do
       OAuthScopesPlug.filter_descendants(["read", "read:lists"], oauth_token.scopes) == [] ->
         {:error, :unauthorized}
     cond do
       OAuthScopesPlug.filter_descendants(["read", "read:lists"], oauth_token.scopes) == [] ->
         {:error, :unauthorized}
@@ -137,16 +135,10 @@ defmodule Pleroma.Web.Streamer do
 
   def stream(topics, items) do
     if should_env_send?() do
 
   def stream(topics, items) do
     if should_env_send?() do
-      List.wrap(topics)
-      |> Enum.each(fn topic ->
-        List.wrap(items)
-        |> Enum.each(fn item ->
-          spawn(fn -> do_stream(topic, item) end)
-        end)
-      end)
+      for topic <- List.wrap(topics), item <- List.wrap(items) do
+        spawn(fn -> do_stream(topic, item) end)
+      end
     end
     end
-
-    :ok
   end
 
   def filtered_by_user?(user, item, streamed_type \\ :activity)
   end
 
   def filtered_by_user?(user, item, streamed_type \\ :activity)
@@ -160,8 +152,7 @@ defmodule Pleroma.Web.Streamer do
     domain_blocks = Pleroma.Web.ActivityPub.MRF.subdomains_regex(user.domain_blocks)
 
     with parent <- Object.normalize(item) || item,
     domain_blocks = Pleroma.Web.ActivityPub.MRF.subdomains_regex(user.domain_blocks)
 
     with parent <- Object.normalize(item) || item,
-         true <-
-           Enum.all?([blocked_ap_ids, muted_ap_ids], &(item.actor not in &1)),
+         true <- Enum.all?([blocked_ap_ids, muted_ap_ids], &(item.actor not in &1)),
          true <- item.data["type"] != "Announce" || item.actor not in reblog_muted_ap_ids,
          true <-
            !(streamed_type == :activity && item.data["type"] == "Announce" &&
          true <- item.data["type"] != "Announce" || item.actor not in reblog_muted_ap_ids,
          true <-
            !(streamed_type == :activity && item.data["type"] == "Announce" &&
@@ -195,6 +186,22 @@ defmodule Pleroma.Web.Streamer do
     end)
   end
 
     end)
   end
 
+  defp do_stream("relationships:update", item) do
+    text = StreamerView.render("relationships_update.json", item)
+
+    [item.follower, item.following]
+    |> Enum.map(fn %{id: id} -> "user:#{id}" end)
+    |> Enum.each(fn user_topic ->
+      Logger.debug("Trying to push relationships:update to #{user_topic}\n\n")
+
+      Registry.dispatch(@registry, user_topic, fn list ->
+        Enum.each(list, fn {pid, _auth} ->
+          send(pid, {:text, text})
+        end)
+      end)
+    end)
+  end
+
   defp do_stream("participation", participation) do
     user_topic = "direct:#{participation.user_id}"
     Logger.debug("Trying to push a conversation participation to #{user_topic}\n\n")
   defp do_stream("participation", participation) do
     user_topic = "direct:#{participation.user_id}"
     Logger.debug("Trying to push a conversation participation to #{user_topic}\n\n")
index 476a3324513a1f42d2b8f13022d1a740f20ad464..92239a411c254771e144a6c6137d487a68d33361 100644 (file)
@@ -74,6 +74,28 @@ defmodule Pleroma.Web.StreamerView do
     |> Jason.encode!()
   end
 
     |> Jason.encode!()
   end
 
+  def render("relationships_update.json", item) do
+    %{
+      event: "pleroma:relationships_update",
+      payload:
+        %{
+          state: item.state,
+          follower: %{
+            id: item.follower.id,
+            follower_count: item.follower.follower_count,
+            following_count: item.follower.following_count
+          },
+          following: %{
+            id: item.following.id,
+            follower_count: item.following.follower_count,
+            following_count: item.following.following_count
+          }
+        }
+        |> Jason.encode!()
+    }
+    |> Jason.encode!()
+  end
+
   def render("conversation.json", %Participation{} = participation) do
     %{
       event: "conversation",
   def render("conversation.json", %Participation{} = participation) do
     %{
       event: "conversation",
index 292a5ef5f3edaf4b09537308ebd22c530ff38fe8..a4bd41922b67f8d7d3a725968708c3edb92211ae 100644 (file)
@@ -73,7 +73,7 @@ defmodule Mix.Tasks.Pleroma.DatabaseTest do
   describe "running update_users_following_followers_counts" do
     test "following and followers count are updated" do
       [user, user2] = insert_pair(:user)
   describe "running update_users_following_followers_counts" do
     test "following and followers count are updated" do
       [user, user2] = insert_pair(:user)
-      {:ok, %User{} = user} = User.follow(user, user2)
+      {:ok, %User{} = user, _user2} = User.follow(user, user2)
 
       following = User.following(user)
 
 
       following = User.following(user)
 
index ce819f815064affd5b8570a08ddcd0cec56e5922..be0cb2668f6ada116fa9d0af31c4ab1dc7cb94e8 100644 (file)
@@ -503,7 +503,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
       moot = insert(:user, nickname: "moot")
       kawen = insert(:user, nickname: "kawen", name: "fediverse expert moon")
 
       moot = insert(:user, nickname: "moot")
       kawen = insert(:user, nickname: "kawen", name: "fediverse expert moon")
 
-      {:ok, user} = User.follow(user, moon)
+      {:ok, user, moon} = User.follow(user, moon)
 
       assert [moon.id, kawen.id] == User.Search.search("moon") |> Enum.map(& &1.id)
 
 
       assert [moon.id, kawen.id] == User.Search.search("moon") |> Enum.map(& &1.id)
 
index eb716486ece45594e44571d81f71f9c8e0c3155b..e605c2726b66b388f62f7d6bb376c329b51bbb1d 100644 (file)
@@ -19,7 +19,7 @@ defmodule Pleroma.BBS.HandlerTest do
     user = insert(:user)
     followed = insert(:user)
 
     user = insert(:user)
     followed = insert(:user)
 
-    {:ok, user} = User.follow(user, followed)
+    {:ok, user, followed} = User.follow(user, followed)
 
     {:ok, _first} = CommonAPI.post(user, %{status: "hey"})
     {:ok, _second} = CommonAPI.post(followed, %{status: "hello"})
 
     {:ok, _first} = CommonAPI.post(user, %{status: "hey"})
     {:ok, _second} = CommonAPI.post(followed, %{status: "hello"})
index ed2cd219da5d60a760dba3439f07f96b9c8b9b18..a6558f9955a5e0c5e14a55e879583bd754812b11 100644 (file)
@@ -779,7 +779,7 @@ defmodule Pleroma.NotificationTest do
       other_user = insert(:user)
 
       {:ok, other_user} = User.block_domain(other_user, blocked_domain)
       other_user = insert(:user)
 
       {:ok, other_user} = User.block_domain(other_user, blocked_domain)
-      {:ok, other_user} = User.follow(other_user, user)
+      {:ok, other_user, user} = User.follow(other_user, user)
 
       {:ok, activity} = CommonAPI.post(user, %{status: "hey @#{other_user.nickname}!"})
 
 
       {:ok, activity} = CommonAPI.post(user, %{status: "hey @#{other_user.nickname}!"})
 
@@ -1070,7 +1070,7 @@ defmodule Pleroma.NotificationTest do
       blocked = insert(:user, ap_id: "http://some-domain.com")
 
       {:ok, user} = User.block_domain(user, "some-domain.com")
       blocked = insert(:user, ap_id: "http://some-domain.com")
 
       {:ok, user} = User.block_domain(user, "some-domain.com")
-      {:ok, _} = User.follow(user, blocked)
+      {:ok, _, _} = User.follow(user, blocked)
 
       {:ok, _activity} = CommonAPI.post(blocked, %{status: "hey @#{user.nickname}"})
 
 
       {:ok, _activity} = CommonAPI.post(blocked, %{status: "hey @#{user.nickname}"})
 
index e404deeb56890ed5902f26b7d544b5193cf7ac11..e198cdc0862ac37927dd49f20e549fb53b888930 100644 (file)
@@ -30,7 +30,7 @@ defmodule Pleroma.User.ImportTest do
 
       assert {:ok, result} = ObanHelpers.perform(job)
       assert is_list(result)
 
       assert {:ok, result} = ObanHelpers.perform(job)
       assert is_list(result)
-      assert result == [user2, user3]
+      assert result == [refresh_record(user2), refresh_record(user3)]
       assert User.following?(user1, user2)
       assert User.following?(user1, user3)
     end
       assert User.following?(user1, user2)
       assert User.following?(user1, user3)
     end
index de1df2e9c362264295c492b44426e285d29934bd..accb0b816dbfc41ea261d3cb67eb182bd4309828 100644 (file)
@@ -151,8 +151,8 @@ defmodule Pleroma.UserSearchTest do
       follower = insert(:user, %{name: "Doe"})
       friend = insert(:user, %{name: "Doe"})
 
       follower = insert(:user, %{name: "Doe"})
       friend = insert(:user, %{name: "Doe"})
 
-      {:ok, follower} = User.follow(follower, u1)
-      {:ok, u1} = User.follow(u1, friend)
+      {:ok, follower, u1} = User.follow(follower, u1)
+      {:ok, u1, friend} = User.follow(u1, friend)
 
       assert [friend.id, follower.id, u2.id] --
                Enum.map(User.search("doe", resolve: false, for_user: u1), & &1.id) == []
 
       assert [friend.id, follower.id, u2.id] --
                Enum.map(User.search("doe", resolve: false, for_user: u1), & &1.id) == []
@@ -165,9 +165,9 @@ defmodule Pleroma.UserSearchTest do
       following_jimi = insert(:user, %{name: "Lizz Wright"})
       follower_lizz = insert(:user, %{name: "Jimi"})
 
       following_jimi = insert(:user, %{name: "Lizz Wright"})
       follower_lizz = insert(:user, %{name: "Jimi"})
 
-      {:ok, lizz} = User.follow(lizz, following_lizz)
-      {:ok, _jimi} = User.follow(jimi, following_jimi)
-      {:ok, _follower_lizz} = User.follow(follower_lizz, lizz)
+      {:ok, lizz, following_lizz} = User.follow(lizz, following_lizz)
+      {:ok, _jimi, _following_jimi} = User.follow(jimi, following_jimi)
+      {:ok, _follower_lizz, _lizz} = User.follow(follower_lizz, lizz)
 
       assert Enum.map(User.search("jimi", following: true, for_user: lizz), & &1.id) == [
                following_lizz.id
 
       assert Enum.map(User.search("jimi", following: true, for_user: lizz), & &1.id) == [
                following_lizz.id
index c678dadb3075ba0e092156beee902a4037702c66..05a084ec4d44a21e7fab225e83a5ec69d10052fe 100644 (file)
@@ -233,7 +233,7 @@ defmodule Pleroma.UserTest do
     {:ok, _user_relationship} = User.block(user, blocked)
     {:ok, _user_relationship} = User.block(reverse_blocked, user)
 
     {:ok, _user_relationship} = User.block(user, blocked)
     {:ok, _user_relationship} = User.block(reverse_blocked, user)
 
-    {:ok, user} = User.follow(user, followed_zero)
+    {:ok, user, followed_zero} = User.follow(user, followed_zero)
 
     {:ok, user} = User.follow_all(user, [followed_one, followed_two, blocked, reverse_blocked])
 
 
     {:ok, user} = User.follow_all(user, [followed_one, followed_two, blocked, reverse_blocked])
 
@@ -262,7 +262,7 @@ defmodule Pleroma.UserTest do
     user = insert(:user)
     followed = insert(:user)
 
     user = insert(:user)
     followed = insert(:user)
 
-    {:ok, user} = User.follow(user, followed)
+    {:ok, user, followed} = User.follow(user, followed)
 
     user = User.get_cached_by_id(user.id)
     followed = User.get_cached_by_ap_id(followed.ap_id)
 
     user = User.get_cached_by_id(user.id)
     followed = User.get_cached_by_ap_id(followed.ap_id)
@@ -302,7 +302,7 @@ defmodule Pleroma.UserTest do
     follower = insert(:user, is_locked: true)
     followed = insert(:user, is_locked: true)
 
     follower = insert(:user, is_locked: true)
     followed = insert(:user, is_locked: true)
 
-    {:ok, follower} = User.maybe_direct_follow(follower, followed)
+    {:ok, follower, followed} = User.maybe_direct_follow(follower, followed)
 
     refute User.following?(follower, followed)
   end
 
     refute User.following?(follower, followed)
   end
@@ -330,7 +330,7 @@ defmodule Pleroma.UserTest do
           following_address: "http://localhost:4001/users/fuser2/following"
         })
 
           following_address: "http://localhost:4001/users/fuser2/following"
         })
 
-      {:ok, user} = User.follow(user, followed, :follow_accept)
+      {:ok, user, followed} = User.follow(user, followed, :follow_accept)
 
       {:ok, user, _activity} = User.unfollow(user, followed)
 
 
       {:ok, user, _activity} = User.unfollow(user, followed)
 
@@ -343,7 +343,7 @@ defmodule Pleroma.UserTest do
       followed = insert(:user)
       user = insert(:user)
 
       followed = insert(:user)
       user = insert(:user)
 
-      {:ok, user} = User.follow(user, followed, :follow_accept)
+      {:ok, user, followed} = User.follow(user, followed, :follow_accept)
 
       assert User.following(user) == [user.follower_address, followed.follower_address]
 
 
       assert User.following(user) == [user.follower_address, followed.follower_address]
 
@@ -904,8 +904,8 @@ defmodule Pleroma.UserTest do
       follower_two = insert(:user)
       not_follower = insert(:user)
 
       follower_two = insert(:user)
       not_follower = insert(:user)
 
-      {:ok, follower_one} = User.follow(follower_one, user)
-      {:ok, follower_two} = User.follow(follower_two, user)
+      {:ok, follower_one, user} = User.follow(follower_one, user)
+      {:ok, follower_two, user} = User.follow(follower_two, user)
 
       res = User.get_followers(user)
 
 
       res = User.get_followers(user)
 
@@ -920,8 +920,8 @@ defmodule Pleroma.UserTest do
       followed_two = insert(:user)
       not_followed = insert(:user)
 
       followed_two = insert(:user)
       not_followed = insert(:user)
 
-      {:ok, user} = User.follow(user, followed_one)
-      {:ok, user} = User.follow(user, followed_two)
+      {:ok, user, followed_one} = User.follow(user, followed_one)
+      {:ok, user, followed_two} = User.follow(user, followed_two)
 
       res = User.get_friends(user)
 
 
       res = User.get_friends(user)
 
@@ -1091,8 +1091,8 @@ defmodule Pleroma.UserTest do
       blocker = insert(:user)
       blocked = insert(:user)
 
       blocker = insert(:user)
       blocked = insert(:user)
 
-      {:ok, blocker} = User.follow(blocker, blocked)
-      {:ok, blocked} = User.follow(blocked, blocker)
+      {:ok, blocker, blocked} = User.follow(blocker, blocked)
+      {:ok, blocked, blocker} = User.follow(blocked, blocker)
 
       assert User.following?(blocker, blocked)
       assert User.following?(blocked, blocker)
 
       assert User.following?(blocker, blocked)
       assert User.following?(blocked, blocker)
@@ -1110,7 +1110,7 @@ defmodule Pleroma.UserTest do
       blocker = insert(:user)
       blocked = insert(:user)
 
       blocker = insert(:user)
       blocked = insert(:user)
 
-      {:ok, blocker} = User.follow(blocker, blocked)
+      {:ok, blocker, blocked} = User.follow(blocker, blocked)
 
       assert User.following?(blocker, blocked)
       refute User.following?(blocked, blocker)
 
       assert User.following?(blocker, blocked)
       refute User.following?(blocked, blocker)
@@ -1128,7 +1128,7 @@ defmodule Pleroma.UserTest do
       blocker = insert(:user)
       blocked = insert(:user)
 
       blocker = insert(:user)
       blocked = insert(:user)
 
-      {:ok, blocked} = User.follow(blocked, blocker)
+      {:ok, blocked, blocker} = User.follow(blocked, blocker)
 
       refute User.following?(blocker, blocked)
       assert User.following?(blocked, blocker)
 
       refute User.following?(blocker, blocked)
       assert User.following?(blocked, blocker)
@@ -1226,7 +1226,7 @@ defmodule Pleroma.UserTest do
       good_eggo = insert(:user, %{ap_id: "https://meanies.social/user/cuteposter"})
 
       {:ok, user} = User.block_domain(user, "meanies.social")
       good_eggo = insert(:user, %{ap_id: "https://meanies.social/user/cuteposter"})
 
       {:ok, user} = User.block_domain(user, "meanies.social")
-      {:ok, user} = User.follow(user, good_eggo)
+      {:ok, user, good_eggo} = User.follow(user, good_eggo)
 
       refute User.blocks?(user, good_eggo)
     end
 
       refute User.blocks?(user, good_eggo)
     end
@@ -1260,8 +1260,8 @@ defmodule Pleroma.UserTest do
       assert Enum.map([actor, addressed], & &1.ap_id) --
                Enum.map(User.get_recipients_from_activity(activity), & &1.ap_id) == []
 
       assert Enum.map([actor, addressed], & &1.ap_id) --
                Enum.map(User.get_recipients_from_activity(activity), & &1.ap_id) == []
 
-      {:ok, user} = User.follow(user, actor)
-      {:ok, _user_two} = User.follow(user_two, actor)
+      {:ok, user, actor} = User.follow(user, actor)
+      {:ok, _user_two, _actor} = User.follow(user_two, actor)
       recipients = User.get_recipients_from_activity(activity)
       assert length(recipients) == 3
       assert user in recipients
       recipients = User.get_recipients_from_activity(activity)
       assert length(recipients) == 3
       assert user in recipients
@@ -1282,8 +1282,8 @@ defmodule Pleroma.UserTest do
       assert Enum.map([actor, addressed], & &1.ap_id) --
                Enum.map(User.get_recipients_from_activity(activity), & &1.ap_id) == []
 
       assert Enum.map([actor, addressed], & &1.ap_id) --
                Enum.map(User.get_recipients_from_activity(activity), & &1.ap_id) == []
 
-      {:ok, _actor} = User.follow(actor, user)
-      {:ok, _actor} = User.follow(actor, user_two)
+      {:ok, _actor, _user} = User.follow(actor, user)
+      {:ok, _actor, _user_two} = User.follow(actor, user_two)
       recipients = User.get_recipients_from_activity(activity)
       assert length(recipients) == 2
       assert addressed in recipients
       recipients = User.get_recipients_from_activity(activity)
       assert length(recipients) == 2
       assert addressed in recipients
@@ -1304,7 +1304,7 @@ defmodule Pleroma.UserTest do
       user = insert(:user)
       user2 = insert(:user)
 
       user = insert(:user)
       user2 = insert(:user)
 
-      {:ok, user} = User.follow(user, user2)
+      {:ok, user, user2} = User.follow(user, user2)
       {:ok, _user} = User.deactivate(user)
 
       user2 = User.get_cached_by_id(user2.id)
       {:ok, _user} = User.deactivate(user)
 
       user2 = User.get_cached_by_id(user2.id)
@@ -1317,7 +1317,7 @@ defmodule Pleroma.UserTest do
       user = insert(:user)
       user2 = insert(:user)
 
       user = insert(:user)
       user2 = insert(:user)
 
-      {:ok, user2} = User.follow(user2, user)
+      {:ok, user2, user} = User.follow(user2, user)
       assert user2.following_count == 1
       assert User.following_count(user2) == 1
 
       assert user2.following_count == 1
       assert User.following_count(user2) == 1
 
@@ -1335,7 +1335,7 @@ defmodule Pleroma.UserTest do
       user = insert(:user)
       user2 = insert(:user)
 
       user = insert(:user)
       user2 = insert(:user)
 
-      {:ok, user2} = User.follow(user2, user)
+      {:ok, user2, user} = User.follow(user2, user)
 
       {:ok, activity} = CommonAPI.post(user, %{status: "hey @#{user2.nickname}"})
 
 
       {:ok, activity} = CommonAPI.post(user, %{status: "hey @#{user2.nickname}"})
 
@@ -1408,10 +1408,10 @@ defmodule Pleroma.UserTest do
 
     test "it deactivates a user, all follow relationships and all activities", %{user: user} do
       follower = insert(:user)
 
     test "it deactivates a user, all follow relationships and all activities", %{user: user} do
       follower = insert(:user)
-      {:ok, follower} = User.follow(follower, user)
+      {:ok, follower, user} = User.follow(follower, user)
 
       locked_user = insert(:user, name: "locked", is_locked: true)
 
       locked_user = insert(:user, name: "locked", is_locked: true)
-      {:ok, _} = User.follow(user, locked_user, :follow_pending)
+      {:ok, _, _} = User.follow(user, locked_user, :follow_pending)
 
       object = insert(:note, user: user)
       activity = insert(:note_activity, user: user, note: object)
 
       object = insert(:note, user: user)
       activity = insert(:note_activity, user: user, note: object)
@@ -1769,9 +1769,9 @@ defmodule Pleroma.UserTest do
     follower2 = insert(:user)
     follower3 = insert(:user)
 
     follower2 = insert(:user)
     follower3 = insert(:user)
 
-    {:ok, follower} = User.follow(follower, user)
-    {:ok, _follower2} = User.follow(follower2, user)
-    {:ok, _follower3} = User.follow(follower3, user)
+    {:ok, follower, user} = User.follow(follower, user)
+    {:ok, _follower2, _user} = User.follow(follower2, user)
+    {:ok, _follower3, _user} = User.follow(follower3, user)
 
     {:ok, _user_relationship} = User.block(user, follower)
     user = refresh_record(user)
 
     {:ok, _user_relationship} = User.block(user, follower)
     user = refresh_record(user)
@@ -2012,8 +2012,7 @@ defmodule Pleroma.UserTest do
       assert other_user.following_count == 0
       assert other_user.follower_count == 0
 
       assert other_user.following_count == 0
       assert other_user.follower_count == 0
 
-      {:ok, user} = Pleroma.User.follow(user, other_user)
-      other_user = Pleroma.User.get_by_id(other_user.id)
+      {:ok, user, other_user} = Pleroma.User.follow(user, other_user)
 
       assert user.following_count == 1
       assert other_user.follower_count == 1
 
       assert user.following_count == 1
       assert other_user.follower_count == 1
@@ -2036,8 +2035,7 @@ defmodule Pleroma.UserTest do
       assert other_user.follower_count == 0
 
       Pleroma.Config.put([:instance, :external_user_synchronization], true)
       assert other_user.follower_count == 0
 
       Pleroma.Config.put([:instance, :external_user_synchronization], true)
-      {:ok, _user} = User.follow(user, other_user)
-      other_user = User.get_by_id(other_user.id)
+      {:ok, _user, other_user} = User.follow(user, other_user)
 
       assert other_user.follower_count == 437
     end
 
       assert other_user.follower_count == 437
     end
@@ -2059,7 +2057,7 @@ defmodule Pleroma.UserTest do
       assert other_user.follower_count == 0
 
       Pleroma.Config.put([:instance, :external_user_synchronization], true)
       assert other_user.follower_count == 0
 
       Pleroma.Config.put([:instance, :external_user_synchronization], true)
-      {:ok, other_user} = User.follow(other_user, user)
+      {:ok, other_user, _user} = User.follow(other_user, user)
 
       assert other_user.following_count == 152
     end
 
       assert other_user.following_count == 152
     end
index c9b42148911df86a99a657670337bdb6938add54..0063d048298b8f6a15d3d738fbbff7125f21d492 100644 (file)
@@ -675,7 +675,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
       recipient = insert(:user)
       actor = insert(:user, %{ap_id: "http://mastodon.example.org/users/actor"})
 
       recipient = insert(:user)
       actor = insert(:user, %{ap_id: "http://mastodon.example.org/users/actor"})
 
-      {:ok, recipient} = User.follow(recipient, actor)
+      {:ok, recipient, actor} = User.follow(recipient, actor)
 
       object =
         data["object"]
 
       object =
         data["object"]
index 6cc25dd9e73a7561dca9e6df28e0be12db97cd72..9eb7ae86b138a0c40b949174f196a557b784fc2c 100644 (file)
@@ -726,7 +726,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
     domain_user = insert(:user, %{ap_id: "https://#{domain}/@pundit"})
     blocker = insert(:user)
 
     domain_user = insert(:user, %{ap_id: "https://#{domain}/@pundit"})
     blocker = insert(:user)
 
-    {:ok, blocker} = User.follow(blocker, domain_user)
+    {:ok, blocker, domain_user} = User.follow(blocker, domain_user)
     {:ok, blocker} = User.block_domain(blocker, domain)
 
     assert User.following?(blocker, domain_user)
     {:ok, blocker} = User.block_domain(blocker, domain)
 
     assert User.following?(blocker, domain_user)
@@ -853,7 +853,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
     user = insert(:user)
     booster = insert(:user)
 
     user = insert(:user)
     booster = insert(:user)
 
-    {:ok, user} = User.follow(user, booster)
+    {:ok, user, booster} = User.follow(user, booster)
 
     {:ok, announce} = CommonAPI.repeat(activity_three.id, booster)
 
 
     {:ok, announce} = CommonAPI.repeat(activity_three.id, booster)
 
@@ -1158,13 +1158,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
       user2 = insert(:user)
       user3 = insert(:user)
 
       user2 = insert(:user)
       user3 = insert(:user)
 
-      {:ok, user1} = User.follow(user1, user3)
+      {:ok, user1, user3} = User.follow(user1, user3)
       assert User.following?(user1, user3)
 
       assert User.following?(user1, user3)
 
-      {:ok, user2} = User.follow(user2, user3)
+      {:ok, user2, user3} = User.follow(user2, user3)
       assert User.following?(user2, user3)
 
       assert User.following?(user2, user3)
 
-      {:ok, user3} = User.follow(user3, user2)
+      {:ok, user3, user2} = User.follow(user3, user2)
       assert User.following?(user3, user2)
 
       {:ok, public_activity} = CommonAPI.post(user3, %{status: "hi 1"})
       assert User.following?(user3, user2)
 
       {:ok, public_activity} = CommonAPI.post(user3, %{status: "hi 1"})
@@ -1931,13 +1931,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
 
   defp public_messages(_) do
     [u1, u2, u3, u4] = insert_list(4, :user)
 
   defp public_messages(_) do
     [u1, u2, u3, u4] = insert_list(4, :user)
-    {:ok, u1} = User.follow(u1, u2)
-    {:ok, u2} = User.follow(u2, u1)
-    {:ok, u1} = User.follow(u1, u4)
-    {:ok, u4} = User.follow(u4, u1)
+    {:ok, u1, u2} = User.follow(u1, u2)
+    {:ok, u2, u1} = User.follow(u2, u1)
+    {:ok, u1, u4} = User.follow(u1, u4)
+    {:ok, u4, u1} = User.follow(u4, u1)
 
 
-    {:ok, u2} = User.follow(u2, u3)
-    {:ok, u3} = User.follow(u3, u2)
+    {:ok, u2, u3} = User.follow(u2, u3)
+    {:ok, u3, u2} = User.follow(u3, u2)
 
     {:ok, a1} = CommonAPI.post(u1, %{status: "Status"})
 
 
     {:ok, a1} = CommonAPI.post(u1, %{status: "Status"})
 
@@ -2030,15 +2030,15 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
 
   defp private_messages(_) do
     [u1, u2, u3, u4] = insert_list(4, :user)
 
   defp private_messages(_) do
     [u1, u2, u3, u4] = insert_list(4, :user)
-    {:ok, u1} = User.follow(u1, u2)
-    {:ok, u2} = User.follow(u2, u1)
-    {:ok, u1} = User.follow(u1, u3)
-    {:ok, u3} = User.follow(u3, u1)
-    {:ok, u1} = User.follow(u1, u4)
-    {:ok, u4} = User.follow(u4, u1)
-
-    {:ok, u2} = User.follow(u2, u3)
-    {:ok, u3} = User.follow(u3, u2)
+    {:ok, u1, u2} = User.follow(u1, u2)
+    {:ok, u2, u1} = User.follow(u2, u1)
+    {:ok, u1, u3} = User.follow(u1, u3)
+    {:ok, u3, u1} = User.follow(u3, u1)
+    {:ok, u1, u4} = User.follow(u1, u4)
+    {:ok, u4, u1} = User.follow(u4, u1)
+
+    {:ok, u2, u3} = User.follow(u2, u3)
+    {:ok, u3, u2} = User.follow(u3, u2)
 
     {:ok, a1} = CommonAPI.post(u1, %{status: "Status", visibility: "private"})
 
 
     {:ok, a1} = CommonAPI.post(u1, %{status: "Status", visibility: "private"})
 
index b9388b966d5d3e067df18c325a54b8c146728a35..3503d25b22ce906116d91e70f8bd7065abee4030 100644 (file)
@@ -281,8 +281,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
       actor = insert(:user, follower_address: follower.ap_id)
       user = insert(:user)
 
       actor = insert(:user, follower_address: follower.ap_id)
       user = insert(:user)
 
-      {:ok, _follower_one} = Pleroma.User.follow(follower, actor)
-      actor = refresh_record(actor)
+      {:ok, follower, actor} = Pleroma.User.follow(follower, actor)
 
       note_activity =
         insert(:note_activity,
 
       note_activity =
         insert(:note_activity,
index 0d431df1832284f47bde5b751b5dca2770c500ea..485216487137c7c78397821199981639b201ce1e 100644 (file)
@@ -15,7 +15,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AcceptHandlingTest do
     follower = insert(:user)
     followed = insert(:user)
 
     follower = insert(:user)
     followed = insert(:user)
 
-    {:ok, follower} = User.follow(follower, followed)
+    {:ok, follower, followed} = User.follow(follower, followed)
     assert User.following?(follower, followed) == true
 
     {:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed)
     assert User.following?(follower, followed) == true
 
     {:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed)
index b8e4ad827f43ca84fd2b7ba9a8648aa683ebed42..679c33c6cac1fe25ef81157a15662436afb3f10d 100644 (file)
@@ -40,8 +40,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.BlockHandlingTest do
       |> Map.put("object", blocked.ap_id)
       |> Map.put("actor", blocker.ap_id)
 
       |> Map.put("object", blocked.ap_id)
       |> Map.put("actor", blocker.ap_id)
 
-    {:ok, blocker} = User.follow(blocker, blocked)
-    {:ok, blocked} = User.follow(blocked, blocker)
+    {:ok, blocker, blocked} = User.follow(blocker, blocked)
+    {:ok, blocked, blocker} = User.follow(blocked, blocker)
 
     assert User.following?(blocker, blocked)
     assert User.following?(blocked, blocker)
 
     assert User.following?(blocker, blocked)
     assert User.following?(blocked, blocker)
index cc28eb7ef6e6d9067eb985ce8807257ab375061f..5a3bef7921bf187ea37474d1a51fa6fa76aeda64 100644 (file)
@@ -35,7 +35,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.RejectHandlingTest do
     follower = insert(:user)
     followed = insert(:user, is_locked: true)
 
     follower = insert(:user)
     followed = insert(:user, is_locked: true)
 
-    {:ok, follower} = User.follow(follower, followed)
+    {:ok, follower, followed} = User.follow(follower, followed)
     {:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed)
 
     assert User.following?(follower, followed) == true
     {:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed)
 
     assert User.following?(follower, followed) == true
index 8e9354c659b71091fbe4dad563c79e7d60c63864..836d4499419b00cbeb3966f56c54f5a133296485 100644 (file)
@@ -15,7 +15,7 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
     mentioned = insert(:user)
     following = insert(:user)
     unrelated = insert(:user)
     mentioned = insert(:user)
     following = insert(:user)
     unrelated = insert(:user)
-    {:ok, following} = Pleroma.User.follow(following, user)
+    {:ok, following, user} = Pleroma.User.follow(following, user)
     {:ok, list} = Pleroma.List.create("foo", user)
 
     Pleroma.List.follow(list, unrelated)
     {:ok, list} = Pleroma.List.create("foo", user)
 
     Pleroma.List.follow(list, unrelated)
index e8a00dd6b812ab3c6843ec381a91e86cd988f1e6..3361c8669319313f1ee3a8586b6bf2be45a66648 100644 (file)
@@ -320,7 +320,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
       user_two = insert(:user)
       user_three = insert(:user)
 
       user_two = insert(:user)
       user_three = insert(:user)
 
-      {:ok, _user_three} = User.follow(user_three, user_one)
+      {:ok, _user_three, _user_one} = User.follow(user_three, user_one)
 
       {:ok, activity} = CommonAPI.post(user_one, %{status: "HI!!!"})
 
 
       {:ok, activity} = CommonAPI.post(user_one, %{status: "HI!!!"})
 
@@ -568,7 +568,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
 
     test "getting followers", %{user: user, conn: conn} do
       other_user = insert(:user)
 
     test "getting followers", %{user: user, conn: conn} do
       other_user = insert(:user)
-      {:ok, %{id: user_id}} = User.follow(user, other_user)
+      {:ok, %{id: user_id}, other_user} = User.follow(user, other_user)
 
       conn = get(conn, "/api/v1/accounts/#{other_user.id}/followers")
 
 
       conn = get(conn, "/api/v1/accounts/#{other_user.id}/followers")
 
@@ -577,7 +577,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
 
     test "getting followers, hide_followers", %{user: user, conn: conn} do
       other_user = insert(:user, hide_followers: true)
 
     test "getting followers, hide_followers", %{user: user, conn: conn} do
       other_user = insert(:user, hide_followers: true)
-      {:ok, _user} = User.follow(user, other_user)
+      {:ok, _user, _other_user} = User.follow(user, other_user)
 
       conn = get(conn, "/api/v1/accounts/#{other_user.id}/followers")
 
 
       conn = get(conn, "/api/v1/accounts/#{other_user.id}/followers")
 
@@ -587,7 +587,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
     test "getting followers, hide_followers, same user requesting" do
       user = insert(:user)
       other_user = insert(:user, hide_followers: true)
     test "getting followers, hide_followers, same user requesting" do
       user = insert(:user)
       other_user = insert(:user, hide_followers: true)
-      {:ok, _user} = User.follow(user, other_user)
+      {:ok, _user, _other_user} = User.follow(user, other_user)
 
       conn =
         build_conn()
 
       conn =
         build_conn()
@@ -599,9 +599,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
     end
 
     test "getting followers, pagination", %{user: user, conn: conn} do
     end
 
     test "getting followers, pagination", %{user: user, conn: conn} do
-      {:ok, %User{id: follower1_id}} = :user |> insert() |> User.follow(user)
-      {:ok, %User{id: follower2_id}} = :user |> insert() |> User.follow(user)
-      {:ok, %User{id: follower3_id}} = :user |> insert() |> User.follow(user)
+      {:ok, %User{id: follower1_id}, _user} = :user |> insert() |> User.follow(user)
+      {:ok, %User{id: follower2_id}, _user} = :user |> insert() |> User.follow(user)
+      {:ok, %User{id: follower3_id}, _user} = :user |> insert() |> User.follow(user)
 
       assert [%{"id" => ^follower3_id}, %{"id" => ^follower2_id}] =
                conn
 
       assert [%{"id" => ^follower3_id}, %{"id" => ^follower2_id}] =
                conn
@@ -637,7 +637,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
 
     test "getting following", %{user: user, conn: conn} do
       other_user = insert(:user)
 
     test "getting following", %{user: user, conn: conn} do
       other_user = insert(:user)
-      {:ok, user} = User.follow(user, other_user)
+      {:ok, user, other_user} = User.follow(user, other_user)
 
       conn = get(conn, "/api/v1/accounts/#{user.id}/following")
 
 
       conn = get(conn, "/api/v1/accounts/#{user.id}/following")
 
@@ -648,7 +648,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
     test "getting following, hide_follows, other user requesting" do
       user = insert(:user, hide_follows: true)
       other_user = insert(:user)
     test "getting following, hide_follows, other user requesting" do
       user = insert(:user, hide_follows: true)
       other_user = insert(:user)
-      {:ok, user} = User.follow(user, other_user)
+      {:ok, user, other_user} = User.follow(user, other_user)
 
       conn =
         build_conn()
 
       conn =
         build_conn()
@@ -662,7 +662,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
     test "getting following, hide_follows, same user requesting" do
       user = insert(:user, hide_follows: true)
       other_user = insert(:user)
     test "getting following, hide_follows, same user requesting" do
       user = insert(:user, hide_follows: true)
       other_user = insert(:user)
-      {:ok, user} = User.follow(user, other_user)
+      {:ok, user, _other_user} = User.follow(user, other_user)
 
       conn =
         build_conn()
 
       conn =
         build_conn()
@@ -677,9 +677,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
       following1 = insert(:user)
       following2 = insert(:user)
       following3 = insert(:user)
       following1 = insert(:user)
       following2 = insert(:user)
       following3 = insert(:user)
-      {:ok, _} = User.follow(user, following1)
-      {:ok, _} = User.follow(user, following2)
-      {:ok, _} = User.follow(user, following3)
+      {:ok, _, _} = User.follow(user, following1)
+      {:ok, _, _} = User.follow(user, following2)
+      {:ok, _, _} = User.follow(user, following3)
 
       res_conn = get(conn, "/api/v1/accounts/#{user.id}/following?since_id=#{following1.id}")
 
 
       res_conn = get(conn, "/api/v1/accounts/#{user.id}/following?since_id=#{following1.id}")
 
@@ -1520,7 +1520,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
 
     test "returns the relationships for the current user", %{user: user, conn: conn} do
       %{id: other_user_id} = other_user = insert(:user)
 
     test "returns the relationships for the current user", %{user: user, conn: conn} do
       %{id: other_user_id} = other_user = insert(:user)
-      {:ok, _user} = User.follow(user, other_user)
+      {:ok, _user, _other_user} = User.follow(user, other_user)
 
       assert [%{"id" => ^other_user_id}] =
                conn
 
       assert [%{"id" => ^other_user_id}] =
                conn
index c67e584dd73632762cadcaf5eaf0cf610e3e9e73..b00615ac9ece5c67f23c4d7698b3dfb57c632989 100644 (file)
@@ -18,7 +18,7 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
       user_two = insert(:user)
       user_three = insert(:user)
 
       user_two = insert(:user)
       user_three = insert(:user)
 
-      {:ok, user_two} = User.follow(user_two, user_one)
+      {:ok, user_two, user_one} = User.follow(user_two, user_one)
 
       {:ok, %{user: user_one, user_two: user_two, user_three: user_three, conn: conn}}
     end
 
       {:ok, %{user: user_one, user_two: user_two, user_three: user_three, conn: conn}}
     end
index a9dd7cd30aaeee4e516223909b127d9be9112aa3..b977b41ae0ab1fec866ffad9d786f20cb4fd25ed 100644 (file)
@@ -21,7 +21,7 @@ defmodule Pleroma.Web.MastodonAPI.FollowRequestControllerTest do
       other_user = insert(:user)
 
       {:ok, _, _, _activity} = CommonAPI.follow(other_user, user)
       other_user = insert(:user)
 
       {:ok, _, _, _activity} = CommonAPI.follow(other_user, user)
-      {:ok, other_user} = User.follow(other_user, user, :follow_pending)
+      {:ok, other_user, user} = User.follow(other_user, user, :follow_pending)
 
       assert User.following?(other_user, user) == false
 
 
       assert User.following?(other_user, user) == false
 
@@ -35,7 +35,7 @@ defmodule Pleroma.Web.MastodonAPI.FollowRequestControllerTest do
       other_user = insert(:user)
 
       {:ok, _, _, _activity} = CommonAPI.follow(other_user, user)
       other_user = insert(:user)
 
       {:ok, _, _, _activity} = CommonAPI.follow(other_user, user)
-      {:ok, other_user} = User.follow(other_user, user, :follow_pending)
+      {:ok, other_user, user} = User.follow(other_user, user, :follow_pending)
 
       user = User.get_cached_by_id(user.id)
       other_user = User.get_cached_by_id(other_user.id)
 
       user = User.get_cached_by_id(user.id)
       other_user = User.get_cached_by_id(other_user.id)
index 8356b64d373088d8ee12c5ffb1cb37245e9664b0..655e35ac6c16b8f0919f6ebd8569fb30c40c6dea 100644 (file)
@@ -136,7 +136,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
     test "doesn't return replies if follower is posting with blocked user" do
       %{conn: conn, user: blocker} = oauth_access(["read:statuses"])
       [blockee, friend] = insert_list(2, :user)
     test "doesn't return replies if follower is posting with blocked user" do
       %{conn: conn, user: blocker} = oauth_access(["read:statuses"])
       [blockee, friend] = insert_list(2, :user)
-      {:ok, blocker} = User.follow(blocker, friend)
+      {:ok, blocker, friend} = User.follow(blocker, friend)
       {:ok, _} = User.block(blocker, blockee)
 
       conn = assign(conn, :user, blocker)
       {:ok, _} = User.block(blocker, blockee)
 
       conn = assign(conn, :user, blocker)
@@ -165,7 +165,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
       %{conn: conn, user: blocker} = oauth_access(["read:statuses"])
       friend = insert(:user)
       blockee = insert(:user, ap_id: "https://example.com/users/blocked")
       %{conn: conn, user: blocker} = oauth_access(["read:statuses"])
       friend = insert(:user)
       blockee = insert(:user, ap_id: "https://example.com/users/blocked")
-      {:ok, blocker} = User.follow(blocker, friend)
+      {:ok, blocker, friend} = User.follow(blocker, friend)
       {:ok, blocker} = User.block_domain(blocker, "example.com")
 
       conn = assign(conn, :user, blocker)
       {:ok, blocker} = User.block_domain(blocker, "example.com")
 
       conn = assign(conn, :user, blocker)
@@ -336,7 +336,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
       user_one = insert(:user)
       user_two = insert(:user)
 
       user_one = insert(:user)
       user_two = insert(:user)
 
-      {:ok, user_two} = User.follow(user_two, user_one)
+      {:ok, user_two, user_one} = User.follow(user_two, user_one)
 
       {:ok, direct} =
         CommonAPI.post(user_one, %{
 
       {:ok, direct} =
         CommonAPI.post(user_one, %{
index 0c5a38bf649e0968b8861c98597f1e167b479af4..687fe55851e4d557eb712154ad95dbf2f1cf4228 100644 (file)
@@ -30,7 +30,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPITest do
     test "returns ok if user already followed" do
       follower = insert(:user)
       user = insert(:user)
     test "returns ok if user already followed" do
       follower = insert(:user)
       user = insert(:user)
-      {:ok, follower} = User.follow(follower, user)
+      {:ok, follower, user} = User.follow(follower, user)
       {:ok, follower} = MastodonAPI.follow(follower, refresh_record(user))
       assert User.following?(follower, user)
     end
       {:ok, follower} = MastodonAPI.follow(follower, refresh_record(user))
       assert User.following?(follower, user)
     end
@@ -41,8 +41,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPITest do
       follower1_user = insert(:user)
       follower2_user = insert(:user)
       user = insert(:user)
       follower1_user = insert(:user)
       follower2_user = insert(:user)
       user = insert(:user)
-      {:ok, _follower1_user} = User.follow(follower1_user, user)
-      {:ok, follower2_user} = User.follow(follower2_user, user)
+      {:ok, _follower1_user, _user} = User.follow(follower1_user, user)
+      {:ok, follower2_user, _user} = User.follow(follower2_user, user)
 
       assert MastodonAPI.get_followers(user, %{"limit" => 1}) == [follower2_user]
     end
 
       assert MastodonAPI.get_followers(user, %{"limit" => 1}) == [follower2_user]
     end
@@ -55,9 +55,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPITest do
       followed_two = insert(:user)
       followed_three = insert(:user)
 
       followed_two = insert(:user)
       followed_three = insert(:user)
 
-      {:ok, user} = User.follow(user, followed_one)
-      {:ok, user} = User.follow(user, followed_two)
-      {:ok, user} = User.follow(user, followed_three)
+      {:ok, user, followed_one} = User.follow(user, followed_one)
+      {:ok, user, followed_two} = User.follow(user, followed_two)
+      {:ok, user, followed_three} = User.follow(user, followed_three)
       res = MastodonAPI.get_friends(user)
 
       assert length(res) == 3
       res = MastodonAPI.get_friends(user)
 
       assert length(res) == 3
index 139e32362104907bcb49b38a651c33d7ac3c1281..8c77f14d44e06103f3de7b248ca464f49f26b450 100644 (file)
@@ -274,8 +274,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
       user = insert(:user)
       other_user = insert(:user)
 
       user = insert(:user)
       other_user = insert(:user)
 
-      {:ok, user} = User.follow(user, other_user)
-      {:ok, other_user} = User.follow(other_user, user)
+      {:ok, user, other_user} = User.follow(user, other_user)
+      {:ok, other_user, user} = User.follow(other_user, user)
       {:ok, _subscription} = User.subscribe(user, other_user)
       {:ok, _user_relationships} = User.mute(user, other_user, %{notifications: true})
       {:ok, _reblog_mute} = CommonAPI.hide_reblogs(user, other_user)
       {:ok, _subscription} = User.subscribe(user, other_user)
       {:ok, _user_relationships} = User.mute(user, other_user, %{notifications: true})
       {:ok, _reblog_mute} = CommonAPI.hide_reblogs(user, other_user)
@@ -301,7 +301,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
       user = insert(:user)
       other_user = insert(:user)
 
       user = insert(:user)
       other_user = insert(:user)
 
-      {:ok, user} = User.follow(user, other_user)
+      {:ok, user, other_user} = User.follow(user, other_user)
       {:ok, _subscription} = User.subscribe(user, other_user)
       {:ok, _user_relationship} = User.block(user, other_user)
       {:ok, _user_relationship} = User.block(other_user, user)
       {:ok, _subscription} = User.subscribe(user, other_user)
       {:ok, _user_relationship} = User.block(user, other_user)
       {:ok, _user_relationship} = User.block(other_user, user)
index 68723de7141060164ac4de5893e36f1863cf6cba..d83d33912dfe6a6cd0a90bb68ed894dd63e0e524 100644 (file)
@@ -47,7 +47,8 @@ defmodule Pleroma.Web.PleromaAPI.UserImportControllerTest do
                  |> json_response_and_validate_schema(200)
 
         assert [{:ok, job_result}] = ObanHelpers.perform_all()
                  |> json_response_and_validate_schema(200)
 
         assert [{:ok, job_result}] = ObanHelpers.perform_all()
-        assert job_result == [user2]
+        assert job_result == [refresh_record(user2)]
+        assert [%Pleroma.User{follower_count: 1}] = job_result
       end
     end
 
       end
     end
 
@@ -108,7 +109,7 @@ defmodule Pleroma.Web.PleromaAPI.UserImportControllerTest do
                |> json_response_and_validate_schema(200)
 
       assert [{:ok, job_result}] = ObanHelpers.perform_all()
                |> json_response_and_validate_schema(200)
 
       assert [{:ok, job_result}] = ObanHelpers.perform_all()
-      assert job_result == users
+      assert job_result == Enum.map(users, &refresh_record/1)
     end
   end
 
     end
   end
 
index dd210c3b5022ce7d20350f303685878580f53bbf..3229ba6f9c90d0990a037d72d32de01668960f6d 100644 (file)
@@ -403,6 +403,73 @@ defmodule Pleroma.Web.StreamerTest do
       assert notif.activity.id == follow_activity.id
       refute Streamer.filtered_by_user?(user, notif)
     end
       assert notif.activity.id == follow_activity.id
       refute Streamer.filtered_by_user?(user, notif)
     end
+
+    test "it sends relationships updates to the 'user' stream", %{
+      user: user,
+      token: oauth_token
+    } do
+      user_id = user.id
+      user_url = user.ap_id
+      follower = insert(:user)
+      follower_token = insert(:oauth_token, user: follower)
+      follower_id = follower.id
+
+      body =
+        File.read!("test/fixtures/users_mock/localhost.json")
+        |> String.replace("{{nickname}}", user.nickname)
+        |> Jason.encode!()
+
+      Tesla.Mock.mock_global(fn
+        %{method: :get, url: ^user_url} ->
+          %Tesla.Env{status: 200, body: body}
+      end)
+
+      Streamer.get_topic_and_add_socket("user", user, oauth_token)
+      Streamer.get_topic_and_add_socket("user", follower, follower_token)
+      {:ok, _follower, _followed, _follow_activity} = CommonAPI.follow(follower, user)
+
+      # follow_pending event sent to both follower and following
+      assert_receive {:text, event}
+      assert_receive {:text, ^event}
+
+      assert %{"event" => "pleroma:relationships_update", "payload" => payload} =
+               Jason.decode!(event)
+
+      assert %{
+               "follower" => %{
+                 "follower_count" => 0,
+                 "following_count" => 0,
+                 "id" => ^follower_id
+               },
+               "following" => %{
+                 "follower_count" => 0,
+                 "following_count" => 0,
+                 "id" => ^user_id
+               },
+               "state" => "follow_pending"
+             } = Jason.decode!(payload)
+
+      # follow_accept event sent to both follower and following
+      assert_receive {:text, event}
+      assert_receive {:text, ^event}
+
+      assert %{"event" => "pleroma:relationships_update", "payload" => payload} =
+               Jason.decode!(event)
+
+      assert %{
+               "follower" => %{
+                 "follower_count" => 0,
+                 "following_count" => 1,
+                 "id" => ^follower_id
+               },
+               "following" => %{
+                 "follower_count" => 1,
+                 "following_count" => 0,
+                 "id" => ^user_id
+               },
+               "state" => "follow_accept"
+             } = Jason.decode!(payload)
+    end
   end
 
   describe "public streams" do
   end
 
   describe "public streams" do
@@ -563,7 +630,7 @@ defmodule Pleroma.Web.StreamerTest do
       user_b = insert(:user)
       user_c = insert(:user)
 
       user_b = insert(:user)
       user_c = insert(:user)
 
-      {:ok, user_a} = User.follow(user_a, user_b)
+      {:ok, user_a, user_b} = User.follow(user_a, user_b)
 
       {:ok, list} = List.create("Test", user_a)
       {:ok, list} = List.follow(list, user_b)
 
       {:ok, list} = List.create("Test", user_a)
       {:ok, list} = List.follow(list, user_b)
@@ -599,7 +666,7 @@ defmodule Pleroma.Web.StreamerTest do
     test "it sends wanted private posts to list", %{user: user_a, token: user_a_token} do
       user_b = insert(:user)
 
     test "it sends wanted private posts to list", %{user: user_a, token: user_a_token} do
       user_b = insert(:user)
 
-      {:ok, user_a} = User.follow(user_a, user_b)
+      {:ok, user_a, user_b} = User.follow(user_a, user_b)
 
       {:ok, list} = List.create("Test", user_a)
       {:ok, list} = List.follow(list, user_b)
 
       {:ok, list} = List.create("Test", user_a)
       {:ok, list} = List.follow(list, user_b)