🐛 Fix send notification api push notification twice

This commit is contained in:
2026-01-15 01:24:30 +08:00
parent f217c0fb30
commit b7aac30384
2 changed files with 31 additions and 19 deletions

View File

@@ -251,18 +251,29 @@ public class PushService
notification.Meta
);
// WS first
// Send to each account
foreach (var account in accounts)
{
notification.AccountId = account;
// WebSocket
WebSocketService.SendPacketToAccount(account, new WebSocketPacket
{
Type = "notifications.new",
Data = notification
});
}
await DeliverPushNotification(notification);
// Push notifications
var subscriptions = await _db.PushSubscriptions
.Where(s => s.AccountId == account)
.ToListAsync();
if (subscriptions.Count > 0)
{
var tasks = subscriptions.Select(sub => SendPushNotificationAsync(sub, notification)).ToList();
await Task.WhenAll(tasks);
}
}
}
private async Task SendPushNotificationAsync(SnNotificationPushSubscription subscription,
@@ -391,4 +402,4 @@ public class PushService
}));
await _db.SaveChangesAsync();
}
}
}