chore: check local subs

This commit is contained in:
lisonge 2024-06-12 21:57:58 +08:00
parent 6dbf68011f
commit e8a93e644c

View File

@ -23,21 +23,22 @@ import li.songe.gkd.util.updateSubscription
class MainViewModel : ViewModel() {
init {
val localSubsItem = SubsItem(
id = LOCAL_SUBS_ID, order = -2, mtime = System.currentTimeMillis()
)
viewModelScope.launchTry(Dispatchers.IO) {
val subsItems = DbSet.subsItemDao.queryAll()
if (!subsItems.any { s -> s.id == localSubsItem.id }) {
if (!subsItems.any { s -> s.id == LOCAL_SUBS_ID }) {
updateSubscription(
RawSubscription(
id = localSubsItem.id,
id = LOCAL_SUBS_ID,
name = "本地订阅",
version = 0
)
)
DbSet.subsItemDao.insert(localSubsItem)
DbSet.subsItemDao.insert(
SubsItem(
id = LOCAL_SUBS_ID,
order = subsItems.minByOrNull { it.order }?.order ?: 0,
)
)
}
}