logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma
commit: b0439df1b529301c8f07097bedb1cba2602a4143
parent: d884b6f704b3d6e5f4b09349224a0c498b75a09b
Author: rinpatch <rinpatch@sdf.org>
Date:   Thu,  2 Jul 2020 10:08:42 +0000

Merge branch '1907-fix-announce-streaming' into 'develop'

Resolve "Streaming API: Repeats of your posts from random people are pushed to the timeline"

Closes #1907

See merge request pleroma/pleroma!2714

Diffstat:

MCHANGELOG.md1+
Mlib/pleroma/web/activity_pub/side_effects.ex6+++++-
Mlib/pleroma/web/streamer/streamer.ex1+
Mtest/web/activity_pub/side_effects_test.exs23+++++++++++++++++++++--
Mtest/web/streamer/streamer_test.exs12++++++++++++
5 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md @@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). <summary>API Changes</summary> - **Breaking:** Emoji API: changed methods and renamed routes. +- Streaming: Repeats of a user's posts will no longer be pushed to the user's stream. </details> <details> diff --git a/lib/pleroma/web/activity_pub/side_effects.ex b/lib/pleroma/web/activity_pub/side_effects.ex @@ -6,6 +6,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do collection, and so on. """ alias Pleroma.Activity + alias Pleroma.Activity.Ir.Topics alias Pleroma.Chat alias Pleroma.Chat.MessageReference alias Pleroma.Notification @@ -97,7 +98,10 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do if !User.is_internal_user?(user) do Notification.create_notifications(object) - ActivityPub.stream_out(object) + + object + |> Topics.get_activity_topics() + |> Streamer.stream(object) end {:ok, object, meta} diff --git a/lib/pleroma/web/streamer/streamer.ex b/lib/pleroma/web/streamer/streamer.ex @@ -116,6 +116,7 @@ defmodule Pleroma.Web.Streamer do 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 <- !(item.data["type"] == "Announce" && parent.data["actor"] == user.ap_id), true <- Enum.all?([blocked_ap_ids, muted_ap_ids], &(parent.data["actor"] not in &1)), true <- MapSet.disjoint?(recipients, recipient_blocks), %{host: item_host} <- URI.parse(item.actor), diff --git a/test/web/activity_pub/side_effects_test.exs b/test/web/activity_pub/side_effects_test.exs @@ -589,10 +589,29 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do end test "it streams out the announce", %{announce: announce} do - with_mock Pleroma.Web.ActivityPub.ActivityPub, [:passthrough], stream_out: fn _ -> nil end do + with_mocks([ + { + Pleroma.Web.Streamer, + [], + [ + stream: fn _, _ -> nil end + ] + }, + { + Pleroma.Web.Push, + [], + [ + send: fn _ -> nil end + ] + } + ]) do {:ok, announce, _} = SideEffects.handle(announce) - assert called(Pleroma.Web.ActivityPub.ActivityPub.stream_out(announce)) + assert called( + Pleroma.Web.Streamer.stream(["user", "list", "public", "public:local"], announce) + ) + + assert called(Pleroma.Web.Push.send(:_)) end end end diff --git a/test/web/streamer/streamer_test.exs b/test/web/streamer/streamer_test.exs @@ -116,6 +116,18 @@ defmodule Pleroma.Web.StreamerTest do refute Streamer.filtered_by_user?(user, announce) end + test "it does not stream announces of the user's own posts in the 'user' stream", %{ + user: user + } do + Streamer.get_topic_and_add_socket("user", user) + + other_user = insert(:user) + {:ok, activity} = CommonAPI.post(user, %{status: "hey"}) + {:ok, announce} = CommonAPI.repeat(activity.id, other_user) + + assert Streamer.filtered_by_user?(user, announce) + end + test "it streams boosts of mastodon user in the 'user' stream", %{user: user} do Streamer.get_topic_and_add_socket("user", user)