Skip to content

Commit

Permalink
drop: on NotificationClient
Browse files Browse the repository at this point in the history
wip add: NotificationRepositoryV2
wip add: `KeyWithValueRepositoryV2`
wip drop: on `KeyWithValueRepository`
wip drop: `RepositoryV2`

wip #377
  • Loading branch information
zin- committed Aug 29, 2024
1 parent 0a20c4c commit 53e2962
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
6 changes: 4 additions & 2 deletions lib/framework/repository/key_with_value_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ mixin DiscarderByKey<E extends KeyWithValue<Key, dynamic>, Key, Result>
}

abstract class KeyWithValueRepositoryV2<
ENTITY extends KeyWithValueV2<Key, dynamic>,
Key> extends Repository<ENTITY> {
ENTITY extends KeyWithValueV2<KEY, dynamic>,
KEY> extends Repository<ENTITY> {
Future<void> receive(ENTITY entity);

Future<void> discard(int key);

Future<void> discardAll();
}
4 changes: 2 additions & 2 deletions lib/notifications/notification_channels.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class NotificationChannels {

late final Map<String, NotificationAction> actionMap;

Future<Notification> buildNotification(
Future<NotificationV2> buildNotification(
NotificationType notificationType,
int memId,
) =>
Expand Down Expand Up @@ -53,7 +53,7 @@ class NotificationChannels {
break;
}

return Notification(
return NotificationV2(
notificationType.buildNotificationId(memId),
title,
body,
Expand Down
14 changes: 5 additions & 9 deletions lib/notifications/notification_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class NotificationClient {
final NotificationChannels notificationChannels;

final ScheduleClient _scheduleClient;
final NotificationRepository _notificationRepositoryV1;
final NotificationRepositoryV2 _notificationRepository;
final PreferenceClient _preferenceClient;
final MemRepository _memRepository;
Expand All @@ -34,7 +33,6 @@ class NotificationClient {
NotificationClient._(
this.notificationChannels,
this._scheduleClient,
this._notificationRepositoryV1,
this._notificationRepository,
this._preferenceClient,
this._memRepository,
Expand All @@ -47,7 +45,6 @@ class NotificationClient {
() => _instance ??= NotificationClient._(
NotificationChannels(buildL10n(context)),
ScheduleClient(),
NotificationRepository(),
NotificationRepositoryV2(),
PreferenceClient(),
MemRepository(),
Expand Down Expand Up @@ -115,7 +112,7 @@ class NotificationClient {
.discard(NotificationType.activeAct.buildNotificationId(memId));
}

await _notificationRepositoryV1.receive(
await _notificationRepository.receive(
await notificationChannels.buildNotification(
notificationType,
memId,
Expand Down Expand Up @@ -176,7 +173,7 @@ class NotificationClient {
Future<void> cancelMemNotifications(int memId) => v(
() async {
for (var id in AllMemNotificationsId.of(memId)) {
await _notificationRepositoryV1.discard(id);
await _notificationRepository.discard(id);
await _scheduleClient.discard(id);
}
},
Expand Down Expand Up @@ -245,10 +242,9 @@ class NotificationClient {

Future<void> 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));
},
Expand Down Expand Up @@ -303,7 +299,7 @@ class NotificationClient {

Future<void> resetAll() => v(
() async {
await _notificationRepositoryV1.discardAll();
await _notificationRepository.discardAll();

final allSavedMems = await _memRepository.ship(
archived: false,
Expand Down
11 changes: 11 additions & 0 deletions lib/notifications/notification_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,15 @@ class NotificationRepositoryV2
'key': key,
},
);

@override
Future<void> discardAll() => v(
() async {
await _flutterLocalNotificationsWrapper?.cancelAll();
await _flutterLocalNotificationsWrapper
?.deleteNotificationChannels(NotificationType.values.map(
(e) => e.buildNotificationChannel().id,
));
},
);
}

0 comments on commit 53e2962

Please sign in to comment.