Do not include notifications from blocked users when with_muted is set
This is not what with_muted is for per documentation and it was agreed on irc that this behavior doesn't make sense.
This commit is contained in:
parent
2ebe8c416a
commit
2dbee29cf5
2 changed files with 16 additions and 11 deletions
|
@ -55,9 +55,19 @@ defmodule Pleroma.Notification do
|
||||||
)
|
)
|
||||||
|> preload([n, a, o], activity: {a, object: o})
|
|> preload([n, a, o], activity: {a, object: o})
|
||||||
|> exclude_muted(user, opts)
|
|> exclude_muted(user, opts)
|
||||||
|
|> exclude_blocked(user)
|
||||||
|> exclude_visibility(opts)
|
|> exclude_visibility(opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp exclude_blocked(query, user) do
|
||||||
|
query
|
||||||
|
|> where([n, a], a.actor not in ^user.info.blocks)
|
||||||
|
|> where(
|
||||||
|
[n, a],
|
||||||
|
fragment("substring(? from '.*://([^/]*)')", a.actor) not in ^user.info.domain_blocks
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
defp exclude_muted(query, _, %{with_muted: true}) do
|
defp exclude_muted(query, _, %{with_muted: true}) do
|
||||||
query
|
query
|
||||||
end
|
end
|
||||||
|
@ -65,11 +75,6 @@ defmodule Pleroma.Notification do
|
||||||
defp exclude_muted(query, user, _opts) do
|
defp exclude_muted(query, user, _opts) do
|
||||||
query
|
query
|
||||||
|> where([n, a], a.actor not in ^user.info.muted_notifications)
|
|> where([n, a], a.actor not in ^user.info.muted_notifications)
|
||||||
|> where([n, a], a.actor not in ^user.info.blocks)
|
|
||||||
|> where(
|
|
||||||
[n, a],
|
|
||||||
fragment("substring(? from '.*://([^/]*)')", a.actor) not in ^user.info.domain_blocks
|
|
||||||
)
|
|
||||||
|> join(:left, [n, a], tm in Pleroma.ThreadMute,
|
|> join(:left, [n, a], tm in Pleroma.ThreadMute,
|
||||||
on: tm.user_id == ^user.id and tm.context == fragment("?->>'context'", a.data)
|
on: tm.user_id == ^user.id and tm.context == fragment("?->>'context'", a.data)
|
||||||
)
|
)
|
||||||
|
|
|
@ -683,7 +683,7 @@ defmodule Pleroma.NotificationTest do
|
||||||
assert Notification.for_user(user) == []
|
assert Notification.for_user(user) == []
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it returns notifications for muted user with notifications and with_muted parameter" do
|
test "it returns notifications from a muted user when with_muted is set" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
muted = insert(:user)
|
muted = insert(:user)
|
||||||
{:ok, user} = User.mute(user, muted)
|
{:ok, user} = User.mute(user, muted)
|
||||||
|
@ -693,27 +693,27 @@ defmodule Pleroma.NotificationTest do
|
||||||
assert length(Notification.for_user(user, %{with_muted: true})) == 1
|
assert length(Notification.for_user(user, %{with_muted: true})) == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it returns notifications for blocked user and with_muted parameter" do
|
test "it doesn't return notifications from a blocked user when with_muted is set" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
blocked = insert(:user)
|
blocked = insert(:user)
|
||||||
{:ok, user} = User.block(user, blocked)
|
{:ok, user} = User.block(user, blocked)
|
||||||
|
|
||||||
{:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
|
{:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
|
||||||
|
|
||||||
assert length(Notification.for_user(user, %{with_muted: true})) == 1
|
assert length(Notification.for_user(user, %{with_muted: true})) == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it returns notificatitons for blocked domain and with_muted parameter" do
|
test "it doesn't return notifications from a domain-blocked user when with_muted is set" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
blocked = insert(:user, ap_id: "http://some-domain.com")
|
blocked = insert(:user, ap_id: "http://some-domain.com")
|
||||||
{:ok, user} = User.block_domain(user, "some-domain.com")
|
{:ok, user} = User.block_domain(user, "some-domain.com")
|
||||||
|
|
||||||
{:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
|
{:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
|
||||||
|
|
||||||
assert length(Notification.for_user(user, %{with_muted: true})) == 1
|
assert length(Notification.for_user(user, %{with_muted: true})) == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it returns notifications for muted thread with_muted parameter" do
|
test "it returns notifications from muted threads when with_muted is set" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
another_user = insert(:user)
|
another_user = insert(:user)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue