🐛 Fix the push subscription won't update
This commit is contained in:
parent
fb2f138925
commit
7c351de594
@ -28,14 +28,15 @@ public class NotificationService(
|
|||||||
{
|
{
|
||||||
var existingSubscription = await db.NotificationPushSubscriptions
|
var existingSubscription = await db.NotificationPushSubscriptions
|
||||||
.Where(s => s.AccountId == account.Id)
|
.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();
|
.FirstOrDefaultAsync();
|
||||||
|
|
||||||
if (existingSubscription != null)
|
if (existingSubscription is not null)
|
||||||
{
|
{
|
||||||
// Reset these audit fields to renew the lifecycle of this device token
|
// Reset these audit fields to renew the lifecycle of this device token
|
||||||
existingSubscription.CreatedAt = Instant.FromDateTimeUtc(DateTime.UtcNow);
|
existingSubscription.DeviceId = deviceId;
|
||||||
existingSubscription.UpdatedAt = Instant.FromDateTimeUtc(DateTime.UtcNow);
|
existingSubscription.DeviceToken = deviceToken;
|
||||||
|
existingSubscription.UpdatedAt = SystemClock.Instance.GetCurrentInstant();
|
||||||
db.Update(existingSubscription);
|
db.Update(existingSubscription);
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
return existingSubscription;
|
return existingSubscription;
|
||||||
@ -250,7 +251,7 @@ public class NotificationService(
|
|||||||
{
|
{
|
||||||
var subList = subscriptions.ToList();
|
var subList = subscriptions.ToList();
|
||||||
if (subList.Count == 0) return;
|
if (subList.Count == 0) return;
|
||||||
|
|
||||||
var requestDict = new Dictionary<string, object>
|
var requestDict = new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
["notifications"] = _BuildNotificationPayload(notification, subList)
|
["notifications"] = _BuildNotificationPayload(notification, subList)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user