on-demand: ActivateOnDemandViewModel: Uniquify SSIDs list

And if SSIDs list is empty, fall back to .anySSID option

Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
Roopesh Chander 2019-03-08 11:51:27 +05:30 committed by Jason A. Donenfeld
parent fff75adfe1
commit bd339e2876
1 changed files with 16 additions and 2 deletions

View File

@ -156,9 +156,23 @@ private extension ActivateOnDemandViewModel {
case .anySSID: case .anySSID:
return .anySSID return .anySSID
case .onlySpecificSSIDs: case .onlySpecificSSIDs:
return .onlySpecificSSIDs(selectedSSIDs) let ssids = uniquifiedNonEmptySelectedSSIDs()
return ssids.isEmpty ? .anySSID : .onlySpecificSSIDs(selectedSSIDs)
case .exceptSpecificSSIDs: case .exceptSpecificSSIDs:
return .exceptSpecificSSIDs(selectedSSIDs) let ssids = uniquifiedNonEmptySelectedSSIDs()
return ssids.isEmpty ? .anySSID : .exceptSpecificSSIDs(selectedSSIDs)
} }
} }
func uniquifiedNonEmptySelectedSSIDs() -> [String] {
let nonEmptySSIDs = selectedSSIDs.filter { !$0.isEmpty }
var seenSSIDs = Set<String>()
var uniquified = [String]()
for ssid in nonEmptySSIDs {
guard !seenSSIDs.contains(ssid) else { continue }
uniquified.append(ssid)
seenSSIDs.insert(ssid)
}
return uniquified
}
} }