fix: handle deleted channels in ChannelSet DataStore

adds `removeSettings` method to delete channels with `Role.DISABLED`
This commit is contained in:
andrekir 2023-05-06 08:08:17 -03:00
parent feed8262ea
commit 41d0315b63
2 changed files with 26 additions and 24 deletions

View file

@ -963,11 +963,8 @@ class MeshService : Service(), Logging {
}
}
private fun addChannelSettings(ch: ChannelProtos.Channel) {
if (ch.index == 0 || ch.settings.name.lowercase() == "admin") adminChannelIndex = ch.index
serviceScope.handledLaunch {
channelSetRepository.addSettings(ch)
}
private fun updateChannelSettings(ch: ChannelProtos.Channel) = serviceScope.handledLaunch {
adminChannelIndex = channelSetRepository.updateChannelSettings(ch)
}
private fun currentSecond() = (System.currentTimeMillis() / 1000).toInt()
@ -1207,7 +1204,7 @@ class MeshService : Service(), Logging {
ch.toString()
)
insertMeshLog(packetToSave)
if (ch.role != ChannelProtos.Channel.Role.DISABLED) addChannelSettings(ch)
if (ch.role != ChannelProtos.Channel.Role.DISABLED) updateChannelSettings(ch)
}
/**
@ -1407,13 +1404,6 @@ class MeshService : Service(), Logging {
}.forEach(::requestConfig)
}
private fun setChannel(ch: ChannelProtos.Channel) {
if (ch.index == 0 || ch.settings.name.lowercase() == "admin") adminChannelIndex = ch.index
sendToRadio(newMeshPacketTo(myNodeNum).buildAdminPacket(wantResponse = true) {
setChannel = ch
})
}
/**
* Start the modern (REV2) API configuration flow
*/
@ -1725,17 +1715,13 @@ class MeshService : Service(), Logging {
}
override fun setChannel(payload: ByteArray?) = toRemoteExceptions {
with(ChannelProtos.Channel.parseFrom(payload)) {
if (index == 0 || settings.name.lowercase() == "admin") adminChannelIndex = index
}
setRemoteChannel(myNodeNum, payload)
}
override fun setRemoteChannel(destNum: Int, payload: ByteArray?) = toRemoteExceptions {
val channel = ChannelProtos.Channel.parseFrom(payload)
sendToRadio(newMeshPacketTo(destNum).buildAdminPacket(wantResponse = true) {
setChannel = channel
})
sendToRadio(newMeshPacketTo(destNum).buildAdminPacket { setChannel = channel })
if (destNum == myNodeNum) updateChannelSettings(channel) // Update our local copy
}
override fun getRemoteChannel(id: Int, destNum: Int, index: Int) = toRemoteExceptions {