BTCPay-infrastructure-recovery
This commit is contained in:
@@ -40,6 +40,14 @@ public class PushNotificationService : IPushNotificationService
|
||||
{
|
||||
try
|
||||
{
|
||||
// Check if the user actually exists in the database
|
||||
var userExists = await _context.Users.AnyAsync(u => u.Id == userId);
|
||||
if (!userExists)
|
||||
{
|
||||
Log.Warning("Attempted to subscribe non-existent user {UserId} to push notifications", userId);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if subscription already exists
|
||||
var existingSubscription = await _context.PushSubscriptions
|
||||
.FirstOrDefaultAsync(ps => ps.Endpoint == subscriptionDto.Endpoint && ps.UserId == userId);
|
||||
@@ -53,6 +61,7 @@ public class PushNotificationService : IPushNotificationService
|
||||
existingSubscription.IsActive = true;
|
||||
existingSubscription.UserAgent = userAgent;
|
||||
existingSubscription.IpAddress = ipAddress;
|
||||
Log.Information("Updated existing push subscription for user {UserId}", userId);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -71,10 +80,11 @@ public class PushNotificationService : IPushNotificationService
|
||||
};
|
||||
|
||||
_context.PushSubscriptions.Add(subscription);
|
||||
Log.Information("Created new push subscription for user {UserId}", userId);
|
||||
}
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
Log.Information("Push subscription created/updated for user {UserId}", userId);
|
||||
Log.Information("Push subscription saved successfully for user {UserId}", userId);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Reference in New Issue
Block a user