@@ -60,9 +60,25 @@ class ListCustomListCoordinator: Coordinator, Presentable, Presenting {
60
60
61
61
coordinator. didFinish = { [ weak self] editCustomListCoordinator, action, list in
62
62
guard let self else { return }
63
+
63
64
popToList ( )
64
65
editCustomListCoordinator. removeFromParent ( )
65
- self . updateRelayConstraints ( for: action, in: list)
66
+
67
+ var relayConstraints = tunnelManager. settings. relayConstraints
68
+ relayConstraints. entryLocations = self . updateRelayConstraint (
69
+ relayConstraints. entryLocations,
70
+ for: action,
71
+ in: list
72
+ )
73
+ relayConstraints. exitLocations = self . updateRelayConstraint (
74
+ relayConstraints. exitLocations,
75
+ for: action,
76
+ in: list
77
+ )
78
+
79
+ tunnelManager. updateSettings ( [ . relayConstraints( relayConstraints) ] ) { [ weak self] in
80
+ self ? . tunnelManager. reconnectTunnel ( selectNewRelay: true )
81
+ }
66
82
}
67
83
68
84
coordinator. didCancel = { [ weak self] editCustomListCoordinator in
@@ -75,38 +91,39 @@ class ListCustomListCoordinator: Coordinator, Presentable, Presenting {
75
91
addChild ( coordinator)
76
92
}
77
93
78
- private func updateRelayConstraints( for action: EditCustomListCoordinator . FinishAction , in list: CustomList ) {
79
- var relayConstraints = tunnelManager. settings. relayConstraints
94
+ private func updateRelayConstraint(
95
+ _ relayConstraint: RelayConstraint < UserSelectedRelays > ,
96
+ for action: EditCustomListCoordinator . FinishAction ,
97
+ in list: CustomList
98
+ ) -> RelayConstraint < UserSelectedRelays > {
99
+ var relayConstraint = relayConstraint
80
100
81
- guard let customListSelection = relayConstraints . exitLocations . value? . customListSelection,
101
+ guard let customListSelection = relayConstraint . value? . customListSelection,
82
102
customListSelection. listId == list. id
83
- else { return }
103
+ else { return relayConstraint }
84
104
85
105
switch action {
86
106
case . save:
87
- // TODO: - Add entry locations
88
107
if customListSelection. isList {
89
108
let selectedRelays = UserSelectedRelays (
90
109
locations: list. locations,
91
110
customListSelection: UserSelectedRelays . CustomListSelection ( listId: list. id, isList: true )
92
111
)
93
- relayConstraints . exitLocations = . only( selectedRelays)
112
+ relayConstraint = . only( selectedRelays)
94
113
} else {
95
114
let selectedConstraintIsRemovedFromList = list. locations. filter {
96
- relayConstraints . exitLocations . value? . locations. contains ( $0) ?? false
115
+ relayConstraint . value? . locations. contains ( $0) ?? false
97
116
} . isEmpty
98
117
99
118
if selectedConstraintIsRemovedFromList {
100
- relayConstraints . exitLocations = . only( UserSelectedRelays ( locations: [ ] ) )
119
+ relayConstraint = . only( UserSelectedRelays ( locations: [ ] ) )
101
120
}
102
121
}
103
122
case . delete:
104
- relayConstraints . exitLocations = . only( UserSelectedRelays ( locations: [ ] ) )
123
+ relayConstraint = . only( UserSelectedRelays ( locations: [ ] ) )
105
124
}
106
125
107
- tunnelManager. updateSettings ( [ . relayConstraints( relayConstraints) ] ) { [ weak self] in
108
- self ? . tunnelManager. reconnectTunnel ( selectNewRelay: true )
109
- }
126
+ return relayConstraint
110
127
}
111
128
112
129
private func popToList( ) {
0 commit comments