mirror of
https://github.com/bitwarden/server.git
synced 2024-11-22 12:15:36 +01:00
[PM-6977] Migrate to FCM v1 (#3917)
* fcmv1 update * try without nested data obj * type must be a string * fcmv1 migration flag * lint fixes * fix tests --------- Co-authored-by: Matt Bishop <mbishop@bitwarden.com>
This commit is contained in:
parent
a17426c2a8
commit
dd8d5955a4
@ -134,6 +134,7 @@ public static class FeatureFlagKeys
|
|||||||
public const string AC1795_UpdatedSubscriptionStatusSection = "AC-1795_updated-subscription-status-section";
|
public const string AC1795_UpdatedSubscriptionStatusSection = "AC-1795_updated-subscription-status-section";
|
||||||
public const string UnassignedItemsBanner = "unassigned-items-banner";
|
public const string UnassignedItemsBanner = "unassigned-items-banner";
|
||||||
public const string EnableDeleteProvider = "AC-1218-delete-provider";
|
public const string EnableDeleteProvider = "AC-1218-delete-provider";
|
||||||
|
public const string AnhFcmv1Migration = "anh-fcmv1-migration";
|
||||||
|
|
||||||
public static List<string> GetAllKeys()
|
public static List<string> GetAllKeys()
|
||||||
{
|
{
|
||||||
|
@ -11,16 +11,19 @@ public class NotificationHubPushRegistrationService : IPushRegistrationService
|
|||||||
{
|
{
|
||||||
private readonly IInstallationDeviceRepository _installationDeviceRepository;
|
private readonly IInstallationDeviceRepository _installationDeviceRepository;
|
||||||
private readonly GlobalSettings _globalSettings;
|
private readonly GlobalSettings _globalSettings;
|
||||||
|
private readonly IFeatureService _featureService;
|
||||||
private readonly ILogger<NotificationHubPushRegistrationService> _logger;
|
private readonly ILogger<NotificationHubPushRegistrationService> _logger;
|
||||||
private Dictionary<NotificationHubType, NotificationHubClient> _clients = [];
|
private Dictionary<NotificationHubType, NotificationHubClient> _clients = [];
|
||||||
|
|
||||||
public NotificationHubPushRegistrationService(
|
public NotificationHubPushRegistrationService(
|
||||||
IInstallationDeviceRepository installationDeviceRepository,
|
IInstallationDeviceRepository installationDeviceRepository,
|
||||||
GlobalSettings globalSettings,
|
GlobalSettings globalSettings,
|
||||||
|
IFeatureService featureService,
|
||||||
ILogger<NotificationHubPushRegistrationService> logger)
|
ILogger<NotificationHubPushRegistrationService> logger)
|
||||||
{
|
{
|
||||||
_installationDeviceRepository = installationDeviceRepository;
|
_installationDeviceRepository = installationDeviceRepository;
|
||||||
_globalSettings = globalSettings;
|
_globalSettings = globalSettings;
|
||||||
|
_featureService = featureService;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
|
||||||
// Is this dirty to do in the ctor?
|
// Is this dirty to do in the ctor?
|
||||||
@ -72,11 +75,20 @@ public class NotificationHubPushRegistrationService : IPushRegistrationService
|
|||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case DeviceType.Android:
|
case DeviceType.Android:
|
||||||
|
if (_featureService.IsEnabled(FeatureFlagKeys.AnhFcmv1Migration))
|
||||||
|
{
|
||||||
|
payloadTemplate = "{\"message\":{\"data\":{\"type\":\"$(type)\",\"payload\":\"$(payload)\"}}}";
|
||||||
|
messageTemplate = "{\"message\":{\"data\":{\"type\":\"$(type)\"}," +
|
||||||
|
"\"notification\":{\"title\":\"$(title)\",\"body\":\"$(message)\"}}}";
|
||||||
|
installation.Platform = NotificationPlatform.FcmV1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
payloadTemplate = "{\"data\":{\"data\":{\"type\":\"#(type)\",\"payload\":\"$(payload)\"}}}";
|
payloadTemplate = "{\"data\":{\"data\":{\"type\":\"#(type)\",\"payload\":\"$(payload)\"}}}";
|
||||||
messageTemplate = "{\"data\":{\"data\":{\"type\":\"#(type)\"}," +
|
messageTemplate = "{\"data\":{\"data\":{\"type\":\"#(type)\"}," +
|
||||||
"\"notification\":{\"title\":\"$(title)\",\"body\":\"$(message)\"}}}";
|
"\"notification\":{\"title\":\"$(title)\",\"body\":\"$(message)\"}}}";
|
||||||
|
|
||||||
installation.Platform = NotificationPlatform.Fcm;
|
installation.Platform = NotificationPlatform.Fcm;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case DeviceType.iOS:
|
case DeviceType.iOS:
|
||||||
payloadTemplate = "{\"data\":{\"type\":\"#(type)\",\"payload\":\"$(payload)\"}," +
|
payloadTemplate = "{\"data\":{\"type\":\"#(type)\",\"payload\":\"$(payload)\"}," +
|
||||||
|
@ -12,18 +12,21 @@ public class NotificationHubPushRegistrationServiceTests
|
|||||||
private readonly NotificationHubPushRegistrationService _sut;
|
private readonly NotificationHubPushRegistrationService _sut;
|
||||||
|
|
||||||
private readonly IInstallationDeviceRepository _installationDeviceRepository;
|
private readonly IInstallationDeviceRepository _installationDeviceRepository;
|
||||||
|
private readonly IFeatureService _featureService;
|
||||||
private readonly ILogger<NotificationHubPushRegistrationService> _logger;
|
private readonly ILogger<NotificationHubPushRegistrationService> _logger;
|
||||||
private readonly GlobalSettings _globalSettings;
|
private readonly GlobalSettings _globalSettings;
|
||||||
|
|
||||||
public NotificationHubPushRegistrationServiceTests()
|
public NotificationHubPushRegistrationServiceTests()
|
||||||
{
|
{
|
||||||
_installationDeviceRepository = Substitute.For<IInstallationDeviceRepository>();
|
_installationDeviceRepository = Substitute.For<IInstallationDeviceRepository>();
|
||||||
|
_featureService = Substitute.For<IFeatureService>();
|
||||||
_logger = Substitute.For<ILogger<NotificationHubPushRegistrationService>>();
|
_logger = Substitute.For<ILogger<NotificationHubPushRegistrationService>>();
|
||||||
_globalSettings = new GlobalSettings();
|
_globalSettings = new GlobalSettings();
|
||||||
|
|
||||||
_sut = new NotificationHubPushRegistrationService(
|
_sut = new NotificationHubPushRegistrationService(
|
||||||
_installationDeviceRepository,
|
_installationDeviceRepository,
|
||||||
_globalSettings,
|
_globalSettings,
|
||||||
|
_featureService,
|
||||||
_logger
|
_logger
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user