Skip to content

Commit

Permalink
Merge pull request #499 from ably/test-run-ci-for-forked-pr
Browse files Browse the repository at this point in the history
feat: setOnBackgroundMessage() is now a Future<void> that will await for the function to complete.
  • Loading branch information
ttypic authored Dec 13, 2023
2 parents 0589304 + 997c3f2 commit 39bc618
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
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

0 comments on commit 39bc618

Please sign in to comment.