mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Add a function to find the first missing channel index and use it.
This commit is contained in:
parent
3c623d3441
commit
15ee57f23b
1 changed files with 15 additions and 3 deletions
|
|
@ -98,12 +98,15 @@ struct Channels: View {
|
|||
|
||||
Button {
|
||||
let lastChannel = node?.myInfo?.channels?.lastObject as? ChannelEntity
|
||||
var lastChannelIndex = lastChannel?.index ?? 0
|
||||
|
||||
let channelIndexes = node?.myInfo?.channels?.compactMap({(ch) -> Int in
|
||||
return (ch as AnyObject).index
|
||||
})
|
||||
var firstChannelIndex = firstMissingChannelIndex(channelIndexes ?? [])
|
||||
channelKeySize = 16
|
||||
let key = generateChannelKey(size: channelKeySize)
|
||||
|
||||
channelName = ""
|
||||
channelIndex = Int32(lastChannelIndex + 1)
|
||||
channelIndex = Int32(firstChannelIndex)
|
||||
channelRole = 2
|
||||
channelKey = key
|
||||
uplink = false
|
||||
|
|
@ -365,3 +368,12 @@ struct Channels: View {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func firstMissingChannelIndex(_ indexes: [Int]) -> Int {
|
||||
for element in 1...indexes.count {
|
||||
if !indexes.contains(element) {
|
||||
return element
|
||||
}
|
||||
}
|
||||
return indexes.count + 1
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue