User relays view
Changelog-Added: Added relay list to user profiles
This commit is contained in:
@@ -110,6 +110,7 @@
|
||||
4CACA9D5280C31E100D9BBE8 /* ReplyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CACA9D4280C31E100D9BBE8 /* ReplyView.swift */; };
|
||||
4CACA9DC280C38C000D9BBE8 /* Profiles.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CACA9DB280C38C000D9BBE8 /* Profiles.swift */; };
|
||||
4CB55EF3295E5D59007FD187 /* RecommendedRelayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CB55EF2295E5D59007FD187 /* RecommendedRelayView.swift */; };
|
||||
4CB55EF5295E679D007FD187 /* UserRelaysView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CB55EF4295E679D007FD187 /* UserRelaysView.swift */; };
|
||||
4CD7641B28A1641400B6928F /* EndBlock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CD7641A28A1641400B6928F /* EndBlock.swift */; };
|
||||
4CE4F8CD281352B30009DFBB /* Notifications.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE4F8CC281352B30009DFBB /* Notifications.swift */; };
|
||||
4CE4F9DE2852768D00C00DD9 /* ConfigView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE4F9DD2852768D00C00DD9 /* ConfigView.swift */; };
|
||||
@@ -290,6 +291,7 @@
|
||||
4CACA9D4280C31E100D9BBE8 /* ReplyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReplyView.swift; sourceTree = "<group>"; };
|
||||
4CACA9DB280C38C000D9BBE8 /* Profiles.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Profiles.swift; sourceTree = "<group>"; };
|
||||
4CB55EF2295E5D59007FD187 /* RecommendedRelayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecommendedRelayView.swift; sourceTree = "<group>"; };
|
||||
4CB55EF4295E679D007FD187 /* UserRelaysView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserRelaysView.swift; sourceTree = "<group>"; };
|
||||
4CD7641A28A1641400B6928F /* EndBlock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EndBlock.swift; sourceTree = "<group>"; };
|
||||
4CE4F8CC281352B30009DFBB /* Notifications.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notifications.swift; sourceTree = "<group>"; };
|
||||
4CE4F9DD2852768D00C00DD9 /* ConfigView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigView.swift; sourceTree = "<group>"; };
|
||||
@@ -489,6 +491,7 @@
|
||||
BAB68BEC29543FA3007BA466 /* SelectWalletView.swift */,
|
||||
E9E4ED0A295867B900DD7078 /* ThreadV2View.swift */,
|
||||
4CB55EF2295E5D59007FD187 /* RecommendedRelayView.swift */,
|
||||
4CB55EF4295E679D007FD187 /* UserRelaysView.swift */,
|
||||
);
|
||||
path = Views;
|
||||
sourceTree = "<group>";
|
||||
@@ -781,6 +784,7 @@
|
||||
4CE6DEE927F7A08100C66700 /* ContentView.swift in Sources */,
|
||||
4CEE2AF5280B29E600AB5EEF /* TimeAgo.swift in Sources */,
|
||||
4C75EFAD28049CFB0006080F /* PostButton.swift in Sources */,
|
||||
4CB55EF5295E679D007FD187 /* UserRelaysView.swift in Sources */,
|
||||
4C363AA228296A7E006E126D /* SearchView.swift in Sources */,
|
||||
4C285C8A2838B985008A31F1 /* ProfilePictureSelector.swift in Sources */,
|
||||
4C75EFB92804A2740006080F /* EventView.swift in Sources */,
|
||||
@@ -1043,7 +1047,7 @@
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CODE_SIGN_ENTITLEMENTS = damus/damus.entitlements;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 8;
|
||||
CURRENT_PROJECT_VERSION = 9;
|
||||
DEVELOPMENT_ASSET_PATHS = "\"damus/Preview Content\"";
|
||||
DEVELOPMENT_TEAM = XK7H4JAB3D;
|
||||
ENABLE_PREVIEWS = YES;
|
||||
@@ -1082,7 +1086,7 @@
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CODE_SIGN_ENTITLEMENTS = damus/damus.entitlements;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 8;
|
||||
CURRENT_PROJECT_VERSION = 9;
|
||||
DEVELOPMENT_ASSET_PATHS = "\"damus/Preview Content\"";
|
||||
DEVELOPMENT_TEAM = XK7H4JAB3D;
|
||||
ENABLE_PREVIEWS = YES;
|
||||
|
||||
@@ -11,6 +11,7 @@ class ProfileModel: ObservableObject, Equatable {
|
||||
@Published var events: [NostrEvent] = []
|
||||
@Published var contacts: NostrEvent? = nil
|
||||
@Published var following: Int = 0
|
||||
@Published var relays: [String: RelayInfo]? = nil
|
||||
|
||||
let pubkey: String
|
||||
let damus: DamusState
|
||||
@@ -71,6 +72,7 @@ class ProfileModel: ObservableObject, Equatable {
|
||||
func handle_profile_contact_event(_ ev: NostrEvent) {
|
||||
self.contacts = ev
|
||||
self.following = count_pubkeys(ev.tags)
|
||||
self.relays = decode_json_relays(ev.content)
|
||||
if damus.contacts.is_friend(ev.pubkey) {
|
||||
self.damus.contacts.add_friend_contact(ev)
|
||||
}
|
||||
|
||||
@@ -240,6 +240,17 @@ struct ProfileView: View {
|
||||
followers.subscribe()
|
||||
}
|
||||
}
|
||||
|
||||
if let relays = profile.relays {
|
||||
NavigationLink(destination: UserRelaysView(state: damus_state, pubkey: profile.pubkey, relays: Array(relays.keys).sorted())) {
|
||||
Text("\(relays.keys.count)")
|
||||
.font(.subheadline.weight(.medium))
|
||||
Text("Relays")
|
||||
.font(.subheadline)
|
||||
.foregroundColor(.gray)
|
||||
}
|
||||
.buttonStyle(PlainButtonStyle())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,12 +10,25 @@ import SwiftUI
|
||||
struct RecommendedRelayView: View {
|
||||
let damus: DamusState
|
||||
let relay: String
|
||||
let add_button: Bool
|
||||
|
||||
init(damus: DamusState, relay: String) {
|
||||
self.damus = damus
|
||||
self.relay = relay
|
||||
self.add_button = true
|
||||
}
|
||||
|
||||
init(damus: DamusState, relay: String, add_button: Bool) {
|
||||
self.damus = damus
|
||||
self.relay = relay
|
||||
self.add_button = add_button
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
Text(relay)
|
||||
Spacer()
|
||||
if let ev = damus.contacts.event {
|
||||
if let ev = damus.contacts.event, add_button {
|
||||
if let privkey = damus.keypair.privkey {
|
||||
Button("Add") {
|
||||
guard let ev = add_relay(ev: ev, privkey: privkey, current_relays: damus.pool.descriptors, relay: relay, info: .rw) else {
|
||||
|
||||
46
damus/Views/UserRelaysView.swift
Normal file
46
damus/Views/UserRelaysView.swift
Normal file
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// UserRelaysView.swift
|
||||
// damus
|
||||
//
|
||||
// Created by William Casarin on 2022-12-29.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct UserRelaysView: View {
|
||||
let state: DamusState
|
||||
let pubkey: String
|
||||
let relays: [String]
|
||||
|
||||
@State var relay_state: [(String, Bool)]
|
||||
|
||||
init (state: DamusState, pubkey: String, relays: [String]) {
|
||||
self.state = state
|
||||
self.pubkey = pubkey
|
||||
self.relays = relays
|
||||
let relay_state = UserRelaysView.make_relay_state(pool: state.pool, relays: relays)
|
||||
self._relay_state = State(initialValue: relay_state)
|
||||
}
|
||||
|
||||
static func make_relay_state(pool: RelayPool, relays: [String]) -> [(String, Bool)] {
|
||||
return relays.map({ r in
|
||||
return (r, 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
|
||||
RecommendedRelayView(damus: state, relay: r, add_button: add)
|
||||
}
|
||||
.onReceive(handle_notify(.relays_changed)) { _ in
|
||||
self.relay_state = UserRelaysView.make_relay_state(pool: state.pool, relays: self.relays)
|
||||
}
|
||||
.navigationBarTitle("Relays")
|
||||
}
|
||||
}
|
||||
|
||||
struct UserRelaysView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
UserRelaysView(state: test_damus_state(), pubkey: "", relays: [])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user