-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(push): concurrency issues within PushNotificationChannelManager (#…
…228) * fix(push): concurrency issues within PushNotificationChannelManager * fix(push): lock on count to ensure atomicity
- Loading branch information
Showing
7 changed files
with
108 additions
and
47 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
...Eurofurence.App.Server.Services/Abstractions/Communication/IPrivateMessageQueueService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
|
||
namespace Eurofurence.App.Server.Services.Abstractions.Communication | ||
{ | ||
public interface IPrivateMessageQueueService | ||
{ | ||
void EnqueueMessage(QueuedNotificationParameters message); | ||
QueuedNotificationParameters? DequeueMessage(); | ||
int GetQueueSize(); | ||
|
||
public struct QueuedNotificationParameters | ||
{ | ||
public string RecipientIdentityId; | ||
public string RecipientRegSysId; | ||
public string ToastTitle; | ||
public string ToastMessage; | ||
public Guid RelatedId; | ||
} | ||
} | ||
} |
36 changes: 27 additions & 9 deletions
36
src/Eurofurence.App.Server.Services/Abstractions/PushNotifications/ApnsConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,43 @@ | ||
using dotAPNS; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace Eurofurence.App.Server.Services.Abstractions.PushNotifications | ||
{ | ||
public class ApnsConfiguration | ||
{ | ||
public bool IsConfigured => !string.IsNullOrWhiteSpace(BundleId) && !string.IsNullOrWhiteSpace(CertContent) && !string.IsNullOrWhiteSpace(KeyId) && !string.IsNullOrWhiteSpace(TeamId); | ||
public string BundleId { get; set; } | ||
public string CertFilePath { get; set; } | ||
public string CertContent { get; set; } | ||
public string KeyId { get; set; } | ||
public string TeamId { get; set; } | ||
public bool UseDevelopmentServer { get; set; } | ||
public string BundleId { get; private set; } | ||
public string CertFilePath { get; private set; } | ||
public string CertContent { get; private set; } | ||
public string KeyId { get; private set; } | ||
public string TeamId { get; private set; } | ||
public bool UseDevelopmentServer { get; private set; } | ||
public ApnsJwtOptions ApnsJwtOptions { get; private set; } | ||
|
||
public static ApnsConfiguration FromConfiguration(IConfiguration configuration) | ||
=> new ApnsConfiguration | ||
{ | ||
{ | ||
|
||
var apnsConfiguration = new ApnsConfiguration | ||
{ | ||
BundleId = configuration["push:apns:bundleId"], | ||
CertContent = configuration["push:apns:certContent"], | ||
KeyId = configuration["push:apns:keyId"], | ||
TeamId = configuration["push:apns:teamId"], | ||
UseDevelopmentServer = bool.TryParse(configuration["push:apns:useDevelopmentServer"], out bool shouldUseDevelopmentServer) ? shouldUseDevelopmentServer : true, | ||
}; | ||
}; | ||
|
||
if (apnsConfiguration.IsConfigured) | ||
{ | ||
apnsConfiguration.ApnsJwtOptions = new ApnsJwtOptions() | ||
{ | ||
BundleId = apnsConfiguration.BundleId, | ||
CertContent = apnsConfiguration.CertContent, | ||
KeyId = apnsConfiguration.KeyId, | ||
TeamId = apnsConfiguration.TeamId, | ||
}; | ||
} | ||
|
||
return apnsConfiguration; | ||
} | ||
} | ||
} |
24 changes: 18 additions & 6 deletions
24
src/Eurofurence.App.Server.Services/Abstractions/PushNotifications/FirebaseConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,28 @@ | ||
using FirebaseAdmin; | ||
using Google.Apis.Auth.OAuth2; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace Eurofurence.App.Server.Services.Abstractions.PushNotifications | ||
{ | ||
public class FirebaseConfiguration | ||
{ | ||
public bool IsConfigured => !string.IsNullOrWhiteSpace(GoogleServiceCredentialKeyFile); | ||
public string GoogleServiceCredentialKeyFile { get; set; } | ||
public bool IsConfigured => !string.IsNullOrWhiteSpace(GoogleServiceCredentialKeyFile) && GoogleCredential != null; | ||
public string GoogleServiceCredentialKeyFile { get; private set; } | ||
public GoogleCredential GoogleCredential { get; private set; } | ||
|
||
public static FirebaseConfiguration FromConfiguration(IConfiguration configuration) | ||
=> new FirebaseConfiguration | ||
{ | ||
GoogleServiceCredentialKeyFile = configuration["push:firebase:googleServiceCredentialKeyFile"] | ||
}; | ||
{ | ||
var firebaseConfiguration = new FirebaseConfiguration | ||
{ | ||
GoogleServiceCredentialKeyFile = configuration["push:firebase:googleServiceCredentialKeyFile"] | ||
}; | ||
|
||
if (!string.IsNullOrWhiteSpace(firebaseConfiguration.GoogleServiceCredentialKeyFile)) { | ||
firebaseConfiguration.GoogleCredential = GoogleCredential.FromFile(firebaseConfiguration.GoogleServiceCredentialKeyFile); | ||
FirebaseApp.Create(new AppOptions { Credential = firebaseConfiguration.GoogleCredential }); | ||
} | ||
|
||
return firebaseConfiguration; | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/Eurofurence.App.Server.Services/Communication/PrivateMessageQueueService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Collections.Generic; | ||
using Eurofurence.App.Server.Services.Abstractions.Communication; | ||
|
||
namespace Eurofurence.App.Server.Services.Communication | ||
{ | ||
public class PrivateMessageQueueService : IPrivateMessageQueueService | ||
{ | ||
private readonly Queue<IPrivateMessageQueueService.QueuedNotificationParameters> _notificationQueue = new(); | ||
|
||
public void EnqueueMessage(IPrivateMessageQueueService.QueuedNotificationParameters message) | ||
{ | ||
lock (_notificationQueue) | ||
_notificationQueue.Enqueue(message); | ||
} | ||
|
||
public IPrivateMessageQueueService.QueuedNotificationParameters? DequeueMessage() | ||
{ | ||
lock (_notificationQueue) | ||
{ | ||
if (_notificationQueue.TryDequeue(out var item)) | ||
return item; | ||
return default; | ||
} | ||
} | ||
|
||
public int GetQueueSize() { | ||
lock (_notificationQueue) | ||
return _notificationQueue.Count; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters