Skip to content

Commit

Permalink
fix: cancel notifications for deleted tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Merrit committed Sep 27, 2023
1 parent c33eff3 commit df7495a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
24 changes: 22 additions & 2 deletions lib/src/tasks/cubit/tasks_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,32 @@ class TasksCubit extends Cubit<TasksState> {
final TaskList? activeList = state.activeList;
if (activeList == null) return;

final updatedLists = state.taskLists.removeTaskList(activeList.id);
final taskLists = [...state.taskLists];

final updatedLists = taskLists.removeTaskList(activeList.id);
emit(state.copyWith(
activeList: null,
activeTask: null,
taskLists: updatedLists,
));
await _tasksRepository.deleteList(id: activeList.id);

try {
await _tasksRepository.deleteList(id: activeList.id);
final tasks = activeList.items;
for (final task in tasks) {
await NotificationsCubit.instance.cancelNotification(task.notificationId);
}
} on Exception catch (e) {
log.e('Failed to delete list', error: e);
emit(state.copyWith(
activeList: activeList,
taskLists: taskLists,
errorMessage: 'Failed to delete list\n\n$e',
));
emit(state.copyWith(
errorMessage: null,
));
}
}

/// Deletes the provided [Task].
Expand Down Expand Up @@ -387,6 +406,7 @@ class TasksCubit extends Cubit<TasksState> {
taskListId: task.taskListId,
taskId: task.id,
);
await NotificationsCubit.instance.cancelNotification(task.notificationId);
} on Exception catch (e) {
log.e('Unable to delete task', error: e);
emit(state.copyWith(
Expand Down
4 changes: 2 additions & 2 deletions lib/src/tasks/repository/src/google_calendar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ class GoogleCalendar implements TasksRepository {
try {
await _api.calendars.delete(id);
} on Exception catch (e) {
log.e('Failed to delete list', error: e);
return false;
log.e('Failed to delete list from Google Calendar', error: e);
rethrow;
}

return true;
Expand Down

0 comments on commit df7495a

Please sign in to comment.