mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-23 15:05:45 +00:00
Merge branch 'exclude-visibilities-for-like-notifications' into 'develop'
Fix exclude_visibilities filter for followers-only Like notifications See merge request pleroma/pleroma!1957
This commit is contained in:
commit
b3c80b8404
|
@ -121,10 +121,28 @@ defmodule Pleroma.Notification do
|
||||||
when is_list(visibility) do
|
when is_list(visibility) do
|
||||||
if Enum.all?(visibility, &(&1 in @valid_visibilities)) do
|
if Enum.all?(visibility, &(&1 in @valid_visibilities)) do
|
||||||
query
|
query
|
||||||
|
|> join(:left, [n, a], mutated_activity in Pleroma.Activity,
|
||||||
|
on:
|
||||||
|
fragment("?->>'context'", a.data) ==
|
||||||
|
fragment("?->>'context'", mutated_activity.data) and
|
||||||
|
fragment("(?->>'type' = 'Like' or ?->>'type' = 'Announce')", a.data, a.data) and
|
||||||
|
fragment("?->>'type'", mutated_activity.data) == "Create",
|
||||||
|
as: :mutated_activity
|
||||||
|
)
|
||||||
|> where(
|
|> where(
|
||||||
[n, a],
|
[n, a, mutated_activity: mutated_activity],
|
||||||
not fragment(
|
not fragment(
|
||||||
"activity_visibility(?, ?, ?) = ANY (?)",
|
"""
|
||||||
|
CASE WHEN (?->>'type') = 'Like' or (?->>'type') = 'Announce'
|
||||||
|
THEN (activity_visibility(?, ?, ?) = ANY (?))
|
||||||
|
ELSE (activity_visibility(?, ?, ?) = ANY (?)) END
|
||||||
|
""",
|
||||||
|
a.data,
|
||||||
|
a.data,
|
||||||
|
mutated_activity.actor,
|
||||||
|
mutated_activity.recipients,
|
||||||
|
mutated_activity.data,
|
||||||
|
^visibility,
|
||||||
a.actor,
|
a.actor,
|
||||||
a.recipients,
|
a.recipients,
|
||||||
a.data,
|
a.data,
|
||||||
|
@ -139,17 +157,7 @@ defmodule Pleroma.Notification do
|
||||||
|
|
||||||
defp exclude_visibility(query, %{exclude_visibilities: visibility})
|
defp exclude_visibility(query, %{exclude_visibilities: visibility})
|
||||||
when visibility in @valid_visibilities do
|
when visibility in @valid_visibilities do
|
||||||
query
|
exclude_visibility(query, [visibility])
|
||||||
|> where(
|
|
||||||
[n, a],
|
|
||||||
not fragment(
|
|
||||||
"activity_visibility(?, ?, ?) = (?)",
|
|
||||||
a.actor,
|
|
||||||
a.recipients,
|
|
||||||
a.data,
|
|
||||||
^visibility
|
|
||||||
)
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp exclude_visibility(query, %{exclude_visibilities: visibility})
|
defp exclude_visibility(query, %{exclude_visibilities: visibility})
|
||||||
|
|
|
@ -137,7 +137,8 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
||||||
assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
|
assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
|
||||||
end
|
end
|
||||||
|
|
||||||
test "filters notifications using exclude_visibilities", %{conn: conn} do
|
describe "exclude_visibilities" do
|
||||||
|
test "filters notifications for mentions", %{conn: conn} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
other_user = insert(:user)
|
other_user = insert(:user)
|
||||||
|
|
||||||
|
@ -188,6 +189,101 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
||||||
assert id == public_activity.id
|
assert id == public_activity.id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "filters notifications for Like activities", %{conn: conn} do
|
||||||
|
user = insert(:user)
|
||||||
|
other_user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, public_activity} =
|
||||||
|
CommonAPI.post(other_user, %{"status" => ".", "visibility" => "public"})
|
||||||
|
|
||||||
|
{:ok, direct_activity} =
|
||||||
|
CommonAPI.post(other_user, %{"status" => "@#{user.nickname}", "visibility" => "direct"})
|
||||||
|
|
||||||
|
{:ok, unlisted_activity} =
|
||||||
|
CommonAPI.post(other_user, %{"status" => ".", "visibility" => "unlisted"})
|
||||||
|
|
||||||
|
{:ok, private_activity} =
|
||||||
|
CommonAPI.post(other_user, %{"status" => ".", "visibility" => "private"})
|
||||||
|
|
||||||
|
{:ok, _, _} = CommonAPI.favorite(public_activity.id, user)
|
||||||
|
{:ok, _, _} = CommonAPI.favorite(direct_activity.id, user)
|
||||||
|
{:ok, _, _} = CommonAPI.favorite(unlisted_activity.id, user)
|
||||||
|
{:ok, _, _} = CommonAPI.favorite(private_activity.id, user)
|
||||||
|
|
||||||
|
activity_ids =
|
||||||
|
conn
|
||||||
|
|> assign(:user, other_user)
|
||||||
|
|> get("/api/v1/notifications", %{exclude_visibilities: ["direct"]})
|
||||||
|
|> json_response(200)
|
||||||
|
|> Enum.map(& &1["status"]["id"])
|
||||||
|
|
||||||
|
assert public_activity.id in activity_ids
|
||||||
|
assert unlisted_activity.id in activity_ids
|
||||||
|
assert private_activity.id in activity_ids
|
||||||
|
refute direct_activity.id in activity_ids
|
||||||
|
|
||||||
|
activity_ids =
|
||||||
|
conn
|
||||||
|
|> assign(:user, other_user)
|
||||||
|
|> get("/api/v1/notifications", %{exclude_visibilities: ["unlisted"]})
|
||||||
|
|> json_response(200)
|
||||||
|
|> Enum.map(& &1["status"]["id"])
|
||||||
|
|
||||||
|
assert public_activity.id in activity_ids
|
||||||
|
refute unlisted_activity.id in activity_ids
|
||||||
|
assert private_activity.id in activity_ids
|
||||||
|
assert direct_activity.id in activity_ids
|
||||||
|
|
||||||
|
activity_ids =
|
||||||
|
conn
|
||||||
|
|> assign(:user, other_user)
|
||||||
|
|> get("/api/v1/notifications", %{exclude_visibilities: ["private"]})
|
||||||
|
|> json_response(200)
|
||||||
|
|> Enum.map(& &1["status"]["id"])
|
||||||
|
|
||||||
|
assert public_activity.id in activity_ids
|
||||||
|
assert unlisted_activity.id in activity_ids
|
||||||
|
refute private_activity.id in activity_ids
|
||||||
|
assert direct_activity.id in activity_ids
|
||||||
|
|
||||||
|
activity_ids =
|
||||||
|
conn
|
||||||
|
|> assign(:user, other_user)
|
||||||
|
|> get("/api/v1/notifications", %{exclude_visibilities: ["public"]})
|
||||||
|
|> json_response(200)
|
||||||
|
|> Enum.map(& &1["status"]["id"])
|
||||||
|
|
||||||
|
refute public_activity.id in activity_ids
|
||||||
|
assert unlisted_activity.id in activity_ids
|
||||||
|
assert private_activity.id in activity_ids
|
||||||
|
assert direct_activity.id in activity_ids
|
||||||
|
end
|
||||||
|
|
||||||
|
test "filters notifications for Announce activities", %{conn: conn} do
|
||||||
|
user = insert(:user)
|
||||||
|
other_user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, public_activity} =
|
||||||
|
CommonAPI.post(other_user, %{"status" => ".", "visibility" => "public"})
|
||||||
|
|
||||||
|
{:ok, unlisted_activity} =
|
||||||
|
CommonAPI.post(other_user, %{"status" => ".", "visibility" => "unlisted"})
|
||||||
|
|
||||||
|
{:ok, _, _} = CommonAPI.repeat(public_activity.id, user)
|
||||||
|
{:ok, _, _} = CommonAPI.repeat(unlisted_activity.id, user)
|
||||||
|
|
||||||
|
activity_ids =
|
||||||
|
conn
|
||||||
|
|> assign(:user, other_user)
|
||||||
|
|> get("/api/v1/notifications", %{exclude_visibilities: ["unlisted"]})
|
||||||
|
|> json_response(200)
|
||||||
|
|> Enum.map(& &1["status"]["id"])
|
||||||
|
|
||||||
|
assert public_activity.id in activity_ids
|
||||||
|
refute unlisted_activity.id in activity_ids
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "filters notifications using exclude_types", %{conn: conn} do
|
test "filters notifications using exclude_types", %{conn: conn} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
other_user = insert(:user)
|
other_user = insert(:user)
|
||||||
|
|
Loading…
Reference in a new issue