From 969ec820c9455356dbf0bcf3a3d4628e00122b16 Mon Sep 17 00:00:00 2001 From: Artyom Kazak Date: Thu, 22 Dec 2022 23:37:08 +0100 Subject: [PATCH 1/3] Better post editor placeholder --- damus/Views/PostView.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/damus/Views/PostView.swift b/damus/Views/PostView.swift index bc14d928..df75aeb8 100644 --- a/damus/Views/PostView.swift +++ b/damus/Views/PostView.swift @@ -77,8 +77,9 @@ struct PostView: View { if post.isEmpty { Text(POST_PLACEHOLDER) .padding(.top, 8) - .padding(.leading, 10) + .padding(.leading, 4) .foregroundColor(Color(uiColor: .placeholderText)) + .allowsHitTesting(false) } } } From 81f3764e4bdcaf25787832d88019e7567d3afea3 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Fri, 23 Dec 2022 08:32:23 -0800 Subject: [PATCH 2/3] profile: don't overwrite profile info This will be important for profile editing --- damus/Nostr/Nostr.swift | 69 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/damus/Nostr/Nostr.swift b/damus/Nostr/Nostr.swift index cc1289c2..9845ecb7 100644 --- 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) } From 972716882c12c6367e08edad780c101dd4b974aa Mon Sep 17 00:00:00 2001 From: William Casarin Date: Fri, 23 Dec 2022 09:20:44 -0800 Subject: [PATCH 3/3] profile: add ability to gets/set nip05 --- damus/Nostr/Nostr.swift | 8 +++++++- damus/Views/ProfilePicView.swift | 2 +- damus/Views/ProfileView.swift | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/damus/Nostr/Nostr.swift b/damus/Nostr/Nostr.swift index 9845ecb7..d8093417 100644 --- a/damus/Nostr/Nostr.swift +++ b/damus/Nostr/Nostr.swift @@ -10,7 +10,7 @@ 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?) { + init (name: String?, display_name: String?, about: String?, picture: String?, website: String?, lud06: String?, lud16: String?, nip05: String?) { self.value = [:] self.name = name self.display_name = display_name @@ -19,6 +19,7 @@ struct Profile: Codable { self.website = website self.lud06 = lud06 self.lud16 = lud16 + self.nip05 = nip05 } var display_name: String? { @@ -56,6 +57,11 @@ struct Profile: Codable { set(s) { value["lud16"] = s } } + var nip05: String? { + get { return value["nip05"]; } + set(s) { value["nip05"] = s } + } + var lightning_uri: URL? { return make_ln_url(self.lud06) ?? make_ln_url(self.lud16) } diff --git a/damus/Views/ProfilePicView.swift b/damus/Views/ProfilePicView.swift index d614a7f9..e0e266be 100644 --- a/damus/Views/ProfilePicView.swift +++ b/damus/Views/ProfilePicView.swift @@ -101,7 +101,7 @@ struct ProfilePicView: View { func make_preview_profiles(_ pubkey: String) -> Profiles { let profiles = Profiles() let picture = "http://cdn.jb55.com/img/red-me.jpg" - let profile = Profile(name: "jb55", display_name: "William Casarin", about: "It's me", picture: picture, website: "https://jb55.com", lud06: nil, lud16: nil) + let profile = Profile(name: "jb55", display_name: "William Casarin", about: "It's me", picture: picture, website: "https://jb55.com", lud06: nil, lud16: nil, nip05: "jb55.com") let ts_profile = TimestampedProfile(profile: profile, timestamp: 0) profiles.add(id: pubkey, profile: ts_profile) return profiles diff --git a/damus/Views/ProfileView.swift b/damus/Views/ProfileView.swift index b924f2eb..f4508247 100644 --- a/damus/Views/ProfileView.swift +++ b/damus/Views/ProfileView.swift @@ -211,7 +211,7 @@ func test_damus_state() -> DamusState { let pubkey = "3efdaebb1d8923ebd99c9e7ace3b4194ab45512e2be79c1b7d68d9243e0d2681" let damus = DamusState(pool: RelayPool(), keypair: Keypair(pubkey: pubkey, privkey: "privkey"), likes: EventCounter(our_pubkey: pubkey), boosts: EventCounter(our_pubkey: pubkey), contacts: Contacts(), tips: TipCounter(our_pubkey: pubkey), profiles: Profiles(), dms: DirectMessagesModel()) - let prof = Profile(name: "damus", display_name: "Damus", about: "iOS app!", picture: "https://damus.io/img/logo.png", website: "https://damus.io", lud06: nil, lud16: "jb55@sendsats.lol") + let prof = Profile(name: "damus", display_name: "Damus", about: "iOS app!", picture: "https://damus.io/img/logo.png", website: "https://damus.io", lud06: nil, lud16: "jb55@sendsats.lol", nip05: "damus.io") let tsprof = TimestampedProfile(profile: prof, timestamp: 0) damus.profiles.add(id: pubkey, profile: tsprof) return damus