From 632da6c9273b55984bdd67b8a10672733df7fae5 Mon Sep 17 00:00:00 2001
From: Roger Braun <roger@rogerbraun.net>
Date: Thu, 2 Nov 2017 22:08:22 +0100
Subject: [PATCH] Don't create notifications if the user is blocked.

---
 lib/pleroma/notification.ex |  8 +++++---
 test/notification_test.exs  | 11 +++++++++++
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex
index 35f817d1d..00a382f31 100644
--- a/lib/pleroma/notification.ex
+++ b/lib/pleroma/notification.ex
@@ -46,9 +46,11 @@ def create_notifications(_), do: {:ok, []}
 
   # TODO move to sql, too.
   def create_notification(%Activity{} = activity, %User{} = user) do
-    notification = %Notification{user_id: user.id, activity_id: activity.id}
-    {:ok, notification} = Repo.insert(notification)
-    notification
+    unless User.blocks?(user, %{ap_id: activity.data["actor"]}) do
+      notification = %Notification{user_id: user.id, activity_id: activity.id}
+      {:ok, notification} = Repo.insert(notification)
+      notification
+    end
   end
 end
 
diff --git a/test/notification_test.exs b/test/notification_test.exs
index f50b3cb24..77fdb532f 100644
--- a/test/notification_test.exs
+++ b/test/notification_test.exs
@@ -20,4 +20,15 @@ test "notifies someone when they are directly addressed" do
       assert other_notification.activity_id == activity.id
     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