Disable notification listeners firing on app startup

This commit is contained in:
Julia Friesel
2018-10-15 08:18:06 +02:00
parent de4d39557e
commit dca286a1d6
+9 -3
View File
@@ -40,14 +40,16 @@ export default function setupNotifications(navigate) {
repeatType: 'day'
})
}
})
}, false)
periodReminderObservable(reminder => {
Notification.cancelLocalNotifications({id: '2'})
if (reminder.enabled) setupPeriodReminder()
})
}, false)
getBleedingDaysSortedByDate().addListener(() => {
getBleedingDaysSortedByDate().addListener((_, changes) => {
// the listener fires on setup, so we check if there were actually any changes
if (nothingChanged(changes)) return
Notification.cancelLocalNotifications({id: '2'})
if (periodReminderObservable.value.enabled) setupPeriodReminder()
})
@@ -77,4 +79,8 @@ function setupPeriodReminder() {
})
}
}
}
function nothingChanged(dbChanges) {
return Object.values(dbChanges).every(changeArray => changeArray.length === 0)
}