This commit implements a new layer called NostrNetworkManager, responsible for managing interactions with the Nostr network, and providing a higher level API that is easier and more secure to use for the layer above it. It also integrates it with the rest of the app, by moving RelayPool and PostBox into NostrNetworkManager, along with all their usages. Changelog-Added: Added NIP-65 relay list support Changelog-Changed: Improved robustness of relay list handling Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
43 lines
1.2 KiB
Swift
43 lines
1.2 KiB
Swift
//
|
|
// UserRelaysView.swift
|
|
// damus
|
|
//
|
|
// Created by William Casarin on 2022-12-29.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct UserRelaysView: View {
|
|
let state: DamusState
|
|
let relays: [RelayURL]
|
|
|
|
@State var relay_state: [(RelayURL, Bool)]
|
|
|
|
init(state: DamusState, relays: [RelayURL]) {
|
|
self.state = state
|
|
self.relays = relays
|
|
let relay_state = UserRelaysView.make_relay_state(state: state, relays: relays)
|
|
self._relay_state = State(initialValue: relay_state)
|
|
}
|
|
|
|
static func make_relay_state(state: DamusState, relays: [RelayURL]) -> [(RelayURL, Bool)] {
|
|
return relays.map({ r in
|
|
return (r, state.nostrNetwork.pool.get_relay(r) == nil)
|
|
}).sorted { (a, b) in a.0 < b.0 }
|
|
}
|
|
|
|
var body: some View {
|
|
List(relay_state, id: \.0) { (r, add) in
|
|
RelayView(state: state, relay: r, showActionButtons: .constant(true), recommended: true)
|
|
}
|
|
.listStyle(PlainListStyle())
|
|
.navigationBarTitle(NSLocalizedString("Relays", comment: "Navigation bar title that shows the list of relays for a user."))
|
|
}
|
|
}
|
|
|
|
struct UserRelaysView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
UserRelaysView(state: test_damus_state, relays: [])
|
|
}
|
|
}
|