Don't create notifications if the user is blocked.
authorRoger Braun <roger@rogerbraun.net>
Thu, 2 Nov 2017 21:08:22 +0000 (22:08 +0100)
committerRoger Braun <roger@rogerbraun.net>
Thu, 2 Nov 2017 21:08:22 +0000 (22:08 +0100)
lib/pleroma/notification.ex
test/notification_test.exs

index 35f817d1d48ade6734a52f4546942ca04fe39e8c..00a382f3184fe65e9106659cfe5a6e9f17970bb5 100644 (file)
@@ -46,9 +46,11 @@ defmodule Pleroma.Notification do
 
   # 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
 
index f50b3cb24d299880cf968334553e0c659b346102..77fdb532fe9e854f74799ecf33d8994e5cda09cf 100644 (file)
@@ -20,4 +20,15 @@ defmodule Pleroma.NotificationTest 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