Add check on activity visibility in sub notification
This commit is contained in:
parent
e6778003ab
commit
76fdfd1c7f
2 changed files with 15 additions and 1 deletions
|
@ -12,6 +12,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.ActivityPub.Utils
|
alias Pleroma.Web.ActivityPub.Utils
|
||||||
|
alias Pleroma.Web.ActivityPub.Visibility
|
||||||
alias Pleroma.Web.Endpoint
|
alias Pleroma.Web.Endpoint
|
||||||
alias Pleroma.Web.MediaProxy
|
alias Pleroma.Web.MediaProxy
|
||||||
|
|
||||||
|
@ -337,13 +338,14 @@ defmodule Pleroma.Web.CommonAPI.Utils do
|
||||||
|
|
||||||
def maybe_notify_subscribers(
|
def maybe_notify_subscribers(
|
||||||
recipients,
|
recipients,
|
||||||
%Activity{data: %{"actor" => actor, "type" => type}}
|
%Activity{data: %{"actor" => actor, "type" => type}} = activity
|
||||||
)
|
)
|
||||||
when type == "Create" do
|
when type == "Create" do
|
||||||
with %User{} = user <- User.get_by_ap_id(actor) do
|
with %User{} = user <- User.get_by_ap_id(actor) do
|
||||||
subscriber_ids =
|
subscriber_ids =
|
||||||
user
|
user
|
||||||
|> User.subscribers()
|
|> User.subscribers()
|
||||||
|
|> Enum.filter(&Visibility.visible_for_user?(activity, &1))
|
||||||
|> Enum.map(& &1.ap_id)
|
|> Enum.map(& &1.ap_id)
|
||||||
|
|
||||||
recipients ++ subscriber_ids
|
recipients ++ subscriber_ids
|
||||||
|
|
|
@ -106,6 +106,18 @@ defmodule Pleroma.NotificationTest do
|
||||||
{:ok, status} = TwitterAPI.create_status(user, %{"status" => "Akariiiin"})
|
{:ok, status} = TwitterAPI.create_status(user, %{"status" => "Akariiiin"})
|
||||||
{:ok, [_notif]} = Notification.create_notifications(status)
|
{:ok, [_notif]} = Notification.create_notifications(status)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it doesn't create subscription notifications if the recipient cannot see the status" do
|
||||||
|
user = insert(:user)
|
||||||
|
subscriber = insert(:user)
|
||||||
|
|
||||||
|
User.subscribe(subscriber, user)
|
||||||
|
|
||||||
|
{:ok, status} =
|
||||||
|
TwitterAPI.create_status(user, %{"status" => "inwisible", "visibility" => "direct"})
|
||||||
|
|
||||||
|
assert {:ok, []} == Notification.create_notifications(status)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "get notification" do
|
describe "get notification" do
|
||||||
|
|
Loading…
Reference in a new issue