sforkowany z mirror/meshtastic-android
feat: get queued packets from database
rodzic
5a07998b73
commit
d23584c283
|
@ -18,6 +18,10 @@ class PacketRepository @Inject constructor(private val packetDaoLazy: dagger.Laz
|
|||
packetDao.getAllPackets()
|
||||
}
|
||||
|
||||
suspend fun getQueuedPackets(): List<DataPacket>? = withContext(Dispatchers.IO) {
|
||||
packetDao.getQueuedPackets()
|
||||
}
|
||||
|
||||
suspend fun insert(packet: Packet) = withContext(Dispatchers.IO) {
|
||||
packetDao.insert(packet)
|
||||
}
|
||||
|
|
|
@ -48,11 +48,15 @@ interface PacketDao {
|
|||
findDataPacket(data)?.let { update(it.copy(data = new)) }
|
||||
}
|
||||
|
||||
@Query("Select data from packet")
|
||||
@Query("Select data from packet order by received_time asc")
|
||||
fun getDataPackets(): List<DataPacket>
|
||||
|
||||
@Transaction
|
||||
fun getDataPacketById(requestId: Int): DataPacket? {
|
||||
return getDataPackets().firstOrNull { it.id == requestId }
|
||||
}
|
||||
|
||||
@Transaction
|
||||
fun getQueuedPackets(): List<DataPacket>? =
|
||||
getDataPackets().filter { it.status in setOf(MessageStatus.ENROUTE, MessageStatus.QUEUED) }
|
||||
}
|
||||
|
|
|
@ -765,12 +765,6 @@ class MeshService : Service(), Logging {
|
|||
}
|
||||
}
|
||||
|
||||
/// If packets arrive before we have our node DB, we delay parsing them until the DB is ready
|
||||
// private val earlyReceivedPackets = mutableListOf<MeshPacket>()
|
||||
|
||||
/// If apps try to send packets when our radio is sleeping, we queue them here instead
|
||||
private val offlineSentPackets = mutableListOf<DataPacket>()
|
||||
|
||||
/// Update our model and resend as needed for a MeshPacket we just received from the radio
|
||||
private fun handleReceivedMeshPacket(packet: MeshPacket) {
|
||||
if (haveNodeDB) {
|
||||
|
@ -792,12 +786,16 @@ class MeshService : Service(), Logging {
|
|||
}
|
||||
|
||||
private fun processQueuedPackets() {
|
||||
offlineSentPackets.forEach { p ->
|
||||
// encapsulate our payload in the proper protobufs and fire it off
|
||||
serviceScope.handledLaunch {
|
||||
packetRepository.get().getQueuedPackets()?.forEach { p ->
|
||||
try {
|
||||
sendNow(p)
|
||||
changeStatus(p, MessageStatus.ENROUTE)
|
||||
} catch (ex: Exception) {
|
||||
errormsg("Error sending queued message:", ex)
|
||||
}
|
||||
}
|
||||
}
|
||||
offlineSentPackets.clear()
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Ładowanie…
Reference in New Issue