Cached relay metadata
This commit is contained in:
@@ -168,6 +168,7 @@
|
|||||||
4CE6DF1227F7A2B300C66700 /* Starscream in Frameworks */ = {isa = PBXBuildFile; productRef = 4CE6DF1127F7A2B300C66700 /* Starscream */; };
|
4CE6DF1227F7A2B300C66700 /* Starscream in Frameworks */ = {isa = PBXBuildFile; productRef = 4CE6DF1127F7A2B300C66700 /* Starscream */; };
|
||||||
4CE6DF1627F8DEBF00C66700 /* RelayConnection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE6DF1527F8DEBF00C66700 /* RelayConnection.swift */; };
|
4CE6DF1627F8DEBF00C66700 /* RelayConnection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE6DF1527F8DEBF00C66700 /* RelayConnection.swift */; };
|
||||||
4CE8794829941DA700F758CC /* RelayFilters.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE8794729941DA700F758CC /* RelayFilters.swift */; };
|
4CE8794829941DA700F758CC /* RelayFilters.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE8794729941DA700F758CC /* RelayFilters.swift */; };
|
||||||
|
4CE8794C2995B59E00F758CC /* RelayMetadatas.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE8794B2995B59E00F758CC /* RelayMetadatas.swift */; };
|
||||||
4CEE2AED2805B22500AB5EEF /* NostrRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2AEC2805B22500AB5EEF /* NostrRequest.swift */; };
|
4CEE2AED2805B22500AB5EEF /* NostrRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2AEC2805B22500AB5EEF /* NostrRequest.swift */; };
|
||||||
4CEE2AF1280B216B00AB5EEF /* EventDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2AF0280B216B00AB5EEF /* EventDetailView.swift */; };
|
4CEE2AF1280B216B00AB5EEF /* EventDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2AF0280B216B00AB5EEF /* EventDetailView.swift */; };
|
||||||
4CEE2AF3280B25C500AB5EEF /* ProfilePicView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2AF2280B25C500AB5EEF /* ProfilePicView.swift */; };
|
4CEE2AF3280B25C500AB5EEF /* ProfilePicView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2AF2280B25C500AB5EEF /* ProfilePicView.swift */; };
|
||||||
@@ -459,6 +460,7 @@
|
|||||||
4CE6DF0327F7A08200C66700 /* damusUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = damusUITestsLaunchTests.swift; sourceTree = "<group>"; };
|
4CE6DF0327F7A08200C66700 /* damusUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = damusUITestsLaunchTests.swift; sourceTree = "<group>"; };
|
||||||
4CE6DF1527F8DEBF00C66700 /* RelayConnection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayConnection.swift; sourceTree = "<group>"; };
|
4CE6DF1527F8DEBF00C66700 /* RelayConnection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayConnection.swift; sourceTree = "<group>"; };
|
||||||
4CE8794729941DA700F758CC /* RelayFilters.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayFilters.swift; sourceTree = "<group>"; };
|
4CE8794729941DA700F758CC /* RelayFilters.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayFilters.swift; sourceTree = "<group>"; };
|
||||||
|
4CE8794B2995B59E00F758CC /* RelayMetadatas.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayMetadatas.swift; sourceTree = "<group>"; };
|
||||||
4CEE2AE72804F57C00AB5EEF /* libsecp256k1.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libsecp256k1.a; sourceTree = "<group>"; };
|
4CEE2AE72804F57C00AB5EEF /* libsecp256k1.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libsecp256k1.a; sourceTree = "<group>"; };
|
||||||
4CEE2AEC2805B22500AB5EEF /* NostrRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NostrRequest.swift; sourceTree = "<group>"; };
|
4CEE2AEC2805B22500AB5EEF /* NostrRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NostrRequest.swift; sourceTree = "<group>"; };
|
||||||
4CEE2AF0280B216B00AB5EEF /* EventDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventDetailView.swift; sourceTree = "<group>"; };
|
4CEE2AF0280B216B00AB5EEF /* EventDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventDetailView.swift; sourceTree = "<group>"; };
|
||||||
@@ -732,6 +734,7 @@
|
|||||||
4C7FF7D628233637009601DB /* Util */ = {
|
4C7FF7D628233637009601DB /* Util */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
4CE879492995B58700F758CC /* Relays */,
|
||||||
4CF0ABEA29844B2F00D66079 /* AnyCodable */,
|
4CF0ABEA29844B2F00D66079 /* AnyCodable */,
|
||||||
4CC7AAE6297EFA7B00430951 /* Zap.swift */,
|
4CC7AAE6297EFA7B00430951 /* Zap.swift */,
|
||||||
4C3A1D322960DB0500558C0F /* Markdown.swift */,
|
4C3A1D322960DB0500558C0F /* Markdown.swift */,
|
||||||
@@ -757,7 +760,6 @@
|
|||||||
4CB883A72975FC1800DC99E7 /* Zaps.swift */,
|
4CB883A72975FC1800DC99E7 /* Zaps.swift */,
|
||||||
4CB883B5297730E400DC99E7 /* LNUrls.swift */,
|
4CB883B5297730E400DC99E7 /* LNUrls.swift */,
|
||||||
3AB72AB8298ECF30004BB58C /* Translator.swift */,
|
3AB72AB8298ECF30004BB58C /* Translator.swift */,
|
||||||
4CE8794729941DA700F758CC /* RelayFilters.swift */,
|
|
||||||
);
|
);
|
||||||
path = Util;
|
path = Util;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@@ -917,6 +919,15 @@
|
|||||||
path = damusUITests;
|
path = damusUITests;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
};
|
};
|
||||||
|
4CE879492995B58700F758CC /* Relays */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
4CE8794729941DA700F758CC /* RelayFilters.swift */,
|
||||||
|
4CE8794B2995B59E00F758CC /* RelayMetadatas.swift */,
|
||||||
|
);
|
||||||
|
path = Relays;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
4CEE2AE62804F57B00AB5EEF /* Frameworks */ = {
|
4CEE2AE62804F57B00AB5EEF /* Frameworks */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
@@ -1129,6 +1140,7 @@
|
|||||||
4C285C86283892E7008A31F1 /* CreateAccountModel.swift in Sources */,
|
4C285C86283892E7008A31F1 /* CreateAccountModel.swift in Sources */,
|
||||||
4C64987C286D03E000EAE2B3 /* DirectMessagesView.swift in Sources */,
|
4C64987C286D03E000EAE2B3 /* DirectMessagesView.swift in Sources */,
|
||||||
7C902AE32981D55B002AB16E /* ZoomableScrollView.swift in Sources */,
|
7C902AE32981D55B002AB16E /* ZoomableScrollView.swift in Sources */,
|
||||||
|
4CE8794C2995B59E00F758CC /* RelayMetadatas.swift in Sources */,
|
||||||
4C363A8C28236B92006E126D /* PubkeyView.swift in Sources */,
|
4C363A8C28236B92006E126D /* PubkeyView.swift in Sources */,
|
||||||
4C5C7E68284ED36500A22DF5 /* SearchHomeModel.swift in Sources */,
|
4C5C7E68284ED36500A22DF5 /* SearchHomeModel.swift in Sources */,
|
||||||
4C75EFB728049D990006080F /* RelayPool.swift in Sources */,
|
4C75EFB728049D990006080F /* RelayPool.swift in Sources */,
|
||||||
|
|||||||
@@ -287,14 +287,17 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Button(action: {
|
// maybe expand this to other timelines in the future
|
||||||
//isFilterVisible.toggle()
|
if selected_timeline == .search {
|
||||||
self.active_sheet = .filter
|
Button(action: {
|
||||||
}) {
|
//isFilterVisible.toggle()
|
||||||
// checklist, checklist.checked, lisdt.bullet, list.bullet.circle, line.3.horizontal.decrease..., line.3.horizontail.decrease
|
self.active_sheet = .filter
|
||||||
Label("Filter", systemImage: "line.3.horizontal.decrease")
|
}) {
|
||||||
.foregroundColor(.gray)
|
// checklist, checklist.checked, lisdt.bullet, list.bullet.circle, line.3.horizontal.decrease..., line.3.horizontail.decrease
|
||||||
//.contentShape(Rectangle())
|
Label("Filter", systemImage: "line.3.horizontal.decrease")
|
||||||
|
.foregroundColor(.gray)
|
||||||
|
//.contentShape(Rectangle())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -585,8 +588,12 @@ struct ContentView: View {
|
|||||||
|
|
||||||
func connect() {
|
func connect() {
|
||||||
let pool = RelayPool()
|
let pool = RelayPool()
|
||||||
|
let metadatas = RelayMetadatas()
|
||||||
|
|
||||||
for relay in BOOTSTRAP_RELAYS {
|
for relay in BOOTSTRAP_RELAYS {
|
||||||
|
if let url = URL(string: relay) {
|
||||||
|
add_new_relay(url: url, info: .rw, metadatas: metadatas, pool: pool)
|
||||||
|
}
|
||||||
add_relay(pool, relay)
|
add_relay(pool, relay)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -603,7 +610,8 @@ struct ContentView: View {
|
|||||||
zaps: Zaps(our_pubkey: pubkey),
|
zaps: Zaps(our_pubkey: pubkey),
|
||||||
lnurls: LNUrls(),
|
lnurls: LNUrls(),
|
||||||
settings: UserSettingsStore(),
|
settings: UserSettingsStore(),
|
||||||
relay_filters: RelayFilters(our_pubkey: pubkey)
|
relay_filters: RelayFilters(our_pubkey: pubkey),
|
||||||
|
relay_metadata: metadatas
|
||||||
)
|
)
|
||||||
home.damus_state = self.damus_state!
|
home.damus_state = self.damus_state!
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ struct DamusState {
|
|||||||
let lnurls: LNUrls
|
let lnurls: LNUrls
|
||||||
let settings: UserSettingsStore
|
let settings: UserSettingsStore
|
||||||
let relay_filters: RelayFilters
|
let relay_filters: RelayFilters
|
||||||
|
let relay_metadata: RelayMetadatas
|
||||||
|
|
||||||
var pubkey: String {
|
var pubkey: String {
|
||||||
return keypair.pubkey
|
return keypair.pubkey
|
||||||
@@ -33,6 +34,6 @@ struct DamusState {
|
|||||||
|
|
||||||
|
|
||||||
static var empty: DamusState {
|
static var empty: DamusState {
|
||||||
return DamusState.init(pool: RelayPool(), keypair: Keypair(pubkey: "", privkey: ""), likes: EventCounter(our_pubkey: ""), boosts: EventCounter(our_pubkey: ""), contacts: Contacts(our_pubkey: ""), tips: TipCounter(our_pubkey: ""), profiles: Profiles(), dms: DirectMessagesModel(our_pubkey: ""), previews: PreviewCache(), zaps: Zaps(our_pubkey: ""), lnurls: LNUrls(), settings: UserSettingsStore(), relay_filters: RelayFilters(our_pubkey: ""))
|
return DamusState.init(pool: RelayPool(), keypair: Keypair(pubkey: "", privkey: ""), likes: EventCounter(our_pubkey: ""), boosts: EventCounter(our_pubkey: ""), contacts: Contacts(our_pubkey: ""), tips: TipCounter(our_pubkey: ""), profiles: Profiles(), dms: DirectMessagesModel(our_pubkey: ""), previews: PreviewCache(), zaps: Zaps(our_pubkey: ""), lnurls: LNUrls(), settings: UserSettingsStore(), relay_filters: RelayFilters(our_pubkey: ""), relay_metadata: RelayMetadatas())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,11 +51,7 @@ class FollowersModel: ObservableObject {
|
|||||||
if has_contact.contains(ev.pubkey) {
|
if has_contact.contains(ev.pubkey) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
process_contact_event(
|
process_contact_event(state: damus_state, ev: ev)
|
||||||
pool: damus_state.pool,
|
|
||||||
contacts: damus_state.contacts,
|
|
||||||
pubkey: damus_state.pubkey, ev: ev
|
|
||||||
)
|
|
||||||
contacts?.append(ev.pubkey)
|
contacts?.append(ev.pubkey)
|
||||||
has_contact.insert(ev.pubkey)
|
has_contact.insert(ev.pubkey)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ class HomeModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handle_contact_event(sub_id: String, relay_id: String, ev: NostrEvent) {
|
func handle_contact_event(sub_id: String, relay_id: String, ev: NostrEvent) {
|
||||||
process_contact_event(pool: damus_state.pool, contacts: damus_state.contacts, pubkey: damus_state.pubkey, ev: ev)
|
process_contact_event(state: self.damus_state, ev: ev)
|
||||||
|
|
||||||
if sub_id == init_subid {
|
if sub_id == init_subid {
|
||||||
pool.send(.unsubscribe(init_subid), to: [relay_id])
|
pool.send(.unsubscribe(init_subid), to: [relay_id])
|
||||||
@@ -643,31 +643,31 @@ func robohash(_ pk: String) -> String {
|
|||||||
return "https://robohash.org/" + pk
|
return "https://robohash.org/" + pk
|
||||||
}
|
}
|
||||||
|
|
||||||
func load_our_stuff(pool: RelayPool, contacts: Contacts, pubkey: String, ev: NostrEvent) {
|
func load_our_stuff(state: DamusState, ev: NostrEvent) {
|
||||||
guard ev.pubkey == pubkey else {
|
guard ev.pubkey == state.pubkey else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// only use new stuff
|
// only use new stuff
|
||||||
if let current_ev = contacts.event {
|
if let current_ev = state.contacts.event {
|
||||||
guard ev.created_at > current_ev.created_at else {
|
guard ev.created_at > current_ev.created_at else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let m_old_ev = contacts.event
|
let m_old_ev = state.contacts.event
|
||||||
contacts.event = ev
|
state.contacts.event = ev
|
||||||
|
|
||||||
load_our_contacts(contacts: contacts, our_pubkey: pubkey, m_old_ev: m_old_ev, ev: ev)
|
load_our_contacts(contacts: state.contacts, our_pubkey: state.pubkey, m_old_ev: m_old_ev, ev: ev)
|
||||||
load_our_relays(contacts: contacts, our_pubkey: pubkey, pool: pool, m_old_ev: m_old_ev, ev: ev)
|
load_our_relays(state: state, m_old_ev: m_old_ev, ev: ev)
|
||||||
}
|
}
|
||||||
|
|
||||||
func process_contact_event(pool: RelayPool, contacts: Contacts, pubkey: String, ev: NostrEvent) {
|
func process_contact_event(state: DamusState, ev: NostrEvent) {
|
||||||
load_our_stuff(pool: pool, contacts: contacts, pubkey: pubkey, ev: ev)
|
load_our_stuff(state: state, ev: ev)
|
||||||
add_contact_if_friend(contacts: contacts, ev: ev)
|
add_contact_if_friend(contacts: state.contacts, ev: ev)
|
||||||
}
|
}
|
||||||
|
|
||||||
func load_our_relays(contacts: Contacts, our_pubkey: String, pool: RelayPool, m_old_ev: NostrEvent?, ev: NostrEvent) {
|
func load_our_relays(state: DamusState, m_old_ev: NostrEvent?, ev: NostrEvent) {
|
||||||
let bootstrap_dict: [String: RelayInfo] = [:]
|
let bootstrap_dict: [String: RelayInfo] = [:]
|
||||||
let old_decoded = m_old_ev.flatMap { decode_json_relays($0.content) } ?? BOOTSTRAP_RELAYS.reduce(into: bootstrap_dict) { (d, r) in
|
let old_decoded = m_old_ev.flatMap { decode_json_relays($0.content) } ?? BOOTSTRAP_RELAYS.reduce(into: bootstrap_dict) { (d, r) in
|
||||||
d[r] = .rw
|
d[r] = .rw
|
||||||
@@ -695,10 +695,10 @@ func load_our_relays(contacts: Contacts, our_pubkey: String, pool: RelayPool, m_
|
|||||||
changed = true
|
changed = true
|
||||||
if new.contains(d) {
|
if new.contains(d) {
|
||||||
if let url = URL(string: d) {
|
if let url = URL(string: d) {
|
||||||
try? pool.add_relay(url, info: decoded[d] ?? .rw)
|
add_new_relay(url: url, info: decoded[d] ?? .rw, metadatas: state.relay_metadata, pool: state.pool)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pool.remove_relay(d)
|
state.pool.remove_relay(d)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -707,6 +707,51 @@ func load_our_relays(contacts: Contacts, our_pubkey: String, pool: RelayPool, m_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func add_new_relay(url: URL, info: RelayInfo, metadatas: RelayMetadatas, pool: RelayPool) {
|
||||||
|
try? pool.add_relay(url, info: info)
|
||||||
|
|
||||||
|
let relay_id = url.absoluteString
|
||||||
|
guard metadatas.lookup(relay_id: relay_id) == nil else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
Task.detached(priority: .background) {
|
||||||
|
guard let meta = try? await fetch_relay_metadata(relay_id: relay_id) else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
metadatas.insert(relay_id: relay_id, metadata: meta)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func fetch_relay_metadata(relay_id: String) async throws -> RelayMetadata? {
|
||||||
|
var urlString = relay_id.replacingOccurrences(of: "wss://", with: "https://")
|
||||||
|
urlString = urlString.replacingOccurrences(of: "ws://", with: "http://")
|
||||||
|
|
||||||
|
guard let url = URL(string: urlString) else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var request = URLRequest(url: url)
|
||||||
|
request.setValue("application/nostr+json", forHTTPHeaderField: "Accept")
|
||||||
|
|
||||||
|
var res: (Data, URLResponse)? = nil
|
||||||
|
|
||||||
|
res = try await URLSession.shared.data(for: request)
|
||||||
|
|
||||||
|
guard let data = res?.0 else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
let nip11 = try JSONDecoder().decode(RelayMetadata.self, from: data)
|
||||||
|
return nip11
|
||||||
|
}
|
||||||
|
|
||||||
|
func process_relay_metadata() {
|
||||||
|
}
|
||||||
|
|
||||||
func handle_incoming_dm(contacts: Contacts, prev_events: NewEventsBits, dms: DirectMessagesModel, our_pubkey: String, ev: NostrEvent) -> NewEventsBits? {
|
func handle_incoming_dm(contacts: Contacts, prev_events: NewEventsBits, dms: DirectMessagesModel, our_pubkey: String, ev: NostrEvent) -> NewEventsBits? {
|
||||||
// hide blocked users
|
// hide blocked users
|
||||||
guard should_show_event(contacts: contacts, ev: ev) else {
|
guard should_show_event(contacts: contacts, ev: ev) else {
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ class ProfileModel: ObservableObject, Equatable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handle_profile_contact_event(_ ev: NostrEvent) {
|
func handle_profile_contact_event(_ ev: NostrEvent) {
|
||||||
process_contact_event(pool: damus.pool, contacts: damus.contacts, pubkey: damus.pubkey, ev: ev)
|
process_contact_event(state: damus, ev: ev)
|
||||||
|
|
||||||
// only use new stuff
|
// only use new stuff
|
||||||
if let current_ev = self.contacts {
|
if let current_ev = self.contacts {
|
||||||
|
|||||||
20
damus/Util/Relays/RelayMetadatas.swift
Normal file
20
damus/Util/Relays/RelayMetadatas.swift
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
//
|
||||||
|
// RelayMetadatas.swift
|
||||||
|
// damus
|
||||||
|
//
|
||||||
|
// Created by William Casarin on 2023-02-09.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
class RelayMetadatas {
|
||||||
|
private var metadata: [String: RelayMetadata] = [:]
|
||||||
|
|
||||||
|
func lookup(relay_id: String) -> RelayMetadata? {
|
||||||
|
return metadata[relay_id]
|
||||||
|
}
|
||||||
|
|
||||||
|
func insert(relay_id: String, metadata: RelayMetadata) {
|
||||||
|
self.metadata[relay_id] = metadata
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -37,7 +37,7 @@ struct RecommendedRelayView: View {
|
|||||||
guard let ev_after_add = add_relay(ev: ev_before_add, privkey: privkey, current_relays: damus.pool.descriptors, relay: relay, info: .rw) else {
|
guard let ev_after_add = add_relay(ev: ev_before_add, privkey: privkey, current_relays: damus.pool.descriptors, relay: relay, info: .rw) else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
process_contact_event(pool: damus.pool, contacts: damus.contacts, pubkey: damus.pubkey, ev: ev_after_add)
|
process_contact_event(state: damus, ev: ev_after_add)
|
||||||
damus.pool.send(.event(ev_after_add))
|
damus.pool.send(.event(ev_after_add))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ struct RelayConfigView: View {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
process_contact_event(pool: state.pool, contacts: state.contacts, pubkey: state.pubkey, ev: ev)
|
process_contact_event(state: state, ev: ev)
|
||||||
|
|
||||||
state.pool.send(.event(new_ev))
|
state.pool.send(.event(new_ev))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,10 +10,9 @@ import SwiftUI
|
|||||||
struct RelayDetailView: View {
|
struct RelayDetailView: View {
|
||||||
let state: DamusState
|
let state: DamusState
|
||||||
let relay: String
|
let relay: String
|
||||||
|
let nip11: RelayMetadata
|
||||||
|
|
||||||
@State private var errorString: String?
|
@State private var errorString: String?
|
||||||
@State private var nip11: RelayMetadata?
|
|
||||||
|
|
||||||
@State var conn_color: Color
|
@State var conn_color: Color
|
||||||
|
|
||||||
@Environment(\.dismiss) var dismiss
|
@Environment(\.dismiss) var dismiss
|
||||||
@@ -69,39 +68,7 @@ struct RelayDetailView: View {
|
|||||||
.onReceive(handle_notify(.switched_timeline)) { notif in
|
.onReceive(handle_notify(.switched_timeline)) { notif in
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
.navigationTitle(nip11?.name ?? "")
|
.navigationTitle(nip11.name ?? "")
|
||||||
.task {
|
|
||||||
var urlString = relay.replacingOccurrences(of: "wss://", with: "https://")
|
|
||||||
urlString = urlString.replacingOccurrences(of: "ws://", with: "http://")
|
|
||||||
|
|
||||||
guard let url = URL(string: urlString) else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var request = URLRequest(url: url)
|
|
||||||
request.setValue("application/nostr+json", forHTTPHeaderField: "Accept")
|
|
||||||
|
|
||||||
var res: (Data, URLResponse)? = nil
|
|
||||||
|
|
||||||
do {
|
|
||||||
res = try await URLSession.shared.data(for: request)
|
|
||||||
} catch {
|
|
||||||
errorString = error.localizedDescription
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
guard let data = res?.0 else {
|
|
||||||
errorString = "Relay not responding to metadata request"
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
do {
|
|
||||||
let nip11 = try JSONDecoder().decode(RelayMetadata.self, from: data)
|
|
||||||
self.nip11 = nip11
|
|
||||||
} catch {
|
|
||||||
errorString = error.localizedDescription
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func nipsList(nips: [Int]) -> AttributedString {
|
private func nipsList(nips: [Int]) -> AttributedString {
|
||||||
@@ -124,6 +91,7 @@ struct RelayDetailView: View {
|
|||||||
|
|
||||||
struct RelayDetailView_Previews: PreviewProvider {
|
struct RelayDetailView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
RelayDetailView(state: test_damus_state(), relay: "wss://nostr.klabo.blog", conn_color: .green)
|
let metadata = RelayMetadata(name: "name", description: "desc", pubkey: "pubkey", contact: "contact", supported_nips: [1,2,3], software: "software", version: "version")
|
||||||
|
RelayDetailView(state: test_damus_state(), relay: "relay", nip11: metadata, conn_color: .green)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,9 +34,13 @@ struct RelayView: View {
|
|||||||
Circle()
|
Circle()
|
||||||
.frame(width: 8.0, height: 8.0)
|
.frame(width: 8.0, height: 8.0)
|
||||||
.foregroundColor(conn_color)
|
.foregroundColor(conn_color)
|
||||||
NavigationLink {
|
if let meta = state.relay_metadata.lookup(relay_id: relay) {
|
||||||
RelayDetailView(state: state, relay: relay, conn_color: conn_color)
|
NavigationLink {
|
||||||
} label: {
|
RelayDetailView(state: state, relay: relay, nip11: meta, conn_color: conn_color)
|
||||||
|
} label: {
|
||||||
|
Text(relay)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
Text(relay)
|
Text(relay)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,7 +83,7 @@ struct RelayView: View {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
process_contact_event(pool: state.pool, contacts: state.contacts, pubkey: state.pubkey, ev: new_ev)
|
process_contact_event(state: state, ev: new_ev)
|
||||||
state.pool.send(.event(new_ev))
|
state.pool.send(.event(new_ev))
|
||||||
} label: {
|
} label: {
|
||||||
Label(NSLocalizedString("Delete", comment: "Button to delete a relay server that the user connects to."), systemImage: "trash")
|
Label(NSLocalizedString("Delete", comment: "Button to delete a relay server that the user connects to."), systemImage: "trash")
|
||||||
|
|||||||
Reference in New Issue
Block a user