diff --git a/src/Core/Constants.cs b/src/Core/Constants.cs index 55751c4dfd..37eee0c70a 100644 --- a/src/Core/Constants.cs +++ b/src/Core/Constants.cs @@ -134,6 +134,7 @@ public static class FeatureFlagKeys public const string AC1795_UpdatedSubscriptionStatusSection = "AC-1795_updated-subscription-status-section"; public const string UnassignedItemsBanner = "unassigned-items-banner"; public const string EnableDeleteProvider = "AC-1218-delete-provider"; + public const string AnhFcmv1Migration = "anh-fcmv1-migration"; public static List GetAllKeys() { diff --git a/src/Core/Services/Implementations/NotificationHubPushRegistrationService.cs b/src/Core/Services/Implementations/NotificationHubPushRegistrationService.cs index 9a31a2a879..b3f46bd139 100644 --- a/src/Core/Services/Implementations/NotificationHubPushRegistrationService.cs +++ b/src/Core/Services/Implementations/NotificationHubPushRegistrationService.cs @@ -11,16 +11,19 @@ public class NotificationHubPushRegistrationService : IPushRegistrationService { private readonly IInstallationDeviceRepository _installationDeviceRepository; private readonly GlobalSettings _globalSettings; + private readonly IFeatureService _featureService; private readonly ILogger _logger; private Dictionary _clients = []; public NotificationHubPushRegistrationService( IInstallationDeviceRepository installationDeviceRepository, GlobalSettings globalSettings, + IFeatureService featureService, ILogger logger) { _installationDeviceRepository = installationDeviceRepository; _globalSettings = globalSettings; + _featureService = featureService; _logger = logger; // Is this dirty to do in the ctor? @@ -72,11 +75,20 @@ public class NotificationHubPushRegistrationService : IPushRegistrationService switch (type) { case DeviceType.Android: - payloadTemplate = "{\"data\":{\"data\":{\"type\":\"#(type)\",\"payload\":\"$(payload)\"}}}"; - messageTemplate = "{\"data\":{\"data\":{\"type\":\"#(type)\"}," + - "\"notification\":{\"title\":\"$(title)\",\"body\":\"$(message)\"}}}"; - - installation.Platform = NotificationPlatform.Fcm; + 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)\"}}}"; + messageTemplate = "{\"data\":{\"data\":{\"type\":\"#(type)\"}," + + "\"notification\":{\"title\":\"$(title)\",\"body\":\"$(message)\"}}}"; + installation.Platform = NotificationPlatform.Fcm; + } break; case DeviceType.iOS: payloadTemplate = "{\"data\":{\"type\":\"#(type)\",\"payload\":\"$(payload)\"}," + diff --git a/test/Core.Test/Services/NotificationHubPushRegistrationServiceTests.cs b/test/Core.Test/Services/NotificationHubPushRegistrationServiceTests.cs index 0b9c64121b..b42ef1cba5 100644 --- a/test/Core.Test/Services/NotificationHubPushRegistrationServiceTests.cs +++ b/test/Core.Test/Services/NotificationHubPushRegistrationServiceTests.cs @@ -12,18 +12,21 @@ public class NotificationHubPushRegistrationServiceTests private readonly NotificationHubPushRegistrationService _sut; private readonly IInstallationDeviceRepository _installationDeviceRepository; + private readonly IFeatureService _featureService; private readonly ILogger _logger; private readonly GlobalSettings _globalSettings; public NotificationHubPushRegistrationServiceTests() { _installationDeviceRepository = Substitute.For(); + _featureService = Substitute.For(); _logger = Substitute.For>(); _globalSettings = new GlobalSettings(); _sut = new NotificationHubPushRegistrationService( _installationDeviceRepository, _globalSettings, + _featureService, _logger ); }