status: support clickable status urls
Changelog-Added: Add support for status URLs
This commit is contained in:
@@ -11,16 +11,14 @@ import MediaPlayer
|
|||||||
struct Song {
|
struct Song {
|
||||||
let started_playing: Date
|
let started_playing: Date
|
||||||
let content: String
|
let content: String
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct UserStatus {
|
struct UserStatus {
|
||||||
let type: UserStatusType
|
let type: UserStatusType
|
||||||
let expires_at: Date?
|
let expires_at: Date?
|
||||||
let content: String
|
var content: String
|
||||||
let created_at: UInt32
|
let created_at: UInt32
|
||||||
let url: URL?
|
var url: URL?
|
||||||
|
|
||||||
func to_note(keypair: FullKeypair) -> NostrEvent? {
|
func to_note(keypair: FullKeypair) -> NostrEvent? {
|
||||||
return make_user_status_note(status: self, keypair: keypair)
|
return make_user_status_note(status: self, keypair: keypair)
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ struct UserStatusSheet: View {
|
|||||||
let keypair: Keypair
|
let keypair: Keypair
|
||||||
|
|
||||||
@State var duration: StatusDuration = .never
|
@State var duration: StatusDuration = .never
|
||||||
|
|
||||||
@ObservedObject var status: UserStatusModel
|
@ObservedObject var status: UserStatusModel
|
||||||
@Environment(\.dismiss) var dismiss
|
@Environment(\.dismiss) var dismiss
|
||||||
|
|
||||||
@@ -45,7 +46,23 @@ struct UserStatusSheet: View {
|
|||||||
Binding(get: {
|
Binding(get: {
|
||||||
status.general?.content ?? ""
|
status.general?.content ?? ""
|
||||||
}, set: { v in
|
}, 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))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,6 +75,14 @@ struct UserStatusSheet: View {
|
|||||||
Text("📋 Working")
|
Text("📋 Working")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
HStack {
|
||||||
|
Image("link")
|
||||||
|
|
||||||
|
TextField(text: url_binding, label: {
|
||||||
|
Text("https://example.com")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
HStack {
|
HStack {
|
||||||
Text("Clear status")
|
Text("Clear status")
|
||||||
|
|
||||||
|
|||||||
@@ -17,38 +17,45 @@ struct UserStatusView: View {
|
|||||||
|
|
||||||
@Environment(\.openURL) var openURL
|
@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 {
|
var body: some View {
|
||||||
VStack(alignment: .leading, spacing: 2) {
|
VStack(alignment: .leading, spacing: 2) {
|
||||||
if show_general, let general = status.general {
|
if show_general, let general = status.general {
|
||||||
Text(verbatim: "\(general.content)")
|
Status(st: general)
|
||||||
.lineLimit(1)
|
|
||||||
.foregroundColor(.gray)
|
|
||||||
.font(.callout.italic())
|
|
||||||
.onTapGesture {
|
|
||||||
if let url = general.url {
|
|
||||||
openURL(url)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if show_music, let playing = status.music {
|
if show_music, let playing = status.music {
|
||||||
Text(verbatim: "🎵\(playing.content)")
|
Status(st: playing, prefix: "🎵")
|
||||||
.lineLimit(1)
|
|
||||||
.foregroundColor(.gray)
|
|
||||||
.font(.callout.italic())
|
|
||||||
.onTapGesture {
|
|
||||||
if let url = playing.url {
|
|
||||||
openURL(url)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
struct UserStatusView_Previews: PreviewProvider {
|
struct UserStatusView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user