fix: clear data when changing devices (#1985)

This commit is contained in:
James Rich 2025-05-30 13:17:09 -05:00 committed by GitHub
parent ead0c43381
commit 25ecdc912e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 102 additions and 22 deletions

View file

@ -31,6 +31,7 @@ import kotlinx.coroutines.flow.mapLatest
import kotlinx.coroutines.withContext
import javax.inject.Inject
@Suppress("TooManyFunctions")
class MeshLogRepository @Inject constructor(
private val meshLogDaoLazy: dagger.Lazy<MeshLogDao>,
private val dispatchers: CoroutineDispatchers,

View file

@ -111,12 +111,8 @@ class NodeRepository @Inject constructor(
}
suspend fun installNodeDB(mi: MyNodeEntity, nodes: List<NodeEntity>) = withContext(dispatchers.io) {
val isDifferentNode = myNodeInfo.value?.myNodeNum != mi.myNodeNum
nodeInfoDao.clearMyNodeInfo()
nodeInfoDao.setMyNodeInfo(mi) // set MyNodeEntity first
if (isDifferentNode) {
nodeInfoDao.clearNodeInfo()
}
nodeInfoDao.putAll(nodes)
}

View file

@ -107,4 +107,8 @@ class PacketRepository @Inject constructor(private val packetDaoLazy: dagger.Laz
suspend fun insertReaction(reaction: ReactionEntity) = withContext(Dispatchers.IO) {
packetDao.insert(reaction)
}
suspend fun clearPacketDB() = withContext(Dispatchers.IO) {
packetDao.deleteAll()
}
}

View file

@ -214,4 +214,7 @@ interface PacketDao {
@Upsert
suspend fun insert(reaction: ReactionEntity)
@Query("DELETE FROM packet")
suspend fun deleteAll()
}