Skip to content

Commit 5470762

Browse files
committed
Merge branch 'display-inactive-servers-in-location-list-ios-1291'
2 parents c914681 + fdf59bb commit 5470762

File tree

7 files changed

+67
-16
lines changed

7 files changed

+67
-16
lines changed

ios/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Line wrap the file at 100 chars. Th
2525
### Add
2626
- Add support for additional languages.
2727
- Add recent connections in the Select location view.
28+
- Show disabled servers in location view.
2829

2930
### Changed
3031
- Improve reliability of the bridge API connection method.

ios/MullvadREST/Relay/RelaySelector+Wireguard.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ extension RelaySelector {
1717
by relayConstraint: RelayConstraint<UserSelectedRelays>,
1818
in relays: REST.ServerRelaysResponse,
1919
filterConstraint: RelayConstraint<RelayFilter>,
20-
daitaEnabled: Bool
20+
daitaEnabled: Bool,
21+
includeInactive: Bool = false
2122
) throws -> [RelayWithLocation<REST.ServerRelay>] {
2223
let mappedRelays = RelayWithLocation.locateRelays(
2324
relays: relays.wireguard.relays,
@@ -28,7 +29,8 @@ extension RelaySelector {
2829
relayConstraint,
2930
filterConstraint: filterConstraint,
3031
daitaEnabled: daitaEnabled,
31-
relays: mappedRelays
32+
relays: mappedRelays,
33+
includeInactive: includeInactive
3234
)
3335
}
3436

ios/MullvadREST/Relay/RelaySelector.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ public enum RelaySelector {
6868
_ relayConstraint: RelayConstraint<UserSelectedRelays>,
6969
filterConstraint: RelayConstraint<RelayFilter>,
7070
daitaEnabled: Bool,
71-
relays: [RelayWithLocation<T>]
71+
relays: [RelayWithLocation<T>],
72+
includeInactive: Bool = false
7273
) throws -> [RelayWithLocation<T>] {
7374
// Filter on various settings and constraints.
74-
var filteredRelays = try filterByActive(relays: relays)
75+
var filteredRelays = includeInactive ? relays : try filterByActive(relays: relays)
7576
filteredRelays = try filterByFilterConstraint(relays: filteredRelays, constraint: filterConstraint)
7677
filteredRelays = try filterByLocationConstraint(relays: filteredRelays, constraint: relayConstraint)
7778
filteredRelays = try filterByDaita(relays: filteredRelays, daitaEnabled: daitaEnabled)

ios/MullvadREST/Relay/RelaySelectorWrapper.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public final class RelaySelectorWrapper: RelaySelectorProtocol, Sendable {
4747
}
4848
}
4949

50+
/// This function is expected to be used by the UI to list all available servers, even the inactive ones.
51+
/// For the purposes of creating a relay connection, we should use `selectRelays` instead.
5052
public func findCandidates(tunnelSettings: LatestTunnelSettings) throws -> RelayCandidates {
5153
let relays = try relayCache.read().relays
5254

@@ -64,7 +66,8 @@ public final class RelaySelectorWrapper: RelaySelectorProtocol, Sendable {
6466
by: .any,
6567
in: relays,
6668
filterConstraint: tunnelSettings.relayConstraints.filter,
67-
daitaEnabled: daitaEnabled
69+
daitaEnabled: daitaEnabled,
70+
includeInactive: true
6871
)
6972
}
7073

ios/MullvadVPN/View controllers/SelectLocation/Views/LocationListItem.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,15 @@ struct LocationListItem<ContextMenu>: View where ContextMenu: View {
6565
}
6666
} label: {
6767
HStack {
68-
if !location.isActive {
69-
Image.mullvadRedDot
70-
} else if location.isSelected {
71-
Image.mullvadIconTick
72-
.foregroundStyle(Color.mullvadSuccessColor)
68+
Group {
69+
if !location.isActive {
70+
Image.mullvadRedDot
71+
} else if location.isSelected {
72+
Image.mullvadIconTick
73+
.foregroundStyle(Color.mullvadSuccessColor)
74+
}
7375
}
76+
.frame(width: 24, height: 24)
7477
Text(location.name)
7578
.foregroundStyle(
7679
location.isActive && !location.isExcluded

ios/MullvadVPN/View controllers/SelectLocation/Views/RelayItemView.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ struct RelayItemView: View {
5757
Spacer()
5858
}
5959
.padding(.vertical, subtitle != nil ? 8 : 16)
60-
.padding(.horizontal, CGFloat(16 * (level + 1)))
60+
.padding(.leading, CGFloat(16 * level + 8))
61+
.padding(.trailing, 16)
6162
.background {
6263
Color.colorForLevel(level)
6364
}
@@ -78,12 +79,15 @@ struct RelayItemView: View {
7879

7980
@ViewBuilder
8081
func locationStatusIndicator() -> some View {
81-
if !location.isActive {
82-
Image.mullvadRedDot
83-
} else if location.isSelected {
84-
Image.mullvadIconTick
85-
.foregroundStyle(Color.mullvadSuccessColor)
82+
Group {
83+
if !location.isActive {
84+
Image.mullvadRedDot
85+
} else if location.isSelected {
86+
Image.mullvadIconTick
87+
.foregroundStyle(Color.mullvadSuccessColor)
88+
}
8689
}
90+
.frame(width: 24, height: 24)
8791
}
8892
}
8993

ios/MullvadVPNTests/MullvadREST/Relay/RelaySelectorTests.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,43 @@ class RelaySelectorTests: XCTestCase {
250250
XCTAssertEqual(error?.reason, .noActiveRelaysFound)
251251
}
252252
}
253+
254+
func testInactiveRelaysExcludedByDefault() throws {
255+
let candidates = try RelaySelector.WireGuard.findCandidates(
256+
by: .any,
257+
in: sampleRelays,
258+
filterConstraint: .any,
259+
daitaEnabled: false
260+
)
261+
262+
XCTAssertFalse(candidates.contains { $0.relay.hostname == "us-nyc-wg-302" })
263+
}
264+
265+
func testInactiveRelaysIncludedWhenRequested() throws {
266+
let candidates = try RelaySelector.WireGuard.findCandidates(
267+
by: .any,
268+
in: sampleRelays,
269+
filterConstraint: .any,
270+
daitaEnabled: false,
271+
includeInactive: true
272+
)
273+
274+
XCTAssertTrue(candidates.contains { $0.relay.hostname == "us-nyc-wg-302" })
275+
XCTAssertFalse(candidates.first { $0.relay.hostname == "us-nyc-wg-302" }!.relay.active)
276+
}
277+
278+
func testInactiveRelaysIncludedInAllInactiveSet() throws {
279+
let candidates = try RelaySelector.WireGuard.findCandidates(
280+
by: .any,
281+
in: sampleRelaysNoActive,
282+
filterConstraint: .any,
283+
daitaEnabled: false,
284+
includeInactive: true
285+
)
286+
287+
XCTAssertEqual(candidates.count, 1)
288+
XCTAssertFalse(candidates[0].relay.active)
289+
}
253290
}
254291

255292
extension RelaySelectorTests {

0 commit comments

Comments
 (0)