aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-05-10 18:21:13 +0800
committerGitHub <noreply@github.com>2019-05-10 18:21:13 +0800
commit51588778a3fc83a69ef766efb79c7458ec47a039 (patch)
tree18ffb48c3bd45687a97aab92b9301e5e10283859 /app/src/main/kotlin/com
parenta5a19290a876faca91c6c865c50350689f72c080 (diff)
parent971214bd5e2d770d44306dc9ec6ab78182762ba5 (diff)
downloadfrost-51588778a3fc83a69ef766efb79c7458ec47a039.tar.gz
frost-51588778a3fc83a69ef766efb79c7458ec47a039.tar.bz2
frost-51588778a3fc83a69ef766efb79c7458ec47a039.zip
Merge pull request #1420 from AllanWang/fix/notifs
Fix/notifs
Diffstat (limited to 'app/src/main/kotlin/com')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/db/NotificationDb.kt17
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt12
2 files changed, 14 insertions, 15 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/db/NotificationDb.kt b/app/src/main/kotlin/com/pitchedapps/frost/db/NotificationDb.kt
index d4b51c1e..813c39a3 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/db/NotificationDb.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/db/NotificationDb.kt
@@ -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
}
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt
index 1c37bc29..4b0e1a82 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt
@@ -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)