@@ -507,6 +507,32 @@ class FirestoreService {
507507 await _db.collection ('notifications' ).doc (notificationId).update ({'read' : true });
508508 }
509509
510+ Future <void > markNotificationUnread (String notificationId) async {
511+ await _db.collection ('notifications' ).doc (notificationId).update ({'read' : false });
512+ }
513+
514+ Future <void > deleteNotification (String notificationId) async {
515+ await _db.collection ('notifications' ).doc (notificationId).delete ();
516+ }
517+
518+ Future <void > deleteAllNotifications (String userId) async {
519+ final snapshot = await _db.collection ('notifications' ).where ('userId' , isEqualTo: userId).get ();
520+ final batch = _db.batch ();
521+ for (final doc in snapshot.docs) {
522+ batch.delete (doc.reference);
523+ }
524+ await batch.commit ();
525+ }
526+
527+ Future <void > markAllAsUnread (String userId) async {
528+ final snapshot = await _db.collection ('notifications' ).where ('userId' , isEqualTo: userId).get ();
529+ final batch = _db.batch ();
530+ for (final doc in snapshot.docs) {
531+ batch.update (doc.reference, {'read' : false });
532+ }
533+ await batch.commit ();
534+ }
535+
510536 // --- Events ---
511537
512538 Future <void > createEvent (GroupEvent event) async {
@@ -555,19 +581,8 @@ class FirestoreService {
555581
556582 await _db.collection ('events' ).doc (event.id).update (updateData);
557583
558- // Notify members
559- final groupDoc = await _db.collection ('groups' ).doc (event.groupId).get ();
560- if (groupDoc.exists) {
561- final group = Group .fromFirestore (groupDoc);
562- debugPrint ('[FirestoreService] Notifying ${group .members .length } members for event update: ${event .title }' );
563- await NotificationService ().notifyEventUpdated (
564- memberIds: group.members,
565- editorId: editedByUserId,
566- eventId: event.id,
567- eventTitle: event.title,
568- groupId: event.groupId,
569- );
570- }
584+ // NOTE: Notification is handled by add_event_modal.dart with changeSummary
585+ // Do NOT send notification here to avoid duplicates
571586 }
572587
573588 Future <void > deleteEvent (String eventId, String deleterId) async {
@@ -990,7 +1005,7 @@ class FirestoreService {
9901005 final group = Group .fromFirestore (groupDoc);
9911006
9921007 await NotificationService ().notifyInheritanceRequest (
993- adminIds: group.admins, // admins includes owner usually
1008+ adminIds: [... group.admins, group.ownerId], // Include owner explicitly
9941009 requesterId: requesterId,
9951010 requesterName: userName,
9961011 placeholderName: phName,
@@ -1224,8 +1239,12 @@ class FirestoreService {
12241239 await _db.collection ('groups' ).doc (request.groupId).update ({
12251240 'members' : FieldValue .arrayUnion ([request.requesterId]),
12261241 });
1227- // Note: We used to update user's joinedGroupIds here, but Admins can't write to other Users.
1228- // The user must sync their own group list on next app launch.
1242+
1243+ // Force sync the new member's joinedGroupIds immediately
1244+ // This allows them to read other group members' profiles right away
1245+ await _db.collection ('users' ).doc (request.requesterId).update ({
1246+ 'joinedGroupIds' : FieldValue .arrayUnion ([request.groupId]),
1247+ });
12291248
12301249 // Get group name for notification
12311250 final groupDoc = await _db.collection ('groups' ).doc (request.groupId).get ();
0 commit comments