mirror of
git://jb55.com/damus
synced 2024-09-18 19:23:49 +00:00
status: click music urls to display in spotify
Changelog-Added: Click music statuses to display in spotify
This commit is contained in:
parent
d02fc9142d
commit
981d500c25
@ -20,16 +20,18 @@ struct UserStatus {
|
||||
let expires_at: Date?
|
||||
let content: String
|
||||
let created_at: UInt32
|
||||
let url: URL?
|
||||
|
||||
func to_note(keypair: FullKeypair) -> NostrEvent? {
|
||||
return make_user_status_note(status: self, keypair: keypair)
|
||||
}
|
||||
|
||||
init(type: UserStatusType, expires_at: Date?, content: String, created_at: UInt32) {
|
||||
init(type: UserStatusType, expires_at: Date?, content: String, created_at: UInt32, url: URL? = nil) {
|
||||
self.type = type
|
||||
self.expires_at = expires_at
|
||||
self.content = content
|
||||
self.created_at = created_at
|
||||
self.url = url
|
||||
}
|
||||
|
||||
func expired() -> Bool {
|
||||
@ -51,6 +53,15 @@ struct UserStatus {
|
||||
return nil
|
||||
}
|
||||
|
||||
if let tag = ev.tags.first(where: { t in t.count >= 2 && t[0].matches_char("r") }),
|
||||
tag.count >= 2,
|
||||
let url = URL(string: tag[1].string())
|
||||
{
|
||||
self.url = url
|
||||
} else {
|
||||
self.url = nil
|
||||
}
|
||||
|
||||
if let tag = ev.tags.first(where: { t in t.count >= 2 && t[0].matches_str("expiration") }),
|
||||
tag.count == 2,
|
||||
let expires = UInt32(tag[1].string())
|
||||
@ -160,6 +171,10 @@ func make_user_status_note(status: UserStatus, keypair: FullKeypair, expiry: Dat
|
||||
tags.append(["expiration", String(UInt32(expiry.timeIntervalSince1970))])
|
||||
}
|
||||
|
||||
if let url = status.url {
|
||||
tags.append(["r", url.absoluteString])
|
||||
}
|
||||
|
||||
let kind = NostrKind.status.rawValue
|
||||
guard let ev = NostrEvent(content: status.content, keypair: keypair.to_keypair(), kind: kind, tags: tags) else {
|
||||
return nil
|
||||
|
@ -15,6 +15,8 @@ struct UserStatusView: View {
|
||||
var show_general: Bool
|
||||
var show_music: Bool
|
||||
|
||||
@Environment(\.openURL) var openURL
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
if show_general, let general = status.general {
|
||||
@ -22,6 +24,11 @@ struct UserStatusView: View {
|
||||
.lineLimit(1)
|
||||
.foregroundColor(.gray)
|
||||
.font(.callout.italic())
|
||||
.onTapGesture {
|
||||
if let url = general.url {
|
||||
openURL(url)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if show_music, let playing = status.music {
|
||||
@ -29,6 +36,11 @@ struct UserStatusView: View {
|
||||
.lineLimit(1)
|
||||
.foregroundColor(.gray)
|
||||
.font(.callout.italic())
|
||||
.onTapGesture {
|
||||
if let url = playing.url {
|
||||
openURL(url)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -671,7 +671,12 @@ struct ContentView: View {
|
||||
|
||||
let pdata = damus_state.profiles.profile_data(damus_state.pubkey)
|
||||
|
||||
let music = UserStatus(type: .music, expires_at: Date.now.addingTimeInterval(song.playbackDuration), content: "\(song.title ?? "Unknown") - \(song.artist ?? "Unknown")", created_at: UInt32(Date.now.timeIntervalSince1970))
|
||||
let desc = "\(song.title ?? "Unknown") - \(song.artist ?? "Unknown")"
|
||||
let encodedDesc = desc.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
|
||||
let url = encodedDesc.flatMap { enc in
|
||||
URL(string: "spotify:search:\(enc)")
|
||||
}
|
||||
let music = UserStatus(type: .music, expires_at: Date.now.addingTimeInterval(song.playbackDuration), content: desc, created_at: UInt32(Date.now.timeIntervalSince1970), url: url)
|
||||
|
||||
pdata.status.music = music
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user