nip48: initial support
This patch adds a new ProxyView which is added to the Event Shell whenever an event has the proxy tag. It includes images of the protocol logos that are listed in the NIP docs. Reviewed-by: William Casarin <jb55@jb55>.com Link: 20240205032400.7069-1-ericholguin@apache.org Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
committed by
William Casarin
parent
4a4a58c7b5
commit
90180202b6
100
damus/Views/Events/Components/ProxyView.swift
Normal file
100
damus/Views/Events/Components/ProxyView.swift
Normal file
@@ -0,0 +1,100 @@
|
||||
//
|
||||
// ProxyView.swift
|
||||
// damus
|
||||
//
|
||||
// Created by eric on 2/3/24.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct ProxyTag {
|
||||
let id: String
|
||||
let protocolName: String
|
||||
|
||||
init(id: String, protocolName: String) {
|
||||
self.id = id
|
||||
self.protocolName = protocolName
|
||||
}
|
||||
}
|
||||
|
||||
struct ProxyView: View {
|
||||
let event: NostrEvent
|
||||
|
||||
@Environment(\.openURL) var openURL
|
||||
|
||||
var body: some View {
|
||||
Group {
|
||||
if let proxy = event_proxy(ev: event) {
|
||||
VStack(alignment: .leading) {
|
||||
Button(
|
||||
action: {
|
||||
if let url = URL(string: proxy.id) {
|
||||
openURL(url)
|
||||
}
|
||||
},
|
||||
label: {
|
||||
HStack {
|
||||
let protocolLogo = get_protocol_image(protocolName: proxy.protocolName)
|
||||
if protocolLogo.isEmpty {
|
||||
Text("\(proxy.protocolName)")
|
||||
.font(.caption)
|
||||
} else {
|
||||
Image(protocolLogo)
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: proxy.protocolName == "activitypub" ? 75 : 20, height: proxy.protocolName == "activitypub" ? 20 : 25)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
.buttonStyle(NeutralButtonStyle(padding: EdgeInsets(top: 2, leading: 5, bottom: 2, trailing: 5), cornerRadius: 20))
|
||||
}
|
||||
} else {
|
||||
EmptyView()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func get_protocol_image(protocolName: String) -> String {
|
||||
switch protocolName {
|
||||
case "activitypub": return "activityPub"
|
||||
case "rss": return "rss"
|
||||
case "atproto": return "atproto"
|
||||
case "web": return "globe"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func event_proxy(ev: NostrEvent) -> ProxyTag? {
|
||||
var proxyParts = [String]()
|
||||
for tag in ev.tags {
|
||||
if tag.count == 3 && tag[0].matches_str("proxy") {
|
||||
proxyParts = tag.strings()
|
||||
guard proxyParts.count == 3 else {
|
||||
return nil
|
||||
}
|
||||
return ProxyTag(id: proxyParts[1], protocolName: proxyParts[2])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
struct ProxyView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
let activityPubEv = NostrEvent(content: "", keypair: test_keypair, kind: 1, tags: [["proxy", "", "activitypub"]])!
|
||||
let atProtoEv = NostrEvent(content: "", keypair: test_keypair, kind: 1, tags: [["proxy", "", "atproto"]])!
|
||||
let rssEv = NostrEvent(content: "", keypair: test_keypair, kind: 1, tags: [["proxy", "", "rss"]])!
|
||||
let webEv = NostrEvent(content: "", keypair: test_keypair, kind: 1, tags: [["proxy", "", "web"]])!
|
||||
let unsupportedEv = NostrEvent(content: "", keypair: test_keypair, kind: 1, tags: [["proxy", "", "unsupported"]])!
|
||||
VStack(alignment: .center, spacing: 10) {
|
||||
ProxyView(event: activityPubEv)
|
||||
ProxyView(event: rssEv)
|
||||
ProxyView(event: atProtoEv)
|
||||
ProxyView(event: webEv)
|
||||
ProxyView(event: unsupportedEv)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -96,6 +96,7 @@ struct EventShell<Content: View>: View {
|
||||
EventTop(state: state, event: event, pubkey: pubkey, is_anon: is_anon)
|
||||
UserStatusView(status: state.profiles.profile_data(pubkey).status, show_general: state.settings.show_general_statuses, show_music: state.settings.show_music_statuses)
|
||||
ReplyPart(events: state.events, event: event, keypair: state.keypair, ndb: state.ndb)
|
||||
ProxyView(event: event)
|
||||
}
|
||||
}
|
||||
.padding(.horizontal)
|
||||
|
||||
Reference in New Issue
Block a user