1
0
mirror of https://github.com/AllanWang/Frost-for-Facebook.git synced 2024-09-19 23:21:34 +02:00

Ensure notifications are always saved

This commit is contained in:
Allan Wang 2019-05-09 20:15:04 +08:00
parent a5a19290a8
commit 971214bd5e
No known key found for this signature in database
GPG Key ID: C93E3F9C679D7A56
2 changed files with 14 additions and 15 deletions

View File

@ -147,16 +147,13 @@ suspend fun NotificationDao.selectNotifications(userId: Long, type: String): Lis
/**
* Returns true if successful, given that there are constraints to the insertion
*/
suspend fun NotificationDao.saveNotifications(type: String, notifs: List<NotificationContent>): Boolean {
if (notifs.isEmpty()) return true
return dao {
try {
_saveNotifications(type, notifs)
true
} catch (e: Exception) {
L.e(e) { "Notif save failed for $type" }
false
}
suspend fun NotificationDao.saveNotifications(type: String, notifs: List<NotificationContent>): Boolean = dao {
try {
_saveNotifications(type, notifs)
true
} catch (e: Exception) {
L.e(e) { "Notif save failed for $type" }
false
}
}

View File

@ -137,10 +137,17 @@ enum class NotificationType(
validText(notif.title) && validText(notif.text)
}
if (notifContents.isEmpty()) return 0
val userId = data.id
// Legacy, remove with dbflow
val prevLatestEpoch = notifDao.latestEpoch(userId, channelId)
L.v { "Notif $name prev epoch $prevLatestEpoch" }
if (!notifDao.saveNotifications(channelId, notifContents)) {
L.d { "Skip notifs for $name as saving failed" }
return -1
}
if (prevLatestEpoch == -1L && !BuildConfig.DEBUG) {
L.d { "Skipping first notification fetch" }
return 0 // do not notify the first time
@ -155,11 +162,6 @@ enum class NotificationType(
L.d { "${newNotifContents.size} new notifs found for $name" }
if (!notifDao.saveNotifications(channelId, newNotifContents)) {
L.d { "Skip notifs for $name as saving failed" }
return 0
}
val notifs = newNotifContents.map { createNotification(context, it) }
frostEvent("Notifications", "Type" to name, "Count" to notifs.size)