move DELAYED_BROADCAST logic to service

This commit is contained in:
andrekir
2022-09-03 07:38:36 -03:00
parent 8516eea9c5
commit e90b856524
4 changed files with 5 additions and 13 deletions

View File

@@ -31,7 +31,6 @@ data class DataPacket(
var status: MessageStatus? = MessageStatus.UNKNOWN,
var hopLimit: Int = 0,
var channel: Int = 0, // channel index
var delayed: Int = 0 // S&F MeshProtos.MeshPacket.Delayed.(...)_VALUE
) : Parcelable {
/**
@@ -68,7 +67,6 @@ data class DataPacket(
parcel.readParcelable(MessageStatus::class.java.classLoader),
parcel.readInt(),
parcel.readInt(),
parcel.readInt()
)
override fun equals(other: Any?): Boolean {
@@ -100,7 +98,6 @@ data class DataPacket(
result = 31 * result + status.hashCode()
result = 31 * result + hopLimit
result = 31 * result + channel
result = 31 * result + delayed
return result
}
@@ -114,7 +111,6 @@ data class DataPacket(
parcel.writeParcelable(status, flags)
parcel.writeInt(hopLimit)
parcel.writeInt(channel)
parcel.writeInt(delayed)
}
override fun describeContents(): Int {
@@ -132,7 +128,6 @@ data class DataPacket(
status = parcel.readParcelable(MessageStatus::class.java.classLoader)
hopLimit = parcel.readInt()
channel = parcel.readInt()
delayed = parcel.readInt()
}
companion object CREATOR : Parcelable.Creator<DataPacket> {
@@ -156,8 +151,7 @@ data class DataPacket(
override fun newArray(size: Int): Array<DataPacket?> {
return arrayOfNulls(size)
}
val utf8: Charset = Charset.forName("UTF-8")
}
}

View File

@@ -575,7 +575,8 @@ class MeshService : Service(), Logging {
val data = packet.decoded
val bytes = data.payload.toByteArray()
val fromId = toNodeID(packet.from)
val toId = toNodeID(packet.to)
val delayedBroadcast = packet.delayed.number == 1 // S&F DELAYED_BROADCAST_VALUE == 1
val toId = if (delayedBroadcast) DataPacket.ID_BROADCAST else toNodeID(packet.to)
val hopLimit = packet.hopLimit
// If the rxTime was not set by the device (because device software was old), guess at a time
@@ -600,7 +601,6 @@ class MeshService : Service(), Logging {
bytes = bytes,
hopLimit = hopLimit,
channel = packet.channel,
delayed = packet.delayedValue
)
}
}

View File

@@ -235,8 +235,7 @@ class ContactsFragment : ScreenFragment("Messages"), Logging {
// find messages for each contactId
selectedList.forEach { contactId ->
deleteList += messagesTotal.filter {
if (contactId == DataPacket.ID_BROADCAST)
it.to == DataPacket.ID_BROADCAST || it.delayed == 1 // MeshPacket.Delayed.DELAYED_BROADCAST_VALUE == 1
if (contactId == DataPacket.ID_BROADCAST) it.to == DataPacket.ID_BROADCAST
else it.from == contactId && it.to != DataPacket.ID_BROADCAST || it.from == DataPacket.ID_LOCAL && it.to == contactId
}
}

View File

@@ -225,8 +225,7 @@ class MessagesFragment : Fragment(), Logging {
/// Called when our node DB changes
fun onMessagesChanged(msgIn: Collection<DataPacket>) {
messages = msgIn.filter {
if (contactId == DataPacket.ID_BROADCAST)
it.to == DataPacket.ID_BROADCAST || it.delayed == 1 // MeshPacket.Delayed.DELAYED_BROADCAST_VALUE == 1
if (contactId == DataPacket.ID_BROADCAST) it.to == DataPacket.ID_BROADCAST
else it.from == contactId && it.to != DataPacket.ID_BROADCAST || it.from == DataPacket.ID_LOCAL && it.to == contactId
}.toTypedArray()
notifyDataSetChanged() // FIXME, this is super expensive and redraws all messages