diff --git a/DysonNetwork.Sphere/Account/NotificationService.cs b/DysonNetwork.Sphere/Account/NotificationService.cs index c4207a0..1599408 100644 --- a/DysonNetwork.Sphere/Account/NotificationService.cs +++ b/DysonNetwork.Sphere/Account/NotificationService.cs @@ -181,19 +181,12 @@ public class NotificationService { if (save) { - // Create new notification objects for each account instead of reusing - var notifications = accounts.Select(x => new Notification + var notifications = accounts.Select(x => { - 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 + notification.Account = x; + notification.AccountId = x.Id; + return notification; }).ToList(); - await _db.BulkInsertAsync(notifications); } @@ -201,20 +194,12 @@ public class NotificationService var subscribers = await _db.NotificationPushSubscriptions .Where(s => accountsId.Contains(s.AccountId)) .ToListAsync(); - - 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(); + var tasks = new List(); + foreach (var subscriber in subscribers) + { + notification.AccountId = subscriber.AccountId; + tasks.Add(_PushSingleNotification(notification, subscriber)); + } await Task.WhenAll(tasks); } diff --git a/DysonNetwork.Sphere/Chat/ChatRoomService.cs b/DysonNetwork.Sphere/Chat/ChatRoomService.cs index fb4fe39..14c742a 100644 --- a/DysonNetwork.Sphere/Chat/ChatRoomService.cs +++ b/DysonNetwork.Sphere/Chat/ChatRoomService.cs @@ -19,6 +19,8 @@ public class ChatRoomService(AppDatabase db, ICacheService cache) return cachedMembers; var members = await db.ChatMembers + .Include(m => m.Account) + .ThenInclude(m => m.Profile) .Where(m => m.ChatRoomId == roomId) .Where(m => m.JoinedAt != null) .Where(m => m.LeaveAt == null) diff --git a/DysonNetwork.Sphere/Chat/ChatService.cs b/DysonNetwork.Sphere/Chat/ChatService.cs index 3f79525..c4e1c82 100644 --- a/DysonNetwork.Sphere/Chat/ChatService.cs +++ b/DysonNetwork.Sphere/Chat/ChatService.cs @@ -98,7 +98,7 @@ public class ChatService( }); // Only add accounts that aren't null - if (member.AccountId != sender.AccountId) + if (member.Account.Id != sender.AccountId) accountsToNotify.Add(member.Account); }