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
|
|
@ -525,12 +525,14 @@ class MeshService : Service(), Logging {
|
|||
wantAck: Boolean = false,
|
||||
id: Int = generatePacketId(), // always assign a packet ID if we didn't already have one
|
||||
hopLimit: Int = 0,
|
||||
channel: Int = 0,
|
||||
priority: MeshPacket.Priority = MeshPacket.Priority.UNSET,
|
||||
initFn: MeshProtos.Data.Builder.() -> Unit
|
||||
): MeshPacket {
|
||||
this.wantAck = wantAck
|
||||
this.id = id
|
||||
this.hopLimit = hopLimit
|
||||
this.channel = channel
|
||||
this.priority = priority
|
||||
decoded = MeshProtos.Data.newBuilder().also {
|
||||
initFn(it)
|
||||
|
|
@ -609,7 +611,8 @@ class MeshService : Service(), Logging {
|
|||
return newMeshPacketTo(p.to!!).buildMeshPacket(
|
||||
id = p.id,
|
||||
wantAck = true,
|
||||
hopLimit = p.hopLimit
|
||||
hopLimit = p.hopLimit,
|
||||
channel = p.channel,
|
||||
) {
|
||||
portnumValue = p.dataType
|
||||
payload = ByteString.copyFrom(p.bytes)
|
||||
|
|
@ -622,12 +625,17 @@ class MeshService : Service(), Logging {
|
|||
if (dataPacket.dataType == Portnums.PortNum.WAYPOINT_APP_VALUE
|
||||
|| dataPacket.dataType == Portnums.PortNum.TEXT_MESSAGE_APP_VALUE
|
||||
) {
|
||||
val fromLocal = dataPacket.from == DataPacket.ID_LOCAL
|
||||
val toBroadcast = dataPacket.to == DataPacket.ID_BROADCAST
|
||||
val contactId = if (fromLocal || toBroadcast) dataPacket.to else dataPacket.from
|
||||
|
||||
// contactKey: unique contact key filter (channel)+(nodeId)
|
||||
val contactKey = "${dataPacket.channel}$contactId"
|
||||
|
||||
val packetToSave = Packet(
|
||||
0L, // autoGenerated
|
||||
dataPacket.dataType,
|
||||
if (dataPacket.from == DataPacket.ID_LOCAL || dataPacket.to == DataPacket.ID_BROADCAST) dataPacket.to else dataPacket.from,
|
||||
dataPacket.channel,
|
||||
MessageStatus.RECEIVED,
|
||||
contactKey,
|
||||
System.currentTimeMillis(),
|
||||
dataPacket
|
||||
)
|
||||
|
|
@ -884,7 +892,7 @@ class MeshService : Service(), Logging {
|
|||
offlineSentPackets.forEach { p ->
|
||||
// encapsulate our payload in the proper protobufs and fire it off
|
||||
sendNow(p)
|
||||
serviceBroadcasts.broadcastMessageStatus(p)
|
||||
changeStatus(p, MessageStatus.ENROUTE)
|
||||
}
|
||||
offlineSentPackets.clear()
|
||||
}
|
||||
|
|
@ -893,8 +901,9 @@ class MeshService : Service(), Logging {
|
|||
* Change the status on a data packet and update watchers
|
||||
*/
|
||||
private fun changeStatus(p: DataPacket, m: MessageStatus) {
|
||||
p.status = m
|
||||
serviceBroadcasts.broadcastMessageStatus(p)
|
||||
serviceScope.handledLaunch {
|
||||
packetRepository.get().updateMessageStatus(p, m)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package com.geeksville.mesh.service
|
|||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Parcelable
|
||||
import com.geeksville.mesh.DataPacket
|
||||
import com.geeksville.mesh.NodeInfo
|
||||
|
||||
|
|
@ -38,20 +37,6 @@ class MeshServiceBroadcasts(
|
|||
explicitBroadcast(intent)
|
||||
}
|
||||
|
||||
fun broadcastMessageStatus(p: DataPacket) {
|
||||
if (p.id == 0) {
|
||||
MeshService.debug("Ignoring anonymous packet status")
|
||||
} else {
|
||||
// Do not log, contains PII possibly
|
||||
// MeshService.debug("Broadcasting message status $p")
|
||||
val intent = Intent(MeshService.ACTION_MESSAGE_STATUS).apply {
|
||||
putExtra(EXTRA_PACKET_ID, p.id)
|
||||
putExtra(EXTRA_STATUS, p.status as Parcelable)
|
||||
}
|
||||
explicitBroadcast(intent)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcast our current connection status
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue