fix #231 message history disappears thanks @dylanhoen

// Now that we use data packets for more things, we need to be choosier about what we keep.  Since (currently - in the future less so)
        // we only care about old text messages, we just store those...
pull/234/head
Kevin Hester 2021-02-06 13:24:48 +08:00
rodzic 9c15e22b8f
commit 4a5e07e52f
2 zmienionych plików z 16 dodań i 11 usunięć

Wyświetl plik

@ -805,8 +805,9 @@ class MainActivity : AppCompatActivity(), Logging,
registerMeshReceiver()
// Init our messages table with the service's record of past text messages (ignore all other message types)
val allMsgs = service.oldMessages
val msgs =
service.oldMessages.filter { p -> p.dataType == Portnums.PortNum.TEXT_MESSAGE_APP_VALUE }
allMsgs.filter { p -> p.dataType == Portnums.PortNum.TEXT_MESSAGE_APP_VALUE }
debug("Service provided ${msgs.size} messages and myNodeNum ${service.myNodeInfo?.myNodeNum}")
model.myNodeInfo.value = service.myNodeInfo
model.messagesState.setMessages(msgs)

Wyświetl plik

@ -596,17 +596,21 @@ class MeshService : Service(), Logging {
}
private fun rememberDataPacket(dataPacket: DataPacket) {
// discard old messages if needed then add the new one
while (recentDataPackets.size > 50)
recentDataPackets.removeAt(0)
// Now that we use data packets for more things, we need to be choosier about what we keep. Since (currently - in the future less so)
// we only care about old text messages, we just store those...
if(dataPacket.dataType == Portnums.PortNum.TEXT_MESSAGE_APP_VALUE) {
// discard old messages if needed then add the new one
while (recentDataPackets.size > 50)
recentDataPackets.removeAt(0)
// FIXME - possible kotlin bug in 1.3.72 - it seems that if we start with the (globally shared) emptyList,
// then adding items are affecting that shared list rather than a copy. This was causing aliasing of
// recentDataPackets with messages.value in the GUI. So if the current list is empty we are careful to make a new list
if (recentDataPackets.isEmpty())
recentDataPackets = mutableListOf(dataPacket)
else
recentDataPackets.add(dataPacket)
// FIXME - possible kotlin bug in 1.3.72 - it seems that if we start with the (globally shared) emptyList,
// then adding items are affecting that shared list rather than a copy. This was causing aliasing of
// recentDataPackets with messages.value in the GUI. So if the current list is empty we are careful to make a new list
if (recentDataPackets.isEmpty())
recentDataPackets = mutableListOf(dataPacket)
else
recentDataPackets.add(dataPacket)
}
}
/// Update our model and resend as needed for a MeshPacket we just received from the radio