File tree Expand file tree Collapse file tree 2 files changed +24
-10
lines changed Expand file tree Collapse file tree 2 files changed +24
-10
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 @@ -540,15 +540,13 @@ class FakeAndroidNotificationHostApi implements AndroidNotificationHostApi {
540
540
List <NotificationChannel > _createdChannels = [];
541
541
542
542
@override
543
- Future <List <NotificationChannel ?>> getNotificationChannels () {
544
- // TODO: implement getNotificationChannels
545
- throw UnimplementedError ();
543
+ Future <List <NotificationChannel ?>> getNotificationChannels () async {
544
+ return _createdChannels.toList (growable: false );
546
545
}
547
546
548
547
@override
549
- Future <void > deleteNotificationChannel (String channelId) {
550
- // TODO: implement deleteNotificationChannel
551
- throw UnimplementedError ();
548
+ Future <void > deleteNotificationChannel (String channelId) async {
549
+ _createdChannels.removeWhere ((e) => e.id == channelId);
552
550
}
553
551
554
552
@override
You can’t perform that action at this time.
0 commit comments