Skip to content

Commit

Permalink
Remove User.GetPushClient
Browse files Browse the repository at this point in the history
  • Loading branch information
nirinchev committed Feb 16, 2023
1 parent 7de185c commit 2dcfd2d
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 157 deletions.
11 changes: 6 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
35 changes: 0 additions & 35 deletions Realm/Realm/Handles/SyncUserHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -279,26 +264,6 @@ public string GetIdentities()
});
}

#region Push

public void RegisterPushToken(AppHandle app, string service, string token, TaskCompletionSource<object> 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<object> 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<ApiKey> CreateApiKeyAsync(AppHandle app, string name)
Expand Down
63 changes: 1 addition & 62 deletions Realm/Realm/Sync/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,20 +221,7 @@ public async Task<T> RefreshCustomDataAsync<T>()
/// </summary>
/// <param name="serviceName">The name of the service as configured on the server.</param>
/// <returns>A <see cref="MongoClient"/> instance that can interact with the databases exposed in the remote service.</returns>
public MongoClient GetMongoClient(string serviceName) => new MongoClient(this, serviceName);

/// <summary>
/// Gets a client for interacting the with Firebase Cloud Messaging service exposed in Atlas App Services.
/// </summary>
/// <remarks>
/// The FCM service needs to be configured and enabled in the App Services UI before devices can register
/// and receive push notifications.
/// </remarks>
/// <param name="serviceName">The name of the service as configured in the App Services UI.</param>
/// <returns>A client that exposes API to register/deregister push notification tokens.</returns>
/// <seealso href="https://docs.mongodb.com/realm/services/send-mobile-push-notifications/index.html#send-a-push-notification">Send Mobile Push Notifications Docs</seealso>
[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);

/// <summary>
/// Links the current user with a new user identity represented by the given credentials.
Expand Down Expand Up @@ -459,53 +446,5 @@ internal async Task<T> CallSerializedAsync<T>(string name, string args, string s
return BsonSerializer.Deserialize<T>(response);
}
}

/// <summary>
/// The Push client exposes an API to register/deregister for push notifications from a client app.
/// </summary>
[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;
}

/// <summary>
/// Registers the given Firebase Cloud Messaging registration token with the user's device on Atlas App Services.
/// </summary>
/// <param name="token">The FCM registration token.</param>
/// <returns>
/// An awaitable <see cref="Task"/> 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.
/// </returns>
public Task RegisterDeviceAsync(string token)
{
Argument.NotNullOrEmpty(token, nameof(token));
var tcs = new TaskCompletionSource<object>();
_user.Handle.RegisterPushToken(_user.App.Handle, _service, token, tcs);

return tcs.Task;
}

/// <summary>
/// Deregister the user's device from Firebase Cloud Messaging.
/// </summary>
/// <returns>
/// An awaitable <see cref="Task"/> 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.
/// </returns>
public Task DeregisterDeviceAsync()
{
var tcs = new TaskCompletionSource<object>();
_user.Handle.DeregisterPushToken(_user.App.Handle, _service, tcs);

return tcs.Task;
}
}
}
}
32 changes: 0 additions & 32 deletions Tests/Realm.Tests/Sync/UserManagementTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppException>(() => 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()
{
Expand Down
6 changes: 0 additions & 6 deletions Tools/DeployApps/BaasClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,6 @@ private async Task<BaasApp> CreateDefaultApp(string name)
new AuthMetadataField("maxAge", "max_age"),
});

await CreateService(app, "gcm", "gcm", new
{
senderId = "gcm",
apiKey = "gcm",
});

return app;
}

Expand Down
17 changes: 0 additions & 17 deletions wrappers/src/sync_user_cs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2dcfd2d

Please sign in to comment.