Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: setOnBackgroundMessage() is now a Future<void> that will await for the function to complete. #499

Merged
merged 7 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/src/platform/src/method_call_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class AblyMethodCallHandler {
}

Future<Object?> _onPushBackgroundMessage(RemoteMessage remoteMessage) async {
_pushNotificationEvents.handleBackgroundMessage(remoteMessage);
await _pushNotificationEvents.handleBackgroundMessage(remoteMessage);
return null;
}

Expand Down
9 changes: 7 additions & 2 deletions lib/src/platform/src/push_notification_events_internal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,14 @@ class PushNotificationEventsInternal implements PushNotificationEvents {

/// @nodoc
/// Handles a RemoteMessage passed from the platform side.
void handleBackgroundMessage(RemoteMessage remoteMessage) {
Future<void> handleBackgroundMessage(RemoteMessage remoteMessage) async {
if (_onBackgroundMessage != null) {
_onBackgroundMessage!(remoteMessage);
final onBackgroundMessageResult = _onBackgroundMessage!(remoteMessage);
// ^^^ _onBackgroundMessage() can return void or Future<void>
if (onBackgroundMessageResult is Future) {
// if it returns a Future we await on it.
await onBackgroundMessageResult;
}
} else {
// ignore:avoid_print
print('Received RemoteMessage but no handler was set. '
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:ably_flutter/ably_flutter.dart';

/// Type definition for a callback invoked when background push message
/// is received.
typedef BackgroundMessageHandler = void Function(RemoteMessage message);
typedef BackgroundMessageHandler = dynamic Function(RemoteMessage message);

/// Push Notification events, such as message arriving or notification tap.
abstract class PushNotificationEvents {
Expand Down
Loading