Skip to content

Commit

Permalink
fix(#154): fix issue with multiple notification not sent
Browse files Browse the repository at this point in the history
  • Loading branch information
JordyHers committed Oct 21, 2023
1 parent 6427841 commit 2f5301a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
3 changes: 2 additions & 1 deletion lib/app/features/parent_side/notification_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class _NotificationPageState extends State<NotificationPage> {

Future<void> _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,
Expand Down
4 changes: 2 additions & 2 deletions lib/services/api_path.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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/';
Expand Down
6 changes: 3 additions & 3 deletions lib/services/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ abstract class Database {

Future<void> deleteChild(ChildModel model);

Future<void> deleteNotification(String id);
Future<void> deleteNotification(String timestamp);

Stream<List<ChildModel>> childrenStream();

Expand Down Expand Up @@ -119,8 +119,8 @@ class FireStoreDatabase implements Database {
}

@override
Future<void> deleteNotification(String id) async {
await _service.deleteData(path: APIPath.notifications(uid, id));
Future<void> deleteNotification(String timestamp) async {
await _service.deleteData(path: APIPath.notifications(uid, timestamp));
}

@override
Expand Down
12 changes: 8 additions & 4 deletions lib/services/firestore_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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> = T Function(Map<String, dynamic> data);
Expand Down Expand Up @@ -35,7 +34,9 @@ class FireStoreService {
required String path,
required Map<String, dynamic> 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);
Expand Down Expand Up @@ -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<List<T>> collectionStream<T>({
Expand Down

0 comments on commit 2f5301a

Please sign in to comment.