From e7942fc6870df77f794aa1982e33d87be98b7a56 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 14 Jun 2025 16:47:03 +0800 Subject: [PATCH] :bug: Fix notification via Send didn't push via ws --- .../Account/NotificationService.cs | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/DysonNetwork.Sphere/Account/NotificationService.cs b/DysonNetwork.Sphere/Account/NotificationService.cs index 646acc7..ae795f2 100644 --- a/DysonNetwork.Sphere/Account/NotificationService.cs +++ b/DysonNetwork.Sphere/Account/NotificationService.cs @@ -125,9 +125,10 @@ public class NotificationService( public async Task BroadcastNotification(Notification notification, bool save = false) { + var accounts = await db.Accounts.ToListAsync(); + if (save) { - var accounts = await db.Accounts.ToListAsync(); var notifications = accounts.Select(x => { var newNotification = new Notification @@ -146,6 +147,17 @@ public class NotificationService( await db.BulkInsertAsync(notifications); } + foreach (var account in accounts) + { + notification.Account = account; + notification.AccountId = account.Id; + ws.SendPacketToAccount(account.Id, new WebSocketPacket + { + Type = "notifications.new", + Data = notification + }); + } + var subscribers = await db.NotificationPushSubscriptions .ToListAsync(); await _PushNotification(notification, subscribers); @@ -173,6 +185,17 @@ public class NotificationService( await db.BulkInsertAsync(notifications); } + foreach (var account in accounts) + { + notification.Account = account; + notification.AccountId = account.Id; + ws.SendPacketToAccount(account.Id, new WebSocketPacket + { + Type = "notifications.new", + Data = notification + }); + } + var accountsId = accounts.Select(x => x.Id).ToList(); var subscribers = await db.NotificationPushSubscriptions .Where(s => accountsId.Contains(s.AccountId))