Skip to content

Commit

Permalink
binding: Add firebaseMessagingOnBackgroundMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
gnprice committed Nov 1, 2023
1 parent b6badf5 commit 63b61e7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/model/binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ abstract class ZulipBinding {
/// Wraps [firebase_messaging.FirebaseMessaging.onMessage].
Stream<firebase_messaging.RemoteMessage> get firebaseMessagingOnMessage;

/// Wraps [firebase_messaging.FirebaseMessaging.onBackgroundMessage].
void firebaseMessagingOnBackgroundMessage(firebase_messaging.BackgroundMessageHandler handler);

/// Wraps the [FlutterLocalNotificationsPlugin] singleton constructor.
FlutterLocalNotificationsPlugin get notifications;
}
Expand Down Expand Up @@ -199,6 +202,11 @@ class LiveZulipBinding extends ZulipBinding {
return firebase_messaging.FirebaseMessaging.onMessage;
}

@override
void firebaseMessagingOnBackgroundMessage(firebase_messaging.BackgroundMessageHandler handler) {
firebase_messaging.FirebaseMessaging.onBackgroundMessage(handler);
}

@override
FlutterLocalNotificationsPlugin get notifications => FlutterLocalNotificationsPlugin();
}
11 changes: 11 additions & 0 deletions test/model/binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ class TestZulipBinding extends ZulipBinding {
@override
Stream<RemoteMessage> get firebaseMessagingOnMessage => firebaseMessaging.onMessage.stream;

@override
void firebaseMessagingOnBackgroundMessage(BackgroundMessageHandler handler) {
firebaseMessaging.onBackgroundMessage.stream.listen(handler);
}

void _resetNotifications() {
_notificationsPlugin = null;
}
Expand Down Expand Up @@ -241,6 +246,12 @@ class FakeFirebaseMessaging extends Fake implements FirebaseMessaging {
Stream<String> get onTokenRefresh => _tokenController.stream;

StreamController<RemoteMessage> onMessage = StreamController.broadcast();

/// Controls [TestZulipBinding.firebaseMessagingOnBackgroundMessage].
///
/// Calling [StreamController.add] on this will cause a call
/// to any handler registered through the latter.
StreamController<RemoteMessage> onBackgroundMessage = StreamController.broadcast();
}

class FakeFlutterLocalNotificationsPlugin extends Fake implements FlutterLocalNotificationsPlugin {
Expand Down

0 comments on commit 63b61e7

Please sign in to comment.