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:22:15 -0500
committerAllan Wang <me@allanwang.ca>2019-03-07 00:22:15 -0500
commitcf5fd28ec74069746b49757b6a95a36851a56105 (patch)
treee4eae77f78efb04b166c5821dfba2f6eafc333db /app/src/main/kotlin/com/pitchedapps/frost/db
parente96160d7f7cf45cdb8673928ac9e2fbca63002bd (diff)
downloadfrost-cf5fd28ec74069746b49757b6a95a36851a56105.tar.gz
frost-cf5fd28ec74069746b49757b6a95a36851a56105.tar.bz2
frost-cf5fd28ec74069746b49757b6a95a36851a56105.zip
Move legacy notif model to internal call
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/db')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/db/NotificationDb.kt14
1 files changed, 10 insertions, 4 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 60ae2ae7..7f41fbf8 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/db/NotificationDb.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/db/NotificationDb.kt
@@ -26,6 +26,8 @@ import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Transaction
+import com.pitchedapps.frost.services.NOTIF_CHANNEL_GENERAL
+import com.pitchedapps.frost.services.NOTIF_CHANNEL_MESSAGES
import com.pitchedapps.frost.services.NotificationContent
import com.pitchedapps.frost.utils.L
import com.raizlabs.android.dbflow.annotation.ConflictAction
@@ -33,10 +35,8 @@ import com.raizlabs.android.dbflow.annotation.Database
import com.raizlabs.android.dbflow.annotation.Migration
import com.raizlabs.android.dbflow.annotation.PrimaryKey
import com.raizlabs.android.dbflow.annotation.Table
-import com.raizlabs.android.dbflow.kotlinextensions.async
import com.raizlabs.android.dbflow.kotlinextensions.eq
import com.raizlabs.android.dbflow.kotlinextensions.from
-import com.raizlabs.android.dbflow.kotlinextensions.save
import com.raizlabs.android.dbflow.kotlinextensions.select
import com.raizlabs.android.dbflow.kotlinextensions.where
import com.raizlabs.android.dbflow.sql.SQLiteType
@@ -153,7 +153,13 @@ suspend fun NotificationDao.saveNotifications(type: String, notifs: List<Notific
}
suspend fun NotificationDao.latestEpoch(userId: Long, type: String): Long = withContext(Dispatchers.IO) {
- _selectEpoch(userId, type) ?: -1
+ _selectEpoch(userId, type) ?: lastNotificationTime(userId).let {
+ when (type) {
+ NOTIF_CHANNEL_GENERAL -> it.epoch
+ NOTIF_CHANNEL_MESSAGES -> it.epochIm
+ else -> -1L
+ }
+ }
}
/**
@@ -183,6 +189,6 @@ data class NotificationModel(
var epochIm: Long = -1L
) : BaseModel()
-fun lastNotificationTime(id: Long): NotificationModel =
+private fun lastNotificationTime(id: Long): NotificationModel =
(select from NotificationModel::class where (NotificationModel_Table.id eq id)).querySingle()
?: NotificationModel(id = id) \ No newline at end of file