@@ -142,10 +142,8 @@ final class LocationDataSource:
142
142
func setSelectedRelays( _ selectedRelays: RelaySelection ) {
143
143
selectedLocation = mapSelection ( from: selectedRelays. selected)
144
144
145
- if selectedRelays. hasExcludedRelay {
146
- excludedLocation = mapSelection ( from: selectedRelays. excluded)
147
- excludedLocation? . excludedRelayTitle = selectedRelays. excludedTitle
148
- }
145
+ excludedLocation = mapSelection ( from: selectedRelays. excluded)
146
+ excludedLocation? . excludedRelayTitle = selectedRelays. excludedTitle
149
147
150
148
tableView. reloadData ( )
151
149
}
@@ -246,9 +244,24 @@ final class LocationDataSource:
246
244
}
247
245
248
246
override func tableView( _ tableView: UITableView , cellForRowAt indexPath: IndexPath ) -> UITableViewCell {
249
- // swiftlint:disable:next force_cast
250
- let cell = super. tableView ( tableView, cellForRowAt: indexPath) as! LocationCell
247
+ let cell = super. tableView ( tableView, cellForRowAt: indexPath)
248
+ guard let cell = cell as? LocationCell , let item = itemIdentifier ( for: indexPath) else {
249
+ return cell
250
+ }
251
+
251
252
cell. delegate = self
253
+
254
+ if item. shouldExcludeLocation ( excludedLocation) {
255
+ // Only host locations should have an excluded title. Since custom list nodes contain
256
+ // all locations of all child nodes, its first location could possibly be a host.
257
+ // Therefore we need to check for that as well.
258
+ if case . hostname = item. node. locations. first, !( item. node is CustomListLocationNode ) {
259
+ cell. setExcluded ( relayTitle: excludedLocation? . excludedRelayTitle)
260
+ } else {
261
+ cell. setExcluded ( )
262
+ }
263
+ }
264
+
252
265
return cell
253
266
}
254
267
}
@@ -263,14 +276,6 @@ extension LocationDataSource {
263
276
func nodeShouldBeSelected( _ node: LocationNode ) -> Bool {
264
277
false // N/A
265
278
}
266
-
267
- func excludedRelayTitle( _ node: LocationNode ) -> String ? {
268
- if nodeMatchesExcludedLocation ( node) {
269
- excludedLocation? . excludedRelayTitle
270
- } else {
271
- nil
272
- }
273
- }
274
279
}
275
280
276
281
extension LocationDataSource : UITableViewDelegate {
@@ -307,7 +312,7 @@ extension LocationDataSource: UITableViewDelegate {
307
312
308
313
func tableView( _ tableView: UITableView , shouldHighlightRowAt indexPath: IndexPath ) -> Bool {
309
314
guard let item = itemIdentifier ( for: indexPath) else { return false }
310
- return !nodeMatchesExcludedLocation ( item. node ) && item. node. isActive
315
+ return !item. shouldExcludeLocation ( excludedLocation ) && item. node. isActive
311
316
}
312
317
313
318
func tableView( _ tableView: UITableView , indentationLevelForRowAt indexPath: IndexPath ) -> Int {
@@ -360,9 +365,7 @@ extension LocationDataSource: LocationCellDelegate {
360
365
guard let indexPath = tableView. indexPath ( for: cell) ,
361
366
let item = itemIdentifier ( for: indexPath) else { return }
362
367
363
- let items = toggledItems ( for: cell, excludedRelayTitleCallback: { node in
364
- self . excludedRelayTitle ( node)
365
- } )
368
+ let items = toggledItems ( for: cell)
366
369
367
370
updateDataSnapshot ( with: items, reloadExisting: true , completion: {
368
371
self . scroll ( to: item, animated: true )
0 commit comments