Streamer: Stream boosts to the boosting user.
authorlain <lain@soykaf.club>
Wed, 22 Apr 2020 15:21:13 +0000 (17:21 +0200)
committerlain <lain@soykaf.club>
Wed, 22 Apr 2020 15:21:13 +0000 (17:21 +0200)
lib/pleroma/user.ex
lib/pleroma/web/streamer/worker.ex
test/user_test.exs
test/web/streamer/streamer_test.exs

index bef4679cbad9c47bc0aa83ad2c5f8ae2de47880f..477237756b0449105eada1726835ccfea6f3c9bb 100644 (file)
@@ -1180,7 +1180,9 @@ defmodule Pleroma.User do
   end
 
   @spec get_recipients_from_activity(Activity.t()) :: [User.t()]
-  def get_recipients_from_activity(%Activity{recipients: to}) do
+  def get_recipients_from_activity(%Activity{recipients: to, actor: actor}) do
+    to = [actor | to]
+
     User.Query.build(%{recipients_from_activity: to, local: true, deactivated: false})
     |> Repo.all()
   end
index abfed21c8aa51eee4458848fcba33fdf4cd8e177..f6160fa4d24f7c5a3f2d9340e7bf1ae823ba2414 100644 (file)
@@ -158,24 +158,6 @@ defmodule Pleroma.Web.Streamer.Worker do
     should_send?(user, activity)
   end
 
-  def push_to_socket(topics, topic, %Activity{data: %{"type" => "Announce"}} = item) do
-    Enum.each(topics[topic] || [], fn %StreamerSocket{
-                                        transport_pid: transport_pid,
-                                        user: socket_user
-                                      } ->
-      # Get the current user so we have up-to-date blocks etc.
-      if socket_user do
-        user = User.get_cached_by_ap_id(socket_user.ap_id)
-
-        if should_send?(user, item) do
-          send(transport_pid, {:text, StreamerView.render("update.json", item, user)})
-        end
-      else
-        send(transport_pid, {:text, StreamerView.render("update.json", item)})
-      end
-    end)
-  end
-
   def push_to_socket(topics, topic, %Participation{} = participation) do
     Enum.each(topics[topic] || [], fn %StreamerSocket{transport_pid: transport_pid} ->
       send(transport_pid, {:text, StreamerView.render("conversation.json", participation)})
index 65e118d6dc9da90e99405005ffc2a1e9bea03869..cd4041673f97d1415cc50fca36715cb72f096554 100644 (file)
@@ -987,6 +987,18 @@ defmodule Pleroma.UserTest do
   end
 
   describe "get_recipients_from_activity" do
+    test "works for announces" do
+      actor = insert(:user)
+      user = insert(:user, local: true)
+
+      {:ok, activity} = CommonAPI.post(actor, %{"status" => "hello"})
+      {:ok, announce, _} = CommonAPI.repeat(activity.id, user)
+
+      recipients = User.get_recipients_from_activity(announce)
+
+      assert user in recipients
+    end
+
     test "get recipients" do
       actor = insert(:user)
       user = insert(:user, local: true)
index eb082b79f49943e44de47655e622ca52801b6e26..8b8d8af6c51521dac9046715814c22d24fcc6731 100644 (file)
@@ -28,6 +28,42 @@ defmodule Pleroma.Web.StreamerTest do
       {:ok, %{user: user, notify: notify}}
     end
 
+    test "it streams the user's post in the 'user' stream", %{user: user} do
+      task =
+        Task.async(fn ->
+          assert_receive {:text, _}, @streamer_timeout
+        end)
+
+      Streamer.add_socket(
+        "user",
+        %{transport_pid: task.pid, assigns: %{user: user}}
+      )
+
+      {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
+
+      Streamer.stream("user", activity)
+      Task.await(task)
+    end
+
+    test "it streams boosts of the user in the 'user' stream", %{user: user} do
+      task =
+        Task.async(fn ->
+          assert_receive {:text, _}, @streamer_timeout
+        end)
+
+      Streamer.add_socket(
+        "user",
+        %{transport_pid: task.pid, assigns: %{user: user}}
+      )
+
+      other_user = insert(:user)
+      {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hey"})
+      {:ok, announce, _} = CommonAPI.repeat(activity.id, user)
+
+      Streamer.stream("user", announce)
+      Task.await(task)
+    end
+
     test "it sends notify to in the 'user' stream", %{user: user, notify: notify} do
       task =
         Task.async(fn ->