File tree 2 files changed +30
-16
lines changed 2 files changed +30
-16
lines changed Original file line number Diff line number Diff line change @@ -51,11 +51,27 @@ class NotificationChannelManager {
51
51
// settings for the channel -- like "override Do Not Disturb", or "use
52
52
// a different sound", or "don't pop on screen" -- their changes get
53
53
// reset. So this has to be done sparingly.
54
- //
55
- // If we do this, we should also look for any channel with the old
56
- // channel ID and delete it. See zulip-mobile's `createNotificationChannel`
57
- // in android/app/src/main/java/com/zulipmobile/notifications/NotificationChannelManager.kt .
58
54
static Future <void > _ensureChannel () async {
55
+ // See if our current-version channel already exists; delete any obsolete
56
+ // previous channels.
57
+ var found = false ;
58
+ final channels = await _androidHost.getNotificationChannels ();
59
+ for (final channel in channels) {
60
+ assert (channel != null ); // TODO(flutter#97848)
61
+ if (channel! .id == kChannelId) {
62
+ found = true ;
63
+ } else {
64
+ await _androidHost.deleteNotificationChannel (channel.id);
65
+ }
66
+ }
67
+
68
+ if (found) {
69
+ // The channel already exists; nothing to do.
70
+ return ;
71
+ }
72
+
73
+ // The channel doesn't exist. Create it.
74
+
59
75
await _androidHost.createNotificationChannel (NotificationChannel (
60
76
id: kChannelId,
61
77
name: 'Messages' , // TODO(i18n)
Original file line number Diff line number Diff line change @@ -528,18 +528,6 @@ class FakeFlutterLocalNotificationsPlugin extends Fake implements FlutterLocalNo
528
528
}
529
529
530
530
class FakeAndroidNotificationHostApi implements AndroidNotificationHostApi {
531
- @override
532
- Future <List <NotificationChannel ?>> getNotificationChannels () {
533
- // TODO: implement getNotificationChannels
534
- throw UnimplementedError ();
535
- }
536
-
537
- @override
538
- Future <void > deleteNotificationChannel (String channelId) {
539
- // TODO: implement deleteNotificationChannel
540
- throw UnimplementedError ();
541
- }
542
-
543
531
/// Consume the log of calls made to [createNotificationChannel] .
544
532
///
545
533
/// This returns a list of the arguments to all calls made
@@ -551,6 +539,16 @@ class FakeAndroidNotificationHostApi implements AndroidNotificationHostApi {
551
539
}
552
540
List <NotificationChannel > _createdChannels = [];
553
541
542
+ @override
543
+ Future <List <NotificationChannel ?>> getNotificationChannels () async {
544
+ return _createdChannels.toList (growable: false );
545
+ }
546
+
547
+ @override
548
+ Future <void > deleteNotificationChannel (String channelId) async {
549
+ _createdChannels.removeWhere ((e) => e.id == channelId);
550
+ }
551
+
554
552
@override
555
553
Future <void > createNotificationChannel (NotificationChannel channel) async {
556
554
_createdChannels.add (channel);
You can’t perform that action at this time.
0 commit comments