From 69444a01253d24d2b06280d995727e8a94ea7046 Mon Sep 17 00:00:00 2001 From: nirinchev Date: Thu, 16 Feb 2023 14:33:12 +0100 Subject: [PATCH] Remove User.GetPushClient --- CHANGELOG.md | 11 ++-- Realm/Realm/Handles/SyncUserHandle.cs | 35 ----------- Realm/Realm/Sync/User.cs | 63 +------------------ Tests/Realm.Tests/Sync/UserManagementTests.cs | 32 ---------- Tools/DeployApps/BaasClient.cs | 6 -- wrappers/src/sync_user_cs.cpp | 17 ----- 6 files changed, 7 insertions(+), 157 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1213060149..982e9df055 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,11 +30,12 @@ * Removed `DiscardLocalResetHandler` - use `DiscardUnsyncedChangedHandler` instead. (PR [#3237](https://github.com/realm/realm-dotnet/pull/3237)) * Removed `Session.SimulateClientReset` extensions. These didn't work with automatic reset handlers and were more confusing than helpful. (PR [#3237](https://github.com/realm/realm-dotnet/pull/3237)) * Removed `AppConfiguration.CustomLogger` and `AppConfiguration.LogLevel` - use `Logger.Default` and `Logger.LogLevel` instead. (PR [#3238](https://github.com/realm/realm-dotnet/pull/3238)) -* Removed `RealmConfigurationBase.ObjectClasses` - use `RealmConfigurationBase.Schema` instead. (PR [#3239](https://github.com/realm/realm-dotnet/pull/3239)) -* Removed `ObjectSchema.IsEmbedded` - use `ObjectSchema.BaseType` instead. (PR [#3239](https://github.com/realm/realm-dotnet/pull/3239)) -* Removed `ObjectSchema.Builder.IsEmbedded` - use `ObjectSchema.Builder.RealmSchemaType` instead. (PR [#3239](https://github.com/realm/realm-dotnet/pull/3239)) -* Removed `ObjectSchema.Builder(string name, bool isEmbedded = false)` - use `Builder(string name, ObjectSchemaType schemaType)` instead. (PR [#3239](https://github.com/realm/realm-dotnet/pull/3239)) -* Removed `RealmSchema.Find` - use `RealmSchema.TryFindObjectSchema` instead. (PR [#3239](https://github.com/realm/realm-dotnet/pull/3239)) +* Removed `RealmConfigurationBase.ObjectClasses` - use `RealmConfigurationBase.Schema` instead. (PR [#3240](https://github.com/realm/realm-dotnet/pull/3240)) +* Removed `ObjectSchema.IsEmbedded` - use `ObjectSchema.BaseType` instead. (PR [#3240](https://github.com/realm/realm-dotnet/pull/3240)) +* Removed `ObjectSchema.Builder.IsEmbedded` - use `ObjectSchema.Builder.RealmSchemaType` instead. (PR [#3240](https://github.com/realm/realm-dotnet/pull/3240)) +* Removed `ObjectSchema.Builder(string name, bool isEmbedded = false)` - use `Builder(string name, ObjectSchemaType schemaType)` instead. (PR [#3240](https://github.com/realm/realm-dotnet/pull/3240)) +* Removed `RealmSchema.Find` - use `RealmSchema.TryFindObjectSchema` instead. (PR [#3240](https://github.com/realm/realm-dotnet/pull/3240)) +* Removed `User.GetPushClient` as it has been deprecated in Atlas App Services - see https://www.mongodb.com/docs/atlas/app-services/reference/push-notifications/. (PR [#3241](https://github.com/realm/realm-dotnet/pull/3241)) ### Enhancements diff --git a/Realm/Realm/Handles/SyncUserHandle.cs b/Realm/Realm/Handles/SyncUserHandle.cs index 3543af600a..253697f9a1 100644 --- a/Realm/Realm/Handles/SyncUserHandle.cs +++ b/Realm/Realm/Handles/SyncUserHandle.cs @@ -84,21 +84,6 @@ private static class NativeMethods [DllImport(InteropConfig.DLL_NAME, EntryPoint = "realm_syncuser_get_serialized_identities", CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr get_identities(SyncUserHandle handle, IntPtr buffer, IntPtr bufsize, out NativeException ex); - #region Push - - [DllImport(InteropConfig.DLL_NAME, EntryPoint = "realm_syncuser_push_register", CallingConvention = CallingConvention.Cdecl)] - public static extern void push_register(SyncUserHandle handle, AppHandle app, - [MarshalAs(UnmanagedType.LPWStr)] string service, IntPtr service_len, - [MarshalAs(UnmanagedType.LPWStr)] string token, IntPtr token_len, - IntPtr tcs_ptr, out NativeException ex); - - [DllImport(InteropConfig.DLL_NAME, EntryPoint = "realm_syncuser_push_deregister", CallingConvention = CallingConvention.Cdecl)] - public static extern void push_deregister(SyncUserHandle handle, AppHandle app, - [MarshalAs(UnmanagedType.LPWStr)] string service, IntPtr service_len, - IntPtr tcs_ptr, out NativeException ex); - - #endregion - #region Api Keys [DllImport(InteropConfig.DLL_NAME, EntryPoint = "realm_syncuser_api_key_create", CallingConvention = CallingConvention.Cdecl)] @@ -279,26 +264,6 @@ public string GetIdentities() }); } - #region Push - - public void RegisterPushToken(AppHandle app, string service, string token, TaskCompletionSource tcs) - { - var tcsHandle = GCHandle.Alloc(tcs); - - NativeMethods.push_register(this, app, service, (IntPtr)service.Length, token, (IntPtr)token.Length, GCHandle.ToIntPtr(tcsHandle), out var ex); - ex.ThrowIfNecessary(); - } - - public void DeregisterPushToken(AppHandle app, string service, TaskCompletionSource tcs) - { - var tcsHandle = GCHandle.Alloc(tcs); - - NativeMethods.push_deregister(this, app, service, (IntPtr)service.Length, GCHandle.ToIntPtr(tcsHandle), out var ex); - ex.ThrowIfNecessary(); - } - - #endregion - #region Api Keys public async Task CreateApiKeyAsync(AppHandle app, string name) diff --git a/Realm/Realm/Sync/User.cs b/Realm/Realm/Sync/User.cs index a961244fb8..b29bcb0a1f 100644 --- a/Realm/Realm/Sync/User.cs +++ b/Realm/Realm/Sync/User.cs @@ -221,20 +221,7 @@ public async Task RefreshCustomDataAsync() /// /// The name of the service as configured on the server. /// A instance that can interact with the databases exposed in the remote service. - public MongoClient GetMongoClient(string serviceName) => new MongoClient(this, serviceName); - - /// - /// Gets a client for interacting the with Firebase Cloud Messaging service exposed in Atlas App Services. - /// - /// - /// The FCM service needs to be configured and enabled in the App Services UI before devices can register - /// and receive push notifications. - /// - /// The name of the service as configured in the App Services UI. - /// A client that exposes API to register/deregister push notification tokens. - /// Send Mobile Push Notifications Docs - [Obsolete("The push notifications functionality has been deprecated: https://www.mongodb.com/docs/atlas/app-services/reference/push-notifications/")] - public PushClient GetPushClient(string serviceName) => new PushClient(this, serviceName); + public MongoClient GetMongoClient(string serviceName) => new(this, serviceName); /// /// Links the current user with a new user identity represented by the given credentials. @@ -459,53 +446,5 @@ internal async Task CallSerializedAsync(string name, string args, string s return BsonSerializer.Deserialize(response); } } - - /// - /// The Push client exposes an API to register/deregister for push notifications from a client app. - /// - [Obsolete("The push notifications functionality has been deprecated: https://www.mongodb.com/docs/atlas/app-services/reference/push-notifications/")] - public class PushClient - { - private readonly User _user; - private readonly string _service; - - internal PushClient(User user, string service) - { - _user = user; - _service = service; - } - - /// - /// Registers the given Firebase Cloud Messaging registration token with the user's device on Atlas App Services. - /// - /// The FCM registration token. - /// - /// An awaitable representing the remote operation. Successful completion indicates that the registration token was registered - /// by Atlas App Services and this device can now receive push notifications. - /// - public Task RegisterDeviceAsync(string token) - { - Argument.NotNullOrEmpty(token, nameof(token)); - var tcs = new TaskCompletionSource(); - _user.Handle.RegisterPushToken(_user.App.Handle, _service, token, tcs); - - return tcs.Task; - } - - /// - /// Deregister the user's device from Firebase Cloud Messaging. - /// - /// - /// An awaitable representing the remote operation. Successful completion indicates that the device's registration token - /// was removed from Atlas App Services and it will no longer receive push notifications. - /// - public Task DeregisterDeviceAsync() - { - var tcs = new TaskCompletionSource(); - _user.Handle.DeregisterPushToken(_user.App.Handle, _service, tcs); - - return tcs.Task; - } - } } } diff --git a/Tests/Realm.Tests/Sync/UserManagementTests.cs b/Tests/Realm.Tests/Sync/UserManagementTests.cs index 6418d70355..3e51b7e3bb 100644 --- a/Tests/Realm.Tests/Sync/UserManagementTests.cs +++ b/Tests/Realm.Tests/Sync/UserManagementTests.cs @@ -410,38 +410,6 @@ public void User_LinkCredentials_WhenInUse_Throws() }); } - [Test, Obsolete("Tests push client")] - public void User_Push_RegisterDevice() - { - SyncTestHelpers.RunBaasTestAsync(async () => - { - var user = await GetUserAsync(); - await user.GetPushClient("gcm").RegisterDeviceAsync("hello"); - }); - } - - [Test, Obsolete("Tests push client")] - public void User_Push_RegisterDevice_WrongService() - { - SyncTestHelpers.RunBaasTestAsync(async () => - { - var user = await GetUserAsync(); - var ex = await TestHelpers.AssertThrows(() => user.GetPushClient("non-existent").RegisterDeviceAsync("hello")); - Assert.That(ex.StatusCode, Is.EqualTo(HttpStatusCode.NotFound)); - Assert.That(ex.Message, Does.Contain("service not found: 'non-existent'")); - }); - } - - [Test, Obsolete("Tests push client")] - public void User_Push_DeregisterDevice() - { - SyncTestHelpers.RunBaasTestAsync(async () => - { - var user = await GetUserAsync(); - await user.GetPushClient("gcm").DeregisterDeviceAsync(); - }); - } - [Test] public void User_JWT_LogsInAndReadsDataFromToken() { diff --git a/Tools/DeployApps/BaasClient.cs b/Tools/DeployApps/BaasClient.cs index 493c55b8b5..a7ad9063e9 100644 --- a/Tools/DeployApps/BaasClient.cs +++ b/Tools/DeployApps/BaasClient.cs @@ -330,12 +330,6 @@ private async Task CreateDefaultApp(string name) new AuthMetadataField("maxAge", "max_age"), }); - await CreateService(app, "gcm", "gcm", new - { - senderId = "gcm", - apiKey = "gcm", - }); - return app; } diff --git a/wrappers/src/sync_user_cs.cpp b/wrappers/src/sync_user_cs.cpp index 9c4bbe6ee4..df3e47f062 100644 --- a/wrappers/src/sync_user_cs.cpp +++ b/wrappers/src/sync_user_cs.cpp @@ -269,23 +269,6 @@ extern "C" { }); } - REALM_EXPORT void realm_syncuser_push_register(SharedSyncUser& user, SharedApp& app, uint16_t* service_buf, size_t service_len, uint16_t* token_buf, size_t token_len, void* tcs_ptr, NativeException::Marshallable& ex) - { - handle_errors(ex, [&] { - Utf16StringAccessor service(service_buf, service_len); - Utf16StringAccessor token(token_buf, token_len); - app->push_notification_client(service).register_device(token, user, get_callback_handler(tcs_ptr)); - }); - } - - REALM_EXPORT void realm_syncuser_push_deregister(SharedSyncUser& user, SharedApp& app, uint16_t* service_buf, size_t service_len, void* tcs_ptr, NativeException::Marshallable& ex) - { - handle_errors(ex, [&] { - Utf16StringAccessor service(service_buf, service_len); - app->push_notification_client(service).deregister_device(user, get_callback_handler(tcs_ptr)); - }); - } - #pragma region ApiKeys REALM_EXPORT void realm_syncuser_api_key_create(SharedSyncUser& user, SharedApp& app, uint16_t* name_buf, size_t name_len, void* tcs_ptr, NativeException::Marshallable& ex)