Skip to content

Commit 1156c71

Browse files
author
Jon Petersson
committed
Review fixes
1 parent f36a43f commit 1156c71

File tree

10 files changed

+155
-130
lines changed

10 files changed

+155
-130
lines changed

ios/MullvadTypes/RelayLocation.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public enum RelayLocation: Codable, Hashable, CustomDebugStringConvertible {
6363
}
6464

6565
/// A list of `RelayLocation` items preceding the given one in the relay tree
66-
public var ascendants: [RelayLocation] {
66+
public var ancestors: [RelayLocation] {
6767
switch self {
6868
case let .hostname(country, city, _):
6969
return [.country(country), .city(country, city)]

ios/MullvadVPN.xcodeproj/project.pbxproj

+4-4
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@
792792
F050AE4C2B70D5A7003F4EDB /* SelectLocationNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = F050AE4B2B70D5A7003F4EDB /* SelectLocationNode.swift */; };
793793
F050AE4E2B70D7F8003F4EDB /* LocationCellViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F050AE4D2B70D7F8003F4EDB /* LocationCellViewModel.swift */; };
794794
F050AE502B70DC4F003F4EDB /* SelectLocationNodeProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = F050AE4F2B70DC4F003F4EDB /* SelectLocationNodeProtocol.swift */; };
795-
F050AE522B70DFC0003F4EDB /* SelectLocationGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = F050AE512B70DFC0003F4EDB /* SelectLocationGroup.swift */; };
795+
F050AE522B70DFC0003F4EDB /* SelectLocationSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = F050AE512B70DFC0003F4EDB /* SelectLocationSection.swift */; };
796796
F050AE5E2B739A73003F4EDB /* LocationDataSourceProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = F050AE5D2B739A73003F4EDB /* LocationDataSourceProtocol.swift */; };
797797
F050AE602B73A41E003F4EDB /* AllLocationDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = F050AE5F2B73A41E003F4EDB /* AllLocationDataSource.swift */; };
798798
F050AE622B74DBAC003F4EDB /* CustomListsDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = F050AE612B74DBAC003F4EDB /* CustomListsDataSource.swift */; };
@@ -1908,7 +1908,7 @@
19081908
F050AE4B2B70D5A7003F4EDB /* SelectLocationNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectLocationNode.swift; sourceTree = "<group>"; };
19091909
F050AE4D2B70D7F8003F4EDB /* LocationCellViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationCellViewModel.swift; sourceTree = "<group>"; };
19101910
F050AE4F2B70DC4F003F4EDB /* SelectLocationNodeProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectLocationNodeProtocol.swift; sourceTree = "<group>"; };
1911-
F050AE512B70DFC0003F4EDB /* SelectLocationGroup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectLocationGroup.swift; sourceTree = "<group>"; };
1911+
F050AE512B70DFC0003F4EDB /* SelectLocationSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectLocationSection.swift; sourceTree = "<group>"; };
19121912
F050AE5D2B739A73003F4EDB /* LocationDataSourceProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationDataSourceProtocol.swift; sourceTree = "<group>"; };
19131913
F050AE5F2B73A41E003F4EDB /* AllLocationDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AllLocationDataSource.swift; sourceTree = "<group>"; };
19141914
F050AE612B74DBAC003F4EDB /* CustomListsDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomListsDataSource.swift; sourceTree = "<group>"; };
@@ -2345,7 +2345,7 @@
23452345
583DA21325FA4B5C00318683 /* LocationDataSource.swift */,
23462346
F050AE5D2B739A73003F4EDB /* LocationDataSourceProtocol.swift */,
23472347
5888AD82227B11080051EB06 /* SelectLocationCell.swift */,
2348-
F050AE512B70DFC0003F4EDB /* SelectLocationGroup.swift */,
2348+
F050AE512B70DFC0003F4EDB /* SelectLocationSection.swift */,
23492349
F050AE4B2B70D5A7003F4EDB /* SelectLocationNode.swift */,
23502350
F050AE4F2B70DC4F003F4EDB /* SelectLocationNodeProtocol.swift */,
23512351
5888AD86227B17950051EB06 /* SelectLocationViewController.swift */,
@@ -5213,7 +5213,7 @@
52135213
586C0D912B03D8A400E7CDD7 /* AccessMethodHeaderFooterReuseIdentifier.swift in Sources */,
52145214
F050AE4C2B70D5A7003F4EDB /* SelectLocationNode.swift in Sources */,
52155215
7A2960F62A963F7500389B82 /* AlertCoordinator.swift in Sources */,
5216-
F050AE522B70DFC0003F4EDB /* SelectLocationGroup.swift in Sources */,
5216+
F050AE522B70DFC0003F4EDB /* SelectLocationSection.swift in Sources */,
52175217
063687BA28EB234F00BE7161 /* PacketTunnelTransport.swift in Sources */,
52185218
A9C342C12ACC37E30045F00E /* TunnelStatusBlockObserver.swift in Sources */,
52195219
587425C12299833500CA2045 /* RootContainerViewController.swift in Sources */,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"pins" : [
3+
{
4+
"identity" : "swift-log",
5+
"kind" : "remoteSourceControl",
6+
"location" : "https://github.com/apple/swift-log.git",
7+
"state" : {
8+
"revision" : "173f567a2dfec11d74588eea82cecea555bdc0bc",
9+
"version" : "1.4.0"
10+
}
11+
},
12+
{
13+
"identity" : "wireguard-apple",
14+
"kind" : "remoteSourceControl",
15+
"location" : "https://github.com/mullvad/wireguard-apple.git",
16+
"state" : {
17+
"revision" : "11a00c20dc03f2751db47e94f585c0778c7bde82"
18+
}
19+
}
20+
],
21+
"version" : 2
22+
}

ios/MullvadVPN/View controllers/SelectLocation/AllLocationDataSource.swift

+34-36
Original file line numberDiff line numberDiff line change
@@ -15,75 +15,73 @@ class AllLocationDataSource: LocationDataSourceProtocol {
1515
private var locationList = [RelayLocation]()
1616

1717
func search(by text: String) -> [RelayLocation] {
18-
if text.isEmpty {
18+
guard !text.isEmpty else {
1919
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+
}
2930

30-
for cityNode in countryNode.children {
31-
cityNode.showsChildren = false
31+
countryNode.children.forEach { cityNode in
32+
cityNode.showsChildren = false
3233

33-
let relaysContainSearchString = cityNode.children
34-
.contains(where: { $0.displayName.fuzzyMatch(text) })
34+
let relaysContainSearchString = cityNode.children
35+
.contains(where: { $0.displayName.fuzzyMatch(text) })
3536

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+
}
4041

41-
filteredLocations.append(cityNode.location)
42-
countryNode.showsChildren = true
42+
filteredLocations.append(cityNode.location)
43+
countryNode.showsChildren = true
4344

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
5048
}
5149
}
5250
}
53-
54-
return filteredLocations
5551
}
52+
53+
return filteredLocations
5654
}
5755

5856
func reload(
59-
_ response: MullvadREST.REST.ServerRelaysResponse,
60-
relays: [MullvadREST.REST.ServerRelay]
57+
_ response: REST.ServerRelaysResponse,
58+
relays: [REST.ServerRelay]
6159
) -> [RelayLocation] {
6260
nodeByLocation.removeAll()
63-
let rootNode = self.makeRootNode(name: SelectLocationGroup.allLocations.description)
61+
let rootNode = self.makeRootNode(name: SelectLocationSection.allLocations.description)
6462

6563
for relay in relays {
6664
guard case let .city(countryCode, cityCode) = RelayLocation(dashSeparatedString: relay.location),
6765
let serverLocation = response.locations[relay.location] else { continue }
6866

6967
let relayLocation = RelayLocation.hostname(countryCode, cityCode, relay.hostname)
7068

71-
for ascendantOrSelf in relayLocation.ascendants + [relayLocation] {
72-
guard !nodeByLocation.keys.contains(ascendantOrSelf) else {
69+
for ancestorOrSelf in relayLocation.ancestors + [relayLocation] {
70+
guard !nodeByLocation.keys.contains(ancestorOrSelf) else {
7371
continue
7472
}
7573

7674
// Maintain the `showsChildren` state when transitioning between relay lists
77-
let wasShowingChildren = nodeByLocation[ascendantOrSelf]?.showsChildren ?? false
75+
let wasShowingChildren = nodeByLocation[ancestorOrSelf]?.showsChildren ?? false
7876

7977
let node = createNode(
8078
root: rootNode,
81-
ascendantOrSelf: ascendantOrSelf,
79+
ancestorOrSelf: ancestorOrSelf,
8280
serverLocation: serverLocation,
8381
relay: relay,
8482
wasShowingChildren: wasShowingChildren
8583
)
86-
nodeByLocation[ascendantOrSelf] = node
84+
nodeByLocation[ancestorOrSelf] = node
8785
}
8886
}
8987

ios/MullvadVPN/View controllers/SelectLocation/CustomListsDataSource.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ class CustomListsDataSource: LocationDataSourceProtocol {
1515
private var locationList = [RelayLocation]()
1616

1717
func search(by text: String) -> [RelayLocation] {
18-
return []
18+
[]
1919
}
2020

2121
func reload(
22-
_ response: MullvadREST.REST.ServerRelaysResponse,
23-
relays: [MullvadREST.REST.ServerRelay]
22+
_ response: REST.ServerRelaysResponse,
23+
relays: [REST.ServerRelay]
2424
) -> [RelayLocation] {
2525
locationList
2626
}

ios/MullvadVPN/View controllers/SelectLocation/LocationCellFactory.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import MullvadTypes
1010
import UIKit
1111

1212
protocol LocationCellEventHandler {
13-
func collapseCell(for item: LocationCellViewModel)
13+
func toggleCell(for item: LocationCellViewModel)
1414
func node(for item: LocationCellViewModel) -> SelectLocationNode?
1515
}
1616

@@ -48,7 +48,7 @@ final class LocationCellFactory: CellFactoryProtocol {
4848
cell.showsCollapseControl = node.isCollapsible
4949
cell.isExpanded = node.showsChildren
5050
cell.didCollapseHandler = { [weak self] _ in
51-
self?.delegate?.collapseCell(for: item)
51+
self?.delegate?.toggleCell(for: item)
5252
}
5353
}
5454
}

ios/MullvadVPN/View controllers/SelectLocation/LocationCellViewModel.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
import MullvadTypes
1010

1111
struct LocationCellViewModel: Hashable {
12-
let group: SelectLocationGroup
12+
let group: SelectLocationSection
1313
let location: RelayLocation
1414
}

0 commit comments

Comments
 (0)