1
0
mirror of https://github.com/AllanWang/Frost-for-Facebook.git synced 2024-11-10 04:52:38 +01: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 * Returns true if successful, given that there are constraints to the insertion
*/ */
suspend fun NotificationDao.saveNotifications(type: String, notifs: List<NotificationContent>): Boolean { suspend fun NotificationDao.saveNotifications(type: String, notifs: List<NotificationContent>): Boolean = dao {
if (notifs.isEmpty()) return true try {
return dao { _saveNotifications(type, notifs)
try { true
_saveNotifications(type, notifs) } catch (e: Exception) {
true L.e(e) { "Notif save failed for $type" }
} catch (e: Exception) { false
L.e(e) { "Notif save failed for $type" }
false
}
} }
} }

View File

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