diff --git a/Iceshrimp.Backend/Core/Extensions/EnumerableExtensions.cs b/Iceshrimp.Backend/Core/Extensions/EnumerableExtensions.cs index 8899c4f6..903a8a37 100644 --- a/Iceshrimp.Backend/Core/Extensions/EnumerableExtensions.cs +++ b/Iceshrimp.Backend/Core/Extensions/EnumerableExtensions.cs @@ -43,4 +43,6 @@ public static class EnumerableExtensions var yArray = y as T[] ?? y.ToArray(); return xArray.Length == yArray.Length && xArray.All(yArray.Contains); } + + public static IEnumerable NotNull(this IEnumerable @enum) => @enum.OfType(); } \ No newline at end of file diff --git a/Iceshrimp.Backend/Core/Services/NotificationService.cs b/Iceshrimp.Backend/Core/Services/NotificationService.cs index 930808d1..3af97948 100644 --- a/Iceshrimp.Backend/Core/Services/NotificationService.cs +++ b/Iceshrimp.Backend/Core/Services/NotificationService.cs @@ -1,6 +1,7 @@ using System.Diagnostics.CodeAnalysis; using Iceshrimp.Backend.Core.Database; using Iceshrimp.Backend.Core.Database.Tables; +using Iceshrimp.Backend.Core.Extensions; using Iceshrimp.Backend.Core.Helpers; using Microsoft.EntityFrameworkCore; @@ -42,14 +43,18 @@ public class NotificationService( public async Task GenerateReplyNotifications(Note note, IReadOnlyCollection mentionedLocalUserIds) { - if (note.Visibility != Note.NoteVisibility.Specified) return; - if (note.VisibleUserIds.Count == 0) return; + var users = mentionedLocalUserIds + .Concat(note.VisibleUserIds) + .Append(note.ReplyUserId) + .NotNull() + .Distinct() + .Except(mentionedLocalUserIds) + .ToList(); - var users = mentionedLocalUserIds.Concat(note.VisibleUserIds).Distinct().Except(mentionedLocalUserIds).ToList(); if (users.Count == 0) return; var blocks = await db.Blockings - .Where(p => p.BlockeeId == note.UserId && mentionedLocalUserIds.Contains(p.BlockerId)) + .Where(p => p.BlockeeId == note.UserId && users.Contains(p.BlockerId)) .Select(p => p.BlockerId) .ToListAsync(); @@ -182,11 +187,11 @@ public class NotificationService( var notification = new Notification { - Id = IdHelpers.GenerateSlowflakeId(), - CreatedAt = DateTime.UtcNow, - Notifier = followRequest.Followee, - Notifiee = followRequest.Follower, - Type = Notification.NotificationType.FollowRequestAccepted + Id = IdHelpers.GenerateSlowflakeId(), + CreatedAt = DateTime.UtcNow, + Notifier = followRequest.Followee, + Notifiee = followRequest.Follower, + Type = Notification.NotificationType.FollowRequestAccepted }; await db.AddAsync(notification);