From 7c351de594a4ee766998cd1ffc7f6a95c328653e Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 1 Jun 2025 01:28:46 +0800 Subject: [PATCH] :bug: Fix the push subscription won't update --- DysonNetwork.Sphere/Account/NotificationService.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/DysonNetwork.Sphere/Account/NotificationService.cs b/DysonNetwork.Sphere/Account/NotificationService.cs index da2486c..1d672bb 100644 --- a/DysonNetwork.Sphere/Account/NotificationService.cs +++ b/DysonNetwork.Sphere/Account/NotificationService.cs @@ -28,14 +28,15 @@ public class NotificationService( { var existingSubscription = await db.NotificationPushSubscriptions .Where(s => s.AccountId == account.Id) - .Where(s => s.DeviceId == deviceId || s.DeviceToken == deviceToken) + .Where(s => (s.DeviceId == deviceId || s.DeviceToken == deviceToken) && s.Provider == provider) .FirstOrDefaultAsync(); - if (existingSubscription != null) + if (existingSubscription is not null) { // Reset these audit fields to renew the lifecycle of this device token - existingSubscription.CreatedAt = Instant.FromDateTimeUtc(DateTime.UtcNow); - existingSubscription.UpdatedAt = Instant.FromDateTimeUtc(DateTime.UtcNow); + existingSubscription.DeviceId = deviceId; + existingSubscription.DeviceToken = deviceToken; + existingSubscription.UpdatedAt = SystemClock.Instance.GetCurrentInstant(); db.Update(existingSubscription); await db.SaveChangesAsync(); return existingSubscription; @@ -250,7 +251,7 @@ public class NotificationService( { var subList = subscriptions.ToList(); if (subList.Count == 0) return; - + var requestDict = new Dictionary { ["notifications"] = _BuildNotificationPayload(notification, subList)