Renamed RelayInfo to LegacyKind3RelayRWConfiguration

This is a non-functional refactor that makes a struct name more
detailed.

Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
This commit is contained in:
Daniel D’Aquino
2025-02-21 20:53:37 -08:00
parent 09ce3af11e
commit c28ab7a57c
6 changed files with 16 additions and 16 deletions

View File

@@ -63,7 +63,7 @@ func follow_user_event(our_contacts: NostrEvent?, keypair: FullKeypair, follow:
}
func decode_json_relays(_ content: String) -> [RelayURL: RelayInfo]? {
func decode_json_relays(_ content: String) -> [RelayURL: LegacyKind3RelayRWConfiguration]? {
return decode_json(content)
}
@@ -80,7 +80,7 @@ func remove_relay(ev: NostrEvent, current_relays: [RelayDescriptor], keypair: Fu
}
/// Handles the creation of a new `kind:3` contact list based on a previous contact list, with the specified relays
func add_relay(ev: NostrEvent, keypair: FullKeypair, current_relays: [RelayDescriptor], relay: RelayURL, info: RelayRWConfiguration) -> NostrEvent? {
func add_relay(ev: NostrEvent, keypair: FullKeypair, current_relays: [RelayDescriptor], relay: RelayURL, info: LegacyKind3RelayRWConfiguration) -> NostrEvent? {
var relays = ensure_relay_info(relays: current_relays, content: ev.content)
// If kind:3 content is empty, or if the relay doesn't exist in the list,
@@ -98,7 +98,7 @@ func add_relay(ev: NostrEvent, keypair: FullKeypair, current_relays: [RelayDescr
return NostrEvent(content: content, keypair: keypair.to_keypair(), kind: 3, tags: ev.tags.strings())
}
func ensure_relay_info(relays: [RelayDescriptor], content: String) -> [RelayURL: RelayInfo] {
func ensure_relay_info(relays: [RelayDescriptor], content: String) -> [RelayURL: LegacyKind3RelayRWConfiguration] {
return decode_json_relays(content) ?? make_contact_relays(relays)
}
@@ -129,7 +129,7 @@ func follow_with_existing_contacts(keypair: FullKeypair, our_contacts: NostrEven
return NostrEvent(content: our_contacts.content, keypair: keypair.to_keypair(), kind: kind, tags: tags)
}
func make_contact_relays(_ relays: [RelayDescriptor]) -> [RelayURL: RelayInfo] {
func make_contact_relays(_ relays: [RelayDescriptor]) -> [RelayURL: LegacyKind3RelayRWConfiguration] {
return relays.reduce(into: [:]) { acc, relay in
acc[relay.url] = relay.info
}

View File

@@ -957,12 +957,12 @@ func process_contact_event(state: DamusState, ev: NostrEvent) {
}
func load_our_relays(state: DamusState, m_old_ev: NostrEvent?, ev: NostrEvent) {
let bootstrap_dict: [RelayURL: RelayInfo] = [:]
let bootstrap_dict: [RelayURL: LegacyKind3RelayRWConfiguration] = [:]
let old_decoded = m_old_ev.flatMap { decode_json_relays($0.content) } ?? state.bootstrap_relays.reduce(into: bootstrap_dict) { (d, r) in
d[r] = .rw
}
guard let decoded: [RelayURL: RelayInfo] = decode_json_relays(ev.content) else {
guard let decoded: [RelayURL: LegacyKind3RelayRWConfiguration] = decode_json_relays(ev.content) else {
return
}

View File

@@ -10,7 +10,7 @@ import Foundation
class ProfileModel: ObservableObject, Equatable {
@Published var contacts: NostrEvent? = nil
@Published var following: Int = 0
@Published var relays: [RelayURL: RelayInfo]? = nil
@Published var relays: [RelayURL: LegacyKind3RelayRWConfiguration]? = nil
@Published var progress: Int = 0
private let MAX_SHARE_RELAYS = 4

View File

@@ -78,8 +78,8 @@ func make_private_zap_request_event(identity: FullKeypair, enc_key: FullKeypair,
func make_first_contact_event(keypair: Keypair) -> NostrEvent? {
let bootstrap_relays = load_bootstrap_relays(pubkey: keypair.pubkey)
let rw_relay_info = RelayInfo(read: true, write: true)
var relays: [RelayURL: RelayInfo] = [:]
let rw_relay_info = LegacyKind3RelayRWConfiguration(read: true, write: true)
var relays: [RelayURL: LegacyKind3RelayRWConfiguration] = [:]
for relay in bootstrap_relays {
relays[relay] = rw_relay_info

View File

@@ -7,16 +7,16 @@
import Foundation
public struct RelayInfo: Codable {
let read: Bool?
let write: Bool?
public struct LegacyKind3RelayRWConfiguration: Codable, Sendable {
public let read: Bool?
public let write: Bool?
init(read: Bool, write: Bool) {
self.read = read
self.write = write
}
static let rw = RelayInfo(read: true, write: true)
static let rw = LegacyKind3RelayRWConfiguration(read: true, write: true)
}
enum RelayVariant {
@@ -27,10 +27,10 @@ enum RelayVariant {
public struct RelayDescriptor {
let url: RelayURL
let info: RelayInfo
let info: LegacyKind3RelayRWConfiguration
let variant: RelayVariant
init(url: RelayURL, info: RelayInfo, variant: RelayVariant = .regular) {
init(url: RelayURL, info: LegacyKind3RelayRWConfiguration, variant: RelayVariant = .regular) {
self.url = url
self.info = info
self.variant = variant

View File

@@ -88,7 +88,7 @@ struct AddRelayView: View {
return
}
let info = RelayInfo.rw
let info = LegacyKind3RelayRWConfiguration.rw
let descriptor = RelayDescriptor(url: url, info: info)
do {