diff --git a/damus.xcodeproj/project.pbxproj b/damus.xcodeproj/project.pbxproj index 6941c131..0cfa0451 100644 --- a/damus.xcodeproj/project.pbxproj +++ b/damus.xcodeproj/project.pbxproj @@ -402,6 +402,7 @@ 5C513FCC2984ACA60072348F /* QRCodeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C513FCB2984ACA60072348F /* QRCodeView.swift */; }; 5C6E1DAD2A193EC2008FC15A /* GradientButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C6E1DAC2A193EC2008FC15A /* GradientButtonStyle.swift */; }; 5C6E1DAF2A194075008FC15A /* PinkGradient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C6E1DAE2A194075008FC15A /* PinkGradient.swift */; }; + 5C7389B12B6EFA7100781E0A /* ProxyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C7389B02B6EFA7100781E0A /* ProxyView.swift */; }; 5CC868DD2AA29B3200FB22BA /* NeutralButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CC868DC2AA29B3200FB22BA /* NeutralButtonStyle.swift */; }; 5CF2DCCC2AA3AF0B00984B8D /* RelayPicView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CF2DCCB2AA3AF0B00984B8D /* RelayPicView.swift */; }; 5CF2DCCE2AABE1A500984B8D /* DamusLightGradient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CF2DCCD2AABE1A500984B8D /* DamusLightGradient.swift */; }; @@ -1305,6 +1306,7 @@ 5C513FCB2984ACA60072348F /* QRCodeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QRCodeView.swift; sourceTree = ""; }; 5C6E1DAC2A193EC2008FC15A /* GradientButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GradientButtonStyle.swift; sourceTree = ""; }; 5C6E1DAE2A194075008FC15A /* PinkGradient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PinkGradient.swift; sourceTree = ""; }; + 5C7389B02B6EFA7100781E0A /* ProxyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProxyView.swift; sourceTree = ""; }; 5CC868DC2AA29B3200FB22BA /* NeutralButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NeutralButtonStyle.swift; sourceTree = ""; }; 5CF2DCCB2AA3AF0B00984B8D /* RelayPicView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayPicView.swift; sourceTree = ""; }; 5CF2DCCD2AABE1A500984B8D /* DamusLightGradient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DamusLightGradient.swift; sourceTree = ""; }; @@ -2244,6 +2246,7 @@ 4CA927662A290F8B0098A105 /* RelativeTime.swift */, 4CA927692A290FC00098A105 /* ContextButton.swift */, 4CA9276B2A2910D10098A105 /* ReplyPart.swift */, + 5C7389B02B6EFA7100781E0A /* ProxyView.swift */, ); path = Components; sourceTree = ""; @@ -3241,6 +3244,7 @@ 4CAAD8B029888AD200060CEA /* RelayConfigView.swift in Sources */, 50088DA129E8271A008A1FDF /* WebSocket.swift in Sources */, 4C3EA64128FF553900C48A62 /* hash_u5.c in Sources */, + 5C7389B12B6EFA7100781E0A /* ProxyView.swift in Sources */, 4C1253542A76C7D60004F4B8 /* LogoutNotify.swift in Sources */, 5C513FCC2984ACA60072348F /* QRCodeView.swift in Sources */, 4CC14FF52A740BB7007AEB17 /* NoteId.swift in Sources */, diff --git a/damus/Assets.xcassets/activityPub.imageset/ActivityPub-logo.svg b/damus/Assets.xcassets/activityPub.imageset/ActivityPub-logo.svg new file mode 100644 index 00000000..8a212622 --- /dev/null +++ b/damus/Assets.xcassets/activityPub.imageset/ActivityPub-logo.svg @@ -0,0 +1,328 @@ + + + + + ActivityPub logo + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + ActivityPub logo + + 2017-04-15 + + + Robert Martinez + + + + + ActivityPub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/damus/Assets.xcassets/activityPub.imageset/Contents.json b/damus/Assets.xcassets/activityPub.imageset/Contents.json new file mode 100644 index 00000000..6799f407 --- /dev/null +++ b/damus/Assets.xcassets/activityPub.imageset/Contents.json @@ -0,0 +1,12 @@ +{ + "images" : [ + { + "filename" : "ActivityPub-logo.svg", + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/damus/Assets.xcassets/atproto.imageset/Contents.json b/damus/Assets.xcassets/atproto.imageset/Contents.json new file mode 100644 index 00000000..53925e4f --- /dev/null +++ b/damus/Assets.xcassets/atproto.imageset/Contents.json @@ -0,0 +1,12 @@ +{ + "images" : [ + { + "filename" : "atproto.png", + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/damus/Assets.xcassets/atproto.imageset/atproto.png b/damus/Assets.xcassets/atproto.imageset/atproto.png new file mode 100644 index 00000000..b4dd7e3a Binary files /dev/null and b/damus/Assets.xcassets/atproto.imageset/atproto.png differ diff --git a/damus/Assets.xcassets/rss.imageset/Contents.json b/damus/Assets.xcassets/rss.imageset/Contents.json new file mode 100644 index 00000000..394d3981 --- /dev/null +++ b/damus/Assets.xcassets/rss.imageset/Contents.json @@ -0,0 +1,12 @@ +{ + "images" : [ + { + "filename" : "rss.png", + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/damus/Assets.xcassets/rss.imageset/rss.png b/damus/Assets.xcassets/rss.imageset/rss.png new file mode 100644 index 00000000..00be2e6e Binary files /dev/null and b/damus/Assets.xcassets/rss.imageset/rss.png differ diff --git a/damus/Views/Events/Components/ProxyView.swift b/damus/Views/Events/Components/ProxyView.swift new file mode 100644 index 00000000..6df55f4a --- /dev/null +++ b/damus/Views/Events/Components/ProxyView.swift @@ -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) + } + } +} diff --git a/damus/Views/Events/EventShell.swift b/damus/Views/Events/EventShell.swift index 3aab1dca..6994cd13 100644 --- a/damus/Views/Events/EventShell.swift +++ b/damus/Views/Events/EventShell.swift @@ -96,6 +96,7 @@ struct EventShell: 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)