File tree 2 files changed +37
-2
lines changed
2 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -53,8 +53,31 @@ class NotificationChannelManager {
53
53
// in android/app/src/main/java/com/zulipmobile/notifications/NotificationChannelManager.kt .
54
54
static Future <void > _ensureChannel () async {
55
55
final plugin = ZulipBinding .instance.notifications;
56
- await plugin.resolvePlatformSpecificImplementation <AndroidFlutterLocalNotificationsPlugin >()
57
- ? .createNotificationChannel (AndroidNotificationChannel (
56
+ final androidPlugin = plugin.resolvePlatformSpecificImplementation <AndroidFlutterLocalNotificationsPlugin >();
57
+ if (androidPlugin == null ) {
58
+ // TODO(log)
59
+ return ;
60
+ }
61
+
62
+ // Delete any older channels.
63
+ var found = false ;
64
+ final channels = await androidPlugin.getNotificationChannels ();
65
+ if (channels != null ) {
66
+ for (final channel in channels) {
67
+ if (channel.id == kChannelId) {
68
+ found = true ;
69
+ } else {
70
+ await androidPlugin.deleteNotificationChannel (channel.id);
71
+ }
72
+ }
73
+ }
74
+ if (found) {
75
+ // The channel already exists, nothing to do.
76
+ return ;
77
+ }
78
+
79
+ // The channel doesn't exists, create it.
80
+ await androidPlugin.createNotificationChannel (AndroidNotificationChannel (
58
81
kChannelId,
59
82
'Messages' , // TODO(i18n)
60
83
importance: Importance .high,
Original file line number Diff line number Diff line change @@ -475,6 +475,18 @@ class FakeAndroidFlutterLocalNotificationsPlugin extends Fake implements Android
475
475
Future <void > createNotificationChannel (AndroidNotificationChannel notificationChannel) async {
476
476
_createdChannels.add (notificationChannel);
477
477
}
478
+
479
+ @override
480
+ Future <List <AndroidNotificationChannel >?> getNotificationChannels () async {
481
+ return _createdChannels;
482
+ }
483
+
484
+ @override
485
+ Future <void > deleteNotificationChannel (String channelId) async {
486
+ _createdChannels.removeWhere ((channel) {
487
+ return channel.id == channelId;
488
+ });
489
+ }
478
490
}
479
491
480
492
class FakeIOSFlutterLocalNotificationsPlugin extends Fake implements IOSFlutterLocalNotificationsPlugin {
You can’t perform that action at this time.
0 commit comments