@@ -961,19 +961,24 @@ const FirebaseService = {
961961 } ) ;
962962 unsubscribeFunctions . push ( unsubItemFrequency ) ;
963963
964+ console . log ( 'Setting up notifications listener for user:' , AppState . currentUser . uid ) ;
965+
964966 const unsubNotifications = getDb ( ) . collection ( col ( 'notifications' ) )
965967 . where ( 'userId' , '==' , AppState . currentUser . uid )
966968 . where ( 'read' , '==' , false )
967969 . orderBy ( 'timestamp' , 'desc' )
968970 . limit ( 10 )
969971 . onSnapshot ( snapshot => {
972+ console . log ( 'Notifications snapshot received, changes:' , snapshot . docChanges ( ) . length ) ;
970973 snapshot . docChanges ( ) . forEach ( change => {
974+ console . log ( 'Notification change type:' , change . type , change . doc . data ( ) ) ;
971975 if ( change . type === 'added' ) {
972976 const notification = change . doc . data ( ) ;
973977 // Show toast for rate change notifications
974978 if ( notification . type === 'rate_change' ) {
975979 const itemName = notification . itemHindiName || notification . itemName ;
976980 const message = `${ itemName } ${ notification . rateTypeLabel } rate: ₹${ notification . oldRate } → ₹${ notification . newRate } (by ${ notification . changedBy } )` ;
981+ console . log ( 'Showing rate change toast:' , message ) ;
977982 UIManager . showToast ( message , 5000 ) ;
978983
979984 // Mark as read after showing
@@ -985,6 +990,8 @@ const FirebaseService = {
985990 console . error ( 'Notifications listener error:' , error ) ;
986991 } ) ;
987992 unsubscribeFunctions . push ( unsubNotifications ) ;
993+ } else {
994+ console . warn ( 'No currentUser.uid, skipping notifications listener' ) ;
988995 }
989996 } ,
990997
@@ -1079,17 +1086,22 @@ const FirebaseService = {
10791086 read : false
10801087 } ;
10811088
1089+ console . log ( `Notifying ${ userIds . length } users about rate change, excluding current user: ${ AppState . currentUser ?. uid } ` ) ;
1090+
10821091 // Notify all relevant users except the one who made the change
1092+ let notifiedCount = 0 ;
10831093 for ( const userId of userIds ) {
10841094 if ( userId !== AppState . currentUser ?. uid ) {
10851095 await getDb ( ) . collection ( col ( 'notifications' ) ) . add ( {
10861096 ...notification ,
10871097 userId : userId
10881098 } ) ;
1099+ notifiedCount ++ ;
1100+ console . log ( `Notification saved for user: ${ userId } ` ) ;
10891101 }
10901102 }
10911103
1092- console . log ( `Rate change notification sent: ${ item . name } ${ rateType } rate: ₹${ oldRate } → ₹${ newRate } ` ) ;
1104+ console . log ( `Rate change notification sent to ${ notifiedCount } users : ${ item . name } ${ rateType } rate: ₹${ oldRate } → ₹${ newRate } ` ) ;
10931105 } catch ( error ) {
10941106 console . error ( 'Error notifying rate change:' , error ) ;
10951107 }
0 commit comments