damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 81f3764e4bdcaf25787832d88019e7567d3afea3
parent 969ec820c9455356dbf0bcf3a3d4628e00122b16
Author: William Casarin <jb55@jb55.com>
Date:   Fri, 23 Dec 2022 08:32:23 -0800

profile: don't overwrite profile info

This will be important for profile editing

Diffstat:
Mdamus/Nostr/Nostr.swift | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 69 insertions(+), 0 deletions(-)

diff --git a/damus/Nostr/Nostr.swift b/damus/Nostr/Nostr.swift @@ -7,7 +7,75 @@ import Foundation +struct Profile: Codable { + var value: [String: String] + + init (name: String?, display_name: String?, about: String?, picture: String?, website: String?, lud06: String?, lud16: String?) { + self.value = [:] + self.name = name + self.display_name = display_name + self.about = about + self.picture = picture + self.website = website + self.lud06 = lud06 + self.lud16 = lud16 + } + + var display_name: String? { + get { return value["display_name"]; } + set(s) { value["display_name"] = s } + } + + var name: String? { + get { return value["name"]; } + set(s) { value["name"] = s } + } + + var about: String? { + get { return value["about"]; } + set(s) { value["about"] = s } + } + + var picture: String? { + get { return value["picture"]; } + set(s) { value["picture"] = s } + } + + var website: String? { + get { return value["website"]; } + set(s) { value["website"] = s } + } + + var lud06: String? { + get { return value["lud06"]; } + set(s) { value["lud06"] = s } + } + + var lud16: String? { + get { return value["lud16"]; } + set(s) { value["lud16"] = s } + } + + var lightning_uri: URL? { + return make_ln_url(self.lud06) ?? make_ln_url(self.lud16) + } + + init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + self.value = try container.decode([String: String].self) + } + + func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(value) + } + + static func displayName(profile: Profile?, pubkey: String) -> String { + return profile?.name ?? abbrev_pubkey(pubkey) + } +} +/* struct Profile: Decodable { let name: String? let display_name: String? @@ -25,6 +93,7 @@ struct Profile: Decodable { return profile?.name ?? abbrev_pubkey(pubkey) } } + */ func make_ln_url(_ str: String?) -> URL? { return str.flatMap { URL(string: "lightning:" + $0) }