From 2f5301a507dc028d03eeeab7f9c6c68c8e0f9578 Mon Sep 17 00:00:00 2001 From: jordyhers Date: Sat, 21 Oct 2023 22:58:18 +0200 Subject: [PATCH] fix(#154): fix issue with multiple notification not sent --- lib/app/features/parent_side/notification_page.dart | 3 ++- lib/services/api_path.dart | 4 ++-- lib/services/database.dart | 6 +++--- lib/services/firestore_service.dart | 12 ++++++++---- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/app/features/parent_side/notification_page.dart b/lib/app/features/parent_side/notification_page.dart index 4ae3823..ed60d70 100644 --- a/lib/app/features/parent_side/notification_page.dart +++ b/lib/app/features/parent_side/notification_page.dart @@ -51,7 +51,8 @@ class _NotificationPageState extends State { Future _delete(BuildContext context, NotificationModel model) async { try { - await widget.database?.deleteNotification(model.id!); + await widget.database + ?.deleteNotification(model.timeStamp!.toIso8601String()); } on FirebaseException catch (e) { await showExceptionAlertDialog( context, diff --git a/lib/services/api_path.dart b/lib/services/api_path.dart index af61430..3279955 100644 --- a/lib/services/api_path.dart +++ b/lib/services/api_path.dart @@ -4,8 +4,8 @@ class APIPath { static String children(String uid) => 'users/$uid/child/'; - static String notifications(String uid, String childId) => - 'users/$uid/notifications/$childId'; + static String notifications(String uid, String timestamp) => + 'users/$uid/notifications/$timestamp'; static String notificationsStream(String uid, String childId) => 'users/$uid/notifications/'; diff --git a/lib/services/database.dart b/lib/services/database.dart index 2d08265..6c36418 100644 --- a/lib/services/database.dart +++ b/lib/services/database.dart @@ -22,7 +22,7 @@ abstract class Database { Future deleteChild(ChildModel model); - Future deleteNotification(String id); + Future deleteNotification(String timestamp); Stream> childrenStream(); @@ -119,8 +119,8 @@ class FireStoreDatabase implements Database { } @override - Future deleteNotification(String id) async { - await _service.deleteData(path: APIPath.notifications(uid, id)); + Future deleteNotification(String timestamp) async { + await _service.deleteData(path: APIPath.notifications(uid, timestamp)); } @override diff --git a/lib/services/firestore_service.dart b/lib/services/firestore_service.dart index 51a2af4..537bdcb 100644 --- a/lib/services/firestore_service.dart +++ b/lib/services/firestore_service.dart @@ -2,7 +2,6 @@ import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:firebase_storage/firebase_storage.dart'; -import 'package:flutter/foundation.dart'; import 'package:times_up_flutter/widgets/show_logger.dart'; typedef QueryBuilder = T Function(Map data); @@ -35,7 +34,9 @@ class FireStoreService { required String path, required Map data, }) async { - final reference = FirebaseFirestore.instance.collection(path).doc(); + final reference = FirebaseFirestore.instance + .collection(path) + .doc(data['timeStamp'] as String); JHLogger.$.d('$path: $data'); await reference.set(data); @@ -78,8 +79,11 @@ class FireStoreService { await reference.delete(); } - debugPrint('delete: $path'); - await reference.delete(); + try { + await reference.delete(); + } catch (e) { + JHLogger.$.e(e); + } } Stream> collectionStream({