aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/db
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-03-07 00:12:24 -0500
committerAllan Wang <me@allanwang.ca>2019-03-07 00:12:24 -0500
commit7f1f2247de1d61354adfd2cec011cc475a20f683 (patch)
tree5a4278969812824953845773aacd4c6672d8ad5e /app/src/main/kotlin/com/pitchedapps/frost/db
parentb417cc51b28d558195c4cc075d0e6ce8192bf270 (diff)
downloadfrost-7f1f2247de1d61354adfd2cec011cc475a20f683.tar.gz
frost-7f1f2247de1d61354adfd2cec011cc475a20f683.tar.bz2
frost-7f1f2247de1d61354adfd2cec011cc475a20f683.zip
Migrate to dao and add filter to title
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/db')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/db/NotificationDb.kt26
1 files changed, 14 insertions, 12 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 9622ec47..60ae2ae7 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/db/NotificationDb.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/db/NotificationDb.kt
@@ -136,9 +136,19 @@ suspend fun NotificationDao.selectNotifications(userId: Long, type: String): Lis
_selectNotifications(userId, type).map { it.toNotifContent() }
}
-suspend fun NotificationDao.saveNotifications(type: String, notifs: List<NotificationContent>) {
- withContext(Dispatchers.IO) {
- _saveNotifications(type, notifs)
+/**
+ * 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 withContext(Dispatchers.IO) {
+ try {
+ _saveNotifications(type, notifs)
+ true
+ } catch (e: Exception) {
+ L.e(e) { "Notif save failed" }
+ false
+ }
}
}
@@ -175,12 +185,4 @@ data class NotificationModel(
fun lastNotificationTime(id: Long): NotificationModel =
(select from NotificationModel::class where (NotificationModel_Table.id eq id)).querySingle()
- ?: NotificationModel(id = id)
-
-fun saveNotificationTime(notificationModel: NotificationModel, callback: (() -> Unit)? = null) {
- notificationModel.async save {
- L.d { "Fb notification model saved" }
- L._d { notificationModel }
- callback?.invoke()
- }
-}
+ ?: NotificationModel(id = id) \ No newline at end of file