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 @@ -52,11 +52,27 @@ class NotificationChannelManager {
52
52
// settings for the channel -- like "override Do Not Disturb", or "use
53
53
// a different sound", or "don't pop on screen" -- their changes get
54
54
// reset. So this has to be done sparingly.
55
- //
56
- // If we do this, we should also look for any channel with the old
57
- // channel ID and delete it. See zulip-mobile's `createNotificationChannel`
58
- // in android/app/src/main/java/com/zulipmobile/notifications/NotificationChannelManager.kt .
59
55
static Future <void > _ensureChannel () async {
56
+ // See if our current-version channel already exists; delete any obsolete
57
+ // previous channels.
58
+ var found = false ;
59
+ final channels = await _androidHost.getNotificationChannels ();
60
+ for (final channel in channels) {
61
+ assert (channel != null ); // TODO(flutter#97848)
62
+ if (channel! .id == kChannelId) {
63
+ found = true ;
64
+ } else {
65
+ await _androidHost.deleteNotificationChannel (channel.id);
66
+ }
67
+ }
68
+
69
+ if (found) {
70
+ // The channel already exists; nothing to do.
71
+ return ;
72
+ }
73
+
74
+ // The channel doesn't exist. Create it.
75
+
60
76
await _androidHost.createNotificationChannel (NotificationChannel (
61
77
id: kChannelId,
62
78
name: 'Messages' , // TODO(i18n)
Original file line number Diff line number Diff line change @@ -555,15 +555,13 @@ class FakeAndroidNotificationHostApi implements AndroidNotificationHostApi {
555
555
List <NotificationChannel > _createdChannels = [];
556
556
557
557
@override
558
- Future <List <NotificationChannel ?>> getNotificationChannels () {
559
- // TODO: implement getNotificationChannels
560
- throw UnimplementedError ();
558
+ Future <List <NotificationChannel ?>> getNotificationChannels () async {
559
+ return _createdChannels.toList (growable: false );
561
560
}
562
561
563
562
@override
564
- Future <void > deleteNotificationChannel (String channelId) {
565
- // TODO: implement deleteNotificationChannel
566
- throw UnimplementedError ();
563
+ Future <void > deleteNotificationChannel (String channelId) async {
564
+ _createdChannels.removeWhere ((e) => e.id == channelId);
567
565
}
568
566
569
567
@override
You can’t perform that action at this time.
0 commit comments