@@ -15,52 +15,50 @@ class AllLocationDataSource: LocationDataSourceProtocol {
15
15
private var locationList = [ RelayLocation] ( )
16
16
17
17
func search( by text: String ) -> [ RelayLocation ] {
18
- if text. isEmpty {
18
+ guard ! text. isEmpty else {
19
19
return locationList
20
- } else {
21
- var filteredLocations : [ RelayLocation ] = [ ]
22
- locationList. forEach { location in
23
- guard let countryNode = nodeByLocation [ location] else { return }
24
- countryNode. showsChildren = false
25
-
26
- if text. isEmpty || countryNode. displayName. fuzzyMatch ( text) {
27
- filteredLocations. append ( countryNode. location)
28
- }
20
+ }
21
+
22
+ var filteredLocations : [ RelayLocation ] = [ ]
23
+ locationList. forEach { location in
24
+ guard let countryNode = nodeByLocation [ location] else { return }
25
+ countryNode. showsChildren = false
26
+
27
+ if countryNode. displayName. fuzzyMatch ( text) {
28
+ filteredLocations. append ( countryNode. location)
29
+ }
29
30
30
- for cityNode in countryNode. children {
31
- cityNode. showsChildren = false
31
+ for cityNode in countryNode. children {
32
+ cityNode. showsChildren = false
32
33
33
- let relaysContainSearchString = cityNode. children
34
- . contains ( where: { $0. displayName. fuzzyMatch ( text) } )
34
+ let relaysContainSearchString = cityNode. children
35
+ . contains ( where: { $0. displayName. fuzzyMatch ( text) } )
35
36
36
- if cityNode. displayName. fuzzyMatch ( text) || relaysContainSearchString {
37
- if !filteredLocations. contains ( where : { $0 == countryNode. location } ) {
38
- filteredLocations. append ( countryNode. location)
39
- }
37
+ if cityNode. displayName. fuzzyMatch ( text) || relaysContainSearchString {
38
+ if !filteredLocations. contains ( countryNode. location) {
39
+ filteredLocations. append ( countryNode. location)
40
+ }
40
41
41
- filteredLocations. append ( cityNode. location)
42
- countryNode. showsChildren = true
42
+ filteredLocations. append ( cityNode. location)
43
+ countryNode. showsChildren = true
43
44
44
- if relaysContainSearchString {
45
- cityNode. children. map { $0. location } . forEach {
46
- filteredLocations. append ( $0)
47
- }
48
- cityNode. showsChildren = true
49
- }
45
+ if relaysContainSearchString {
46
+ filteredLocations. append ( contentsOf: cityNode. children. map { $0. location } )
47
+ cityNode. showsChildren = true
50
48
}
51
49
}
52
50
}
53
-
54
- return filteredLocations
55
51
}
52
+
53
+ return filteredLocations
56
54
}
57
55
58
56
func reload(
59
- _ response: MullvadREST . REST . ServerRelaysResponse ,
60
- relays: [ MullvadREST . REST . ServerRelay ]
57
+ _ response: REST . ServerRelaysResponse ,
58
+ relays: [ REST . ServerRelay ]
61
59
) -> [ RelayLocation ] {
62
60
nodeByLocation. removeAll ( )
63
- let rootNode = self . makeRootNode ( name: SelectLocationGroup . allLocations. description)
61
+ let rootNode = self . makeRootNode ( name: SelectLocationSection . allLocations. description)
64
62
65
63
for relay in relays {
66
64
guard case let . city( countryCode, cityCode) = RelayLocation ( dashSeparatedString: relay. location) ,
0 commit comments