From 90083a754dc0bfe0c8a04fbaa3e78f68a848035e Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 29 Jun 2020 17:48:18 +0200 Subject: [PATCH] Notifications: Never return `nil` in the notification list. --- lib/pleroma/notification.ex | 1 + test/notification_test.exs | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index 9ee9606be..58dcf880a 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -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 diff --git a/test/notification_test.exs b/test/notification_test.exs index 526f43fab..5389dabca 100644 --- a/test/notification_test.exs +++ b/test/notification_test.exs @@ -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) -- 2.45.2