Notifications: Never return `nil` in the notification list.

This commit is contained in:
lain 2020-06-29 17:48:18 +02:00
parent dc31fbfe6c
commit 90083a754d
2 changed files with 13 additions and 0 deletions

View File

@ -367,6 +367,7 @@ defp do_create_notifications(%Activity{} = activity, options) do
do_send = do_send && user in enabled_receivers do_send = do_send && user in enabled_receivers
create_notification(activity, user, do_send) create_notification(activity, user, do_send)
end) end)
|> Enum.filter(& &1)
{:ok, notifications} {:ok, notifications}
end end

View File

@ -21,7 +21,19 @@ defmodule Pleroma.NotificationTest do
alias Pleroma.Web.Push alias Pleroma.Web.Push
alias Pleroma.Web.Streamer alias Pleroma.Web.Streamer
# TODO: Test there's no nil notifications
describe "create_notifications" do 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 test "creates a notification for an emoji reaction" do
user = insert(:user) user = insert(:user)
other_user = insert(:user) other_user = insert(:user)