Don't create notifications if the user is blocked.

This commit is contained in:
Roger Braun 2017-11-02 22:08:22 +01:00
parent 6a5f087174
commit 632da6c927
2 changed files with 16 additions and 3 deletions

View file

@ -46,9 +46,11 @@ defmodule Pleroma.Notification do
# TODO move to sql, too. # TODO move to sql, too.
def create_notification(%Activity{} = activity, %User{} = user) do def create_notification(%Activity{} = activity, %User{} = user) do
notification = %Notification{user_id: user.id, activity_id: activity.id} unless User.blocks?(user, %{ap_id: activity.data["actor"]}) do
{:ok, notification} = Repo.insert(notification) notification = %Notification{user_id: user.id, activity_id: activity.id}
notification {:ok, notification} = Repo.insert(notification)
notification
end
end end
end end

View file

@ -20,4 +20,15 @@ defmodule Pleroma.NotificationTest do
assert other_notification.activity_id == activity.id assert other_notification.activity_id == activity.id
end end
end end
describe "create_notification" do
test "it doesn't create a notification for user if the user blocks the activity author" do
activity = insert(:note_activity)
author = User.get_by_ap_id(activity.data["actor"])
user = insert(:user)
{:ok, user} = User.block(user, author)
assert nil == Notification.create_notification(activity, user)
end
end
end end