Notifications: Never return `nil` in the notification list.
authorlain <lain@soykaf.club>
Mon, 29 Jun 2020 15:48:18 +0000 (17:48 +0200)
committerlain <lain@soykaf.club>
Mon, 29 Jun 2020 15:48:18 +0000 (17:48 +0200)
lib/pleroma/notification.ex
test/notification_test.exs

index 9ee9606becb9fd9bf779d81b6b72a01c5b4595ac..58dcf880a54d8b27ace3a125ed7fc8bf28128f74 100644 (file)
@@ -367,6 +367,7 @@ defmodule Pleroma.Notification do
         do_send = do_send && user in enabled_receivers
         create_notification(activity, user, do_send)
       end)
+      |> Enum.filter(& &1)
 
     {:ok, notifications}
   end
index 526f43fab7a53f1313bd602e2f0f392a6c70820c..5389dabcaf06cabc0f92daa63918f7e40bd54571 100644 (file)
@@ -21,7 +21,19 @@ defmodule Pleroma.NotificationTest do
   alias Pleroma.Web.Push
   alias Pleroma.Web.Streamer
 
+  # TODO: Test there's no nil notifications
+
   describe "create_notifications" do
+    test "never returns nil" do
+      user = insert(:user)
+      other_user = insert(:user, %{invisible: true})
+
+      {:ok, activity} = CommonAPI.post(user, %{status: "yeah"})
+      {:ok, activity} = CommonAPI.react_with_emoji(activity.id, other_user, "☕")
+
+      refute {:ok, [nil]} == Notification.create_notifications(activity)
+    end
+
     test "creates a notification for an emoji reaction" do
       user = insert(:user)
       other_user = insert(:user)