damus

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

commit 2c6999e15c868386a0147a2a5e973de15d1c7789
parent 981d500c25a1f6ab01af0ff40e32bbdb842c23b0
Author: William Casarin <jb55@jb55.com>
Date:   Wed, 23 Aug 2023 17:46:15 -0700

status: support clickable status urls

Changelog-Added: Add support for status URLs

Diffstat:
Mdamus/Components/Status/UserStatus.swift | 6++----
Mdamus/Components/Status/UserStatusSheet.swift | 27++++++++++++++++++++++++++-
Mdamus/Components/Status/UserStatusView.swift | 45++++++++++++++++++++++++++-------------------
3 files changed, 54 insertions(+), 24 deletions(-)

diff --git a/damus/Components/Status/UserStatus.swift b/damus/Components/Status/UserStatus.swift @@ -11,16 +11,14 @@ import MediaPlayer struct Song { let started_playing: Date let content: String - - } struct UserStatus { let type: UserStatusType let expires_at: Date? - let content: String + var content: String let created_at: UInt32 - let url: URL? + var url: URL? func to_note(keypair: FullKeypair) -> NostrEvent? { return make_user_status_note(status: self, keypair: keypair) diff --git a/damus/Components/Status/UserStatusSheet.swift b/damus/Components/Status/UserStatusSheet.swift @@ -38,6 +38,7 @@ struct UserStatusSheet: View { let keypair: Keypair @State var duration: StatusDuration = .never + @ObservedObject var status: UserStatusModel @Environment(\.dismiss) var dismiss @@ -45,7 +46,23 @@ struct UserStatusSheet: View { Binding(get: { status.general?.content ?? "" }, set: { v in - status.general = UserStatus(type: .general, expires_at: duration.expiration, content: v, created_at: UInt32(Date.now.timeIntervalSince1970)) + if let general = status.general { + status.general = UserStatus(type: .general, expires_at: duration.expiration, content: v, created_at: UInt32(Date.now.timeIntervalSince1970), url: general.url) + } else { + status.general = UserStatus(type: .general, expires_at: duration.expiration, content: v, created_at: UInt32(Date.now.timeIntervalSince1970), url: nil) + } + }) + } + + var url_binding: Binding<String> { + Binding(get: { + status.general?.url?.absoluteString ?? "" + }, set: { v in + if let general = status.general { + status.general = UserStatus(type: .general, expires_at: duration.expiration, content: general.content, created_at: UInt32(Date.now.timeIntervalSince1970), url: URL(string: v)) + } else { + status.general = UserStatus(type: .general, expires_at: duration.expiration, content: "", created_at: UInt32(Date.now.timeIntervalSince1970), url: URL(string: v)) + } }) } @@ -59,6 +76,14 @@ struct UserStatusSheet: View { }) HStack { + Image("link") + + TextField(text: url_binding, label: { + Text("https://example.com") + }) + } + + HStack { Text("Clear status") Spacer() diff --git a/damus/Components/Status/UserStatusView.swift b/damus/Components/Status/UserStatusView.swift @@ -17,38 +17,45 @@ struct UserStatusView: View { @Environment(\.openURL) var openURL + func Status(st: UserStatus, prefix: String = "") -> some View { + HStack { + Text(verbatim: "\(prefix)\(st.content)") + .lineLimit(1) + .foregroundColor(.gray) + .font(.callout.italic()) + if st.url != nil { + Image("link") + .resizable() + .frame(width: 16, height: 16) + .foregroundColor(.gray) + } + } + .onTapGesture { + if let url = st.url { + openURL(url) + } + } + } + var body: some View { VStack(alignment: .leading, spacing: 2) { if show_general, let general = status.general { - Text(verbatim: "\(general.content)") - .lineLimit(1) - .foregroundColor(.gray) - .font(.callout.italic()) - .onTapGesture { - if let url = general.url { - openURL(url) - } - } + Status(st: general) } if show_music, let playing = status.music { - Text(verbatim: "🎵\(playing.content)") - .lineLimit(1) - .foregroundColor(.gray) - .font(.callout.italic()) - .onTapGesture { - if let url = playing.url { - openURL(url) - } - } + Status(st: playing, prefix: "🎵") } } } } +/* struct UserStatusView_Previews: PreviewProvider { static var previews: some View { - UserStatusView(status: .init(), show_general: true, show_music: true) + UserStatusView(status: UserStatus(type: .music, expires_at: nil, content: "Track - Artist", created_at: 0, url: URL(string: "spotify:search:abc")), show_general: true, show_music: true) } } + +*/