From 472221302dee3abaf005b6ecdddf0951d4dfb3e3 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Fri, 30 May 2025 22:49:03 +0800 Subject: [PATCH] :bug: Trying to fix message notification again... --- .../Account/NotificationService.cs | 35 +++++++++++++------ DysonNetwork.Sphere/Chat/ChatService.cs | 2 +- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/DysonNetwork.Sphere/Account/NotificationService.cs b/DysonNetwork.Sphere/Account/NotificationService.cs index 1599408..c4207a0 100644 --- a/DysonNetwork.Sphere/Account/NotificationService.cs +++ b/DysonNetwork.Sphere/Account/NotificationService.cs @@ -181,12 +181,19 @@ public class NotificationService { if (save) { - var notifications = accounts.Select(x => + // Create new notification objects for each account instead of reusing + var notifications = accounts.Select(x => new Notification { - notification.Account = x; - notification.AccountId = x.Id; - return notification; + Topic = notification.Topic, + Title = notification.Title, + Subtitle = notification.Subtitle, + Content = notification.Content, + Meta = notification.Meta != null ? new Dictionary(notification.Meta) : null, + Priority = notification.Priority, + Account = x, + AccountId = x.Id }).ToList(); + await _db.BulkInsertAsync(notifications); } @@ -194,12 +201,20 @@ public class NotificationService var subscribers = await _db.NotificationPushSubscriptions .Where(s => accountsId.Contains(s.AccountId)) .ToListAsync(); - var tasks = new List(); - foreach (var subscriber in subscribers) - { - notification.AccountId = subscriber.AccountId; - tasks.Add(_PushSingleNotification(notification, subscriber)); - } + + var tasks = (from subscriber in subscribers + let notificationCopy = new Notification + { + Id = notification.Id, + Topic = notification.Topic, + Title = notification.Title, + Subtitle = notification.Subtitle, + Content = notification.Content, + Meta = notification.Meta != null ? new Dictionary(notification.Meta) : null, + Priority = notification.Priority, + AccountId = subscriber.AccountId + } + select _PushSingleNotification(notificationCopy, subscriber)).ToList(); await Task.WhenAll(tasks); } diff --git a/DysonNetwork.Sphere/Chat/ChatService.cs b/DysonNetwork.Sphere/Chat/ChatService.cs index c9f828b..3f79525 100644 --- a/DysonNetwork.Sphere/Chat/ChatService.cs +++ b/DysonNetwork.Sphere/Chat/ChatService.cs @@ -46,7 +46,7 @@ public class ChatService( { // Log the exception properly // Consider using ILogger or your logging framework - logger.LogError($"Error when delivering message: {ex.Message}"); + logger.LogError($"Error when delivering message: {ex.Message} {ex.StackTrace}"); } });