diff --git a/lib/notifications/display.dart b/lib/notifications/display.dart index 54e8d18c19..f07959e7c1 100644 --- a/lib/notifications/display.dart +++ b/lib/notifications/display.dart @@ -52,16 +52,14 @@ class NotificationChannelManager { // channel ID and delete it. See zulip-mobile's `createNotificationChannel` // in android/app/src/main/java/com/zulipmobile/notifications/NotificationChannelManager.kt . static Future _ensureChannel() async { - final plugin = ZulipBinding.instance.notifications; - await plugin.resolvePlatformSpecificImplementation() - ?.createNotificationChannel(AndroidNotificationChannel( - kChannelId, - 'Messages', // TODO(i18n) - importance: Importance.high, - enableLights: true, - vibrationPattern: kVibrationPattern, - // TODO(#340) sound - )); + await ZulipBinding.instance.androidNotificationHost.createNotificationChannel(NotificationChannel( + id: kChannelId, + name: 'Messages', // TODO(i18n) + importance: NotificationImportance.high, + lightsEnabled: true, + vibrationPattern: kVibrationPattern, + // TODO(#340) sound + )); } } diff --git a/test/model/binding.dart b/test/model/binding.dart index b1f226b1ae..b73cb25944 100644 --- a/test/model/binding.dart +++ b/test/model/binding.dart @@ -460,21 +460,6 @@ class FakeFlutterLocalNotificationsPlugin extends Fake implements FlutterLocalNo } class FakeAndroidFlutterLocalNotificationsPlugin extends Fake implements AndroidFlutterLocalNotificationsPlugin { - /// Consume the log of calls made to [createNotificationChannel]. - /// - /// This returns a list of the arguments to all calls made - /// to [createNotificationChannel] since the last call to this method. - List takeCreatedChannels() { - final result = _createdChannels; - _createdChannels = []; - return result; - } - List _createdChannels = []; - - @override - Future createNotificationChannel(AndroidNotificationChannel notificationChannel) async { - _createdChannels.add(notificationChannel); - } } class FakeIOSFlutterLocalNotificationsPlugin extends Fake implements IOSFlutterLocalNotificationsPlugin { @@ -492,6 +477,17 @@ class FakeAndroidNotificationHostApi implements AndroidNotificationHostApi { } List _notifyCalls = []; + /// Consume the log of calls made to [createNotificationChannel]. + /// + /// This returns a list of the arguments to all calls made + /// to [createNotificationChannel] since the last call to this method. + List takeCreatedChannels() { + final result = _createdChannels; + _createdChannels = []; + return result; + } + List _createdChannels = []; + @override Future notify({ String? tag, @@ -526,9 +522,8 @@ class FakeAndroidNotificationHostApi implements AndroidNotificationHostApi { } @override - Future createNotificationChannel(NotificationChannel channel) { - // TODO: implement createNotificationChannel - throw UnimplementedError(); + Future createNotificationChannel(NotificationChannel channel) async { + _createdChannels.add(channel); } } diff --git a/test/notifications/display_test.dart b/test/notifications/display_test.dart index b1a7183b87..f05e5da3ed 100644 --- a/test/notifications/display_test.dart +++ b/test/notifications/display_test.dart @@ -27,11 +27,6 @@ import '../test_navigation.dart'; import '../widgets/message_list_checks.dart'; import '../widgets/page_checks.dart'; -FakeAndroidFlutterLocalNotificationsPlugin get notifAndroid => - testBinding.notifications - .resolvePlatformSpecificImplementation() - as FakeAndroidFlutterLocalNotificationsPlugin; - MessageFcmMessage messageFcmMessage( Message zulipMessage, { String? streamName, @@ -87,20 +82,13 @@ void main() { group('NotificationChannelManager', () { test('smoke', () async { await init(); - check(notifAndroid.takeCreatedChannels()).single + check(testBinding.androidNotificationHost.takeCreatedChannels()).single ..id.equals(NotificationChannelManager.kChannelId) ..name.equals('Messages') - ..description.isNull() - ..groupId.isNull() - ..importance.equals(Importance.high) - ..playSound.isTrue() - ..sound.isNull() - ..enableVibration.isTrue() + ..importance.equals(NotificationImportance.high) + ..lightsEnabled.equals(true) ..vibrationPattern.isNotNull().deepEquals( NotificationChannelManager.kVibrationPattern) - ..showBadge.isTrue() - ..enableLights.isTrue() - ..ledColor.isNull() ; }); }); @@ -375,19 +363,12 @@ void main() { }); } -extension AndroidNotificationChannelChecks on Subject { +extension NotificationChannelChecks on Subject { Subject get id => has((x) => x.id, 'id'); - Subject get name => has((x) => x.name, 'name'); - Subject get description => has((x) => x.description, 'description'); - Subject get groupId => has((x) => x.groupId, 'groupId'); - Subject get importance => has((x) => x.importance, 'importance'); - Subject get playSound => has((x) => x.playSound, 'playSound'); - Subject get sound => has((x) => x.sound, 'sound'); - Subject get enableVibration => has((x) => x.enableVibration, 'enableVibration'); - Subject get enableLights => has((x) => x.enableLights, 'enableLights'); + Subject get importance => has((x) => x.importance, 'importance'); + Subject get name => has((x) => x.name, 'name'); + Subject get lightsEnabled => has((x) => x.lightsEnabled, 'lightsEnabled'); Subject get vibrationPattern => has((x) => x.vibrationPattern, 'vibrationPattern'); - Subject get ledColor => has((x) => x.ledColor, 'ledColor'); - Subject get showBadge => has((x) => x.showBadge, 'showBadge'); } extension on Subject {