From 53e2962f2094f97cec02a80ea694731fa11109e2 Mon Sep 17 00:00:00 2001 From: zin- Date: Fri, 30 Aug 2024 07:49:20 +0900 Subject: [PATCH] drop: on `NotificationClient` wip add: NotificationRepositoryV2 wip add: `KeyWithValueRepositoryV2` wip drop: on `KeyWithValueRepository` wip drop: `RepositoryV2` wip #377 --- .../repository/key_with_value_repository.dart | 6 ++++-- lib/notifications/notification_channels.dart | 4 ++-- lib/notifications/notification_client.dart | 14 +++++--------- lib/notifications/notification_repository.dart | 11 +++++++++++ 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/lib/framework/repository/key_with_value_repository.dart b/lib/framework/repository/key_with_value_repository.dart index d5dd686cc..bf3f0a92b 100644 --- a/lib/framework/repository/key_with_value_repository.dart +++ b/lib/framework/repository/key_with_value_repository.dart @@ -11,9 +11,11 @@ mixin DiscarderByKey, Key, Result> } abstract class KeyWithValueRepositoryV2< - ENTITY extends KeyWithValueV2, - Key> extends Repository { + ENTITY extends KeyWithValueV2, + KEY> extends Repository { Future receive(ENTITY entity); Future discard(int key); + + Future discardAll(); } diff --git a/lib/notifications/notification_channels.dart b/lib/notifications/notification_channels.dart index a1d5cb76c..590983e36 100644 --- a/lib/notifications/notification_channels.dart +++ b/lib/notifications/notification_channels.dart @@ -16,7 +16,7 @@ class NotificationChannels { late final Map actionMap; - Future buildNotification( + Future buildNotification( NotificationType notificationType, int memId, ) => @@ -53,7 +53,7 @@ class NotificationChannels { break; } - return Notification( + return NotificationV2( notificationType.buildNotificationId(memId), title, body, diff --git a/lib/notifications/notification_client.dart b/lib/notifications/notification_client.dart index 640dcfe41..5c1b6ccdd 100644 --- a/lib/notifications/notification_client.dart +++ b/lib/notifications/notification_client.dart @@ -25,7 +25,6 @@ class NotificationClient { final NotificationChannels notificationChannels; final ScheduleClient _scheduleClient; - final NotificationRepository _notificationRepositoryV1; final NotificationRepositoryV2 _notificationRepository; final PreferenceClient _preferenceClient; final MemRepository _memRepository; @@ -34,7 +33,6 @@ class NotificationClient { NotificationClient._( this.notificationChannels, this._scheduleClient, - this._notificationRepositoryV1, this._notificationRepository, this._preferenceClient, this._memRepository, @@ -47,7 +45,6 @@ class NotificationClient { () => _instance ??= NotificationClient._( NotificationChannels(buildL10n(context)), ScheduleClient(), - NotificationRepository(), NotificationRepositoryV2(), PreferenceClient(), MemRepository(), @@ -115,7 +112,7 @@ class NotificationClient { .discard(NotificationType.activeAct.buildNotificationId(memId)); } - await _notificationRepositoryV1.receive( + await _notificationRepository.receive( await notificationChannels.buildNotification( notificationType, memId, @@ -176,7 +173,7 @@ class NotificationClient { Future cancelMemNotifications(int memId) => v( () async { for (var id in AllMemNotificationsId.of(memId)) { - await _notificationRepositoryV1.discard(id); + await _notificationRepository.discard(id); await _scheduleClient.discard(id); } }, @@ -245,10 +242,9 @@ class NotificationClient { Future cancelActNotification(int memId) => v( () async { - await _notificationRepositoryV1 - .discard(activeActNotificationId(memId)); + await _notificationRepository.discard(activeActNotificationId(memId)); - await _notificationRepositoryV1 + await _notificationRepository .discard(afterActStartedNotificationId(memId)); await _scheduleClient.discard(afterActStartedNotificationId(memId)); }, @@ -303,7 +299,7 @@ class NotificationClient { Future resetAll() => v( () async { - await _notificationRepositoryV1.discardAll(); + await _notificationRepository.discardAll(); final allSavedMems = await _memRepository.ship( archived: false, diff --git a/lib/notifications/notification_repository.dart b/lib/notifications/notification_repository.dart index 37c6b269c..0de719cb5 100644 --- a/lib/notifications/notification_repository.dart +++ b/lib/notifications/notification_repository.dart @@ -120,4 +120,15 @@ class NotificationRepositoryV2 'key': key, }, ); + + @override + Future discardAll() => v( + () async { + await _flutterLocalNotificationsWrapper?.cancelAll(); + await _flutterLocalNotificationsWrapper + ?.deleteNotificationChannels(NotificationType.values.map( + (e) => e.buildNotificationChannel().id, + )); + }, + ); }