From a2724f9a7b07b592f628476796623580b587e3ec Mon Sep 17 00:00:00 2001 From: Maxwell Weru Date: Sat, 3 Feb 2024 13:19:20 +0300 Subject: [PATCH] Mark all FirebaseLegacy code as obsolete --- .../FcmLegacy/FcmLegacyAuthenticationHandler.cs | 1 + .../FcmLegacy/FcmLegacyNotifier.cs | 1 + .../FcmLegacy/FcmLegacyNotifierConfigureOptions.cs | 2 ++ .../FcmLegacy/FcmLegacyNotifierOptions.cs | 2 ++ .../FcmLegacy/Models/FcmLegacyErrorCode.cs | 1 + .../FcmLegacy/Models/FcmLegacyNotification.cs | 1 + .../FcmLegacy/Models/FcmLegacyNotificationAndroid.cs | 1 + .../FcmLegacy/Models/FcmLegacyNotificationIos.cs | 1 + .../FcmLegacy/Models/FcmLegacyNotificationWeb.cs | 1 + .../FcmLegacy/Models/FcmLegacyPriority.cs | 1 + .../FcmLegacy/Models/FcmLegacyRequest.cs | 5 +++++ .../FcmLegacy/Models/FcmLegacyResponse.cs | 1 + .../FcmLegacy/Models/FcmLegacyResult.cs | 1 + .../IServiceCollectionExtensions.cs | 2 ++ src/Tingle.Extensions.PushNotifications/MessageStrings.cs | 2 ++ .../PushNotificationsJsonSerializerContext.cs | 2 ++ .../FcmLegacyNotifierTests.cs | 2 ++ 17 files changed, 27 insertions(+) diff --git a/src/Tingle.Extensions.PushNotifications/FcmLegacy/FcmLegacyAuthenticationHandler.cs b/src/Tingle.Extensions.PushNotifications/FcmLegacy/FcmLegacyAuthenticationHandler.cs index 17b87fb..43399f7 100644 --- a/src/Tingle.Extensions.PushNotifications/FcmLegacy/FcmLegacyAuthenticationHandler.cs +++ b/src/Tingle.Extensions.PushNotifications/FcmLegacy/FcmLegacyAuthenticationHandler.cs @@ -8,6 +8,7 @@ namespace Tingle.Extensions.PushNotifications.FcmLegacy; /// Implementation of for . /// /// The options accessor for . +[Obsolete(MessageStrings.FirebaseLegacyObsoleteMessage)] internal class FcmLegacyAuthenticationHandler(IOptionsSnapshot optionsAccessor) : AuthenticationHandler { private readonly FcmLegacyNotifierOptions options = optionsAccessor?.Value ?? throw new ArgumentNullException(nameof(optionsAccessor)); diff --git a/src/Tingle.Extensions.PushNotifications/FcmLegacy/FcmLegacyNotifier.cs b/src/Tingle.Extensions.PushNotifications/FcmLegacy/FcmLegacyNotifier.cs index fc6eb11..51bb970 100644 --- a/src/Tingle.Extensions.PushNotifications/FcmLegacy/FcmLegacyNotifier.cs +++ b/src/Tingle.Extensions.PushNotifications/FcmLegacy/FcmLegacyNotifier.cs @@ -12,6 +12,7 @@ namespace Tingle.Extensions.PushNotifications.FcmLegacy; /// /// The for making requests. /// The options accessor for . +[Obsolete(MessageStrings.FirebaseLegacyObsoleteMessage)] public class FcmLegacyNotifier(HttpClient httpClient, IOptionsSnapshot optionsAccessor) : AbstractHttpApiClient(httpClient, optionsAccessor) { private const string BaseUrl = "https://fcm.googleapis.com/fcm/send"; diff --git a/src/Tingle.Extensions.PushNotifications/FcmLegacy/FcmLegacyNotifierConfigureOptions.cs b/src/Tingle.Extensions.PushNotifications/FcmLegacy/FcmLegacyNotifierConfigureOptions.cs index 548d5a5..275cea7 100644 --- a/src/Tingle.Extensions.PushNotifications/FcmLegacy/FcmLegacyNotifierConfigureOptions.cs +++ b/src/Tingle.Extensions.PushNotifications/FcmLegacy/FcmLegacyNotifierConfigureOptions.cs @@ -1,7 +1,9 @@ using Microsoft.Extensions.Options; +using Tingle.Extensions.PushNotifications; namespace Microsoft.Extensions.DependencyInjection; +[Obsolete(MessageStrings.FirebaseLegacyObsoleteMessage)] internal class FcmLegacyNotifierConfigureOptions : IValidateOptions { /// diff --git a/src/Tingle.Extensions.PushNotifications/FcmLegacy/FcmLegacyNotifierOptions.cs b/src/Tingle.Extensions.PushNotifications/FcmLegacy/FcmLegacyNotifierOptions.cs index 0fe6d24..10d0757 100644 --- a/src/Tingle.Extensions.PushNotifications/FcmLegacy/FcmLegacyNotifierOptions.cs +++ b/src/Tingle.Extensions.PushNotifications/FcmLegacy/FcmLegacyNotifierOptions.cs @@ -1,9 +1,11 @@ using Tingle.Extensions.Http; +using Tingle.Extensions.PushNotifications; using Tingle.Extensions.PushNotifications.FcmLegacy; namespace Microsoft.Extensions.DependencyInjection; /// Configuration options for . +[Obsolete(MessageStrings.FirebaseLegacyObsoleteMessage)] public class FcmLegacyNotifierOptions : AbstractHttpApiClientOptions { /// The authentication key for Firebase using the legacy HTTP API. diff --git a/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyErrorCode.cs b/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyErrorCode.cs index 3d9806d..635d819 100644 --- a/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyErrorCode.cs +++ b/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyErrorCode.cs @@ -5,6 +5,7 @@ namespace Tingle.Extensions.PushNotifications.FcmLegacy.Models; /// /// Represents a reason why an FCM request failed in the legacy HTTP API. /// +[Obsolete(MessageStrings.FirebaseLegacyObsoleteMessage)] [JsonConverter(typeof(JsonStringEnumConverter))] public enum FcmLegacyErrorCode { diff --git a/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyNotification.cs b/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyNotification.cs index a9b040a..aca6a97 100644 --- a/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyNotification.cs +++ b/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyNotification.cs @@ -5,6 +5,7 @@ namespace Tingle.Extensions.PushNotifications.FcmLegacy.Models; /// /// Abstractions for an FCM notification using legacy HTTP API. /// +[Obsolete(MessageStrings.FirebaseLegacyObsoleteMessage)] public abstract class FcmLegacyNotification { /// diff --git a/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyNotificationAndroid.cs b/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyNotificationAndroid.cs index fe5d761..cc088c4 100644 --- a/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyNotificationAndroid.cs +++ b/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyNotificationAndroid.cs @@ -5,6 +5,7 @@ namespace Tingle.Extensions.PushNotifications.FcmLegacy.Models; /// /// Represents an for Android in the legacy HTTP API. /// +[Obsolete(MessageStrings.FirebaseLegacyObsoleteMessage)] public class FcmLegacyNotificationAndroid : FcmLegacyNotification { /// diff --git a/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyNotificationIos.cs b/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyNotificationIos.cs index 4c1008b..94c64c5 100644 --- a/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyNotificationIos.cs +++ b/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyNotificationIos.cs @@ -5,6 +5,7 @@ namespace Tingle.Extensions.PushNotifications.FcmLegacy.Models; /// /// Represents an for iOS. /// +[Obsolete(MessageStrings.FirebaseLegacyObsoleteMessage)] public class FcmLegacyNotificationIos : FcmLegacyNotification { /// diff --git a/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyNotificationWeb.cs b/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyNotificationWeb.cs index 25f889b..626cb23 100644 --- a/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyNotificationWeb.cs +++ b/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyNotificationWeb.cs @@ -5,6 +5,7 @@ namespace Tingle.Extensions.PushNotifications.FcmLegacy.Models; /// /// Represents an for Web (i.e. Chrome). /// +[Obsolete(MessageStrings.FirebaseLegacyObsoleteMessage)] public class FcmLegacyNotificationWeb : FcmLegacyNotification { /// diff --git a/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyPriority.cs b/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyPriority.cs index 53e45ae..a0733e5 100644 --- a/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyPriority.cs +++ b/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyPriority.cs @@ -5,6 +5,7 @@ namespace Tingle.Extensions.PushNotifications.FcmLegacy.Models; /// /// Represents the priority of an FCM request in the legacy HTTP API. /// +[Obsolete(MessageStrings.FirebaseLegacyObsoleteMessage)] [JsonConverter(typeof(JsonStringEnumConverter))] public enum FcmLegacyPriority { diff --git a/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyRequest.cs b/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyRequest.cs index 8d5ca14..d4445e0 100644 --- a/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyRequest.cs +++ b/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyRequest.cs @@ -5,6 +5,7 @@ namespace Tingle.Extensions.PushNotifications.FcmLegacy.Models; /// /// Represents a request payload sent to Firebase Cloud Messaging (FCM) using the legacy HTTP API. /// +[Obsolete(MessageStrings.FirebaseLegacyObsoleteMessage)] public class FcmLegacyRequest { /// @@ -133,6 +134,7 @@ public class FcmLegacyRequest /// Represents a request payload sent to Firebase Cloud Messaging (FCM) using the legacy HTTP API. /// /// The type for use with the property. +[Obsolete(MessageStrings.FirebaseLegacyObsoleteMessage)] public class FcmLegacyRequest : FcmLegacyRequest where TNotification : FcmLegacyNotification, new() // using the generic type solves a serialization issue with System.Text.Json { /// @@ -149,14 +151,17 @@ public class FcmLegacyRequest /// /// Represents a request payload sent to Firebase Cloud Messaging (FCM) using the legacy HTTP API to Android. /// +[Obsolete(MessageStrings.FirebaseLegacyObsoleteMessage)] public class FcmLegacyRequestAndroid : FcmLegacyRequest { } /// /// Represents a request payload sent to Firebase Cloud Messaging (FCM) using the legacy HTTP API to iOS. /// +[Obsolete(MessageStrings.FirebaseLegacyObsoleteMessage)] public class FcmLegacyRequestIos : FcmLegacyRequest { } /// /// Represents a request payload sent to Firebase Cloud Messaging (FCM) using the legacy HTTP API to Web. /// +[Obsolete(MessageStrings.FirebaseLegacyObsoleteMessage)] public class FcmLegacyRequestWeb : FcmLegacyRequest { } diff --git a/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyResponse.cs b/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyResponse.cs index ebe45bc..c19d4ef 100644 --- a/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyResponse.cs +++ b/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyResponse.cs @@ -5,6 +5,7 @@ namespace Tingle.Extensions.PushNotifications.FcmLegacy.Models; /// /// Represents a response payload received from Firebase Cloud Messaging (FCM) in the legacy HTTP API. /// +[Obsolete(MessageStrings.FirebaseLegacyObsoleteMessage)] public class FcmLegacyResponse { /// diff --git a/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyResult.cs b/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyResult.cs index 56ee8a7..34fcc3c 100644 --- a/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyResult.cs +++ b/src/Tingle.Extensions.PushNotifications/FcmLegacy/Models/FcmLegacyResult.cs @@ -5,6 +5,7 @@ namespace Tingle.Extensions.PushNotifications.FcmLegacy.Models; /// /// Represents the result of each sent message using the legacy HTTP API. /// +[Obsolete(MessageStrings.FirebaseLegacyObsoleteMessage)] public class FcmLegacyResult { /// diff --git a/src/Tingle.Extensions.PushNotifications/IServiceCollectionExtensions.cs b/src/Tingle.Extensions.PushNotifications/IServiceCollectionExtensions.cs index e326ffa..07dd67c 100644 --- a/src/Tingle.Extensions.PushNotifications/IServiceCollectionExtensions.cs +++ b/src/Tingle.Extensions.PushNotifications/IServiceCollectionExtensions.cs @@ -1,4 +1,5 @@ using Tingle.Extensions.Http; +using Tingle.Extensions.PushNotifications; using Tingle.Extensions.PushNotifications.Apple; using Tingle.Extensions.PushNotifications.FcmLegacy; using Tingle.Extensions.PushNotifications.Firebase; @@ -14,6 +15,7 @@ public static class IServiceCollectionExtensions /// The to add to. /// Action to configure instances. /// An that can be used to configure the client. + [Obsolete(MessageStrings.FirebaseLegacyObsoleteMessage)] public static IHttpClientBuilder AddFcmLegacyNotifier(this IServiceCollection services, Action? configure = null) { // configure authentication diff --git a/src/Tingle.Extensions.PushNotifications/MessageStrings.cs b/src/Tingle.Extensions.PushNotifications/MessageStrings.cs index bb4976f..d4aa170 100644 --- a/src/Tingle.Extensions.PushNotifications/MessageStrings.cs +++ b/src/Tingle.Extensions.PushNotifications/MessageStrings.cs @@ -4,4 +4,6 @@ internal class MessageStrings { internal const string SerializationUnreferencedCodeMessage = "JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved."; internal const string SerializationRequiresDynamicCodeMessage = "JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications."; + + internal const string FirebaseLegacyObsoleteMessage = "FCM legacy APIs for HTTP and XMPP protocols are deprecated and will be removed in the future. Migrate to the HTTP v1 API (Tingle.Extensions.PushNotifications.Firebase) before June 2024 to ensure uninterrupted service. See https://firebase.google.com/docs/cloud-messaging/migrate-v1 for more details."; } diff --git a/src/Tingle.Extensions.PushNotifications/PushNotificationsJsonSerializerContext.cs b/src/Tingle.Extensions.PushNotifications/PushNotificationsJsonSerializerContext.cs index ac56b7a..51990e4 100644 --- a/src/Tingle.Extensions.PushNotifications/PushNotificationsJsonSerializerContext.cs +++ b/src/Tingle.Extensions.PushNotifications/PushNotificationsJsonSerializerContext.cs @@ -8,11 +8,13 @@ namespace Tingle.Extensions.PushNotifications; [JsonSerializable(typeof(Apple.ApnsAuthenticationHandler.ApnsAuthHeader))] [JsonSerializable(typeof(Apple.ApnsAuthenticationHandler.ApnsAuthPayload))] +#pragma warning disable CS0618 // Type or member is obsolete [JsonSerializable(typeof(FcmLegacy.Models.FcmLegacyRequest))] [JsonSerializable(typeof(FcmLegacy.Models.FcmLegacyRequestAndroid))] [JsonSerializable(typeof(FcmLegacy.Models.FcmLegacyRequestIos))] [JsonSerializable(typeof(FcmLegacy.Models.FcmLegacyRequestWeb))] [JsonSerializable(typeof(FcmLegacy.Models.FcmLegacyResponse))] +#pragma warning restore CS0618 // Type or member is obsolete [JsonSerializable(typeof(Firebase.Models.FirebaseRequest))] [JsonSerializable(typeof(Firebase.Models.FirebaseResponse))] diff --git a/tests/Tingle.Extensions.PushNotifications.Tests/FcmLegacyNotifierTests.cs b/tests/Tingle.Extensions.PushNotifications.Tests/FcmLegacyNotifierTests.cs index 90717a6..8f0f510 100644 --- a/tests/Tingle.Extensions.PushNotifications.Tests/FcmLegacyNotifierTests.cs +++ b/tests/Tingle.Extensions.PushNotifications.Tests/FcmLegacyNotifierTests.cs @@ -4,6 +4,8 @@ using Tingle.Extensions.PushNotifications.FcmLegacy.Models; using Xunit.Abstractions; +#pragma warning disable CS0618 // Type or member is obsolete + namespace Tingle.Extensions.PushNotifications.Tests; public class FcmLegacyNotifierTests(ITestOutputHelper outputHelper)