mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
refactor messages to Room database
This commit is contained in:
parent
ab7bf4922b
commit
65e982ddd5
12 changed files with 191 additions and 279 deletions
|
|
@ -5,6 +5,8 @@ import androidx.room.Insert
|
|||
import androidx.room.Update
|
||||
import androidx.room.Query
|
||||
import androidx.room.Transaction
|
||||
import com.geeksville.mesh.DataPacket
|
||||
import com.geeksville.mesh.MessageStatus
|
||||
import com.geeksville.mesh.database.entity.Packet
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
|
|
@ -17,8 +19,17 @@ interface PacketDao {
|
|||
@Insert
|
||||
fun insert(packet: Packet)
|
||||
|
||||
@Query("Delete from packet")
|
||||
fun deleteAll()
|
||||
@Query("Select * from packet where port_num = 1 and contact_key = :contact order by received_time asc")
|
||||
fun getMessagesFrom(contact: String): Flow<List<Packet>>
|
||||
|
||||
@Query("Select * from packet where data = :data")
|
||||
fun findDataPacket(data: DataPacket): Packet
|
||||
|
||||
@Query("Delete from packet where port_num = 1")
|
||||
fun deleteAllMessages()
|
||||
|
||||
@Query("Delete from packet where uuid in (:uuidList)")
|
||||
fun deleteMessages(uuidList: List<Long>)
|
||||
|
||||
@Query("Delete from packet where uuid=:uuid")
|
||||
fun _delete(uuid: Long)
|
||||
|
|
@ -31,4 +42,9 @@ interface PacketDao {
|
|||
@Update
|
||||
fun update(packet: Packet)
|
||||
|
||||
@Transaction
|
||||
fun updateMessageStatus(data: DataPacket, m: MessageStatus) {
|
||||
val new = data.copy(status = m)
|
||||
update(findDataPacket(data).copy(data = new))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue