damus

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

commit d5857325b1a067dceb0cf2d9ff4041a74c3af4e9
parent 04e4bc7985a173c6b31855e5751dcef251ebcdaa
Author: William Casarin <jb55@jb55.com>
Date:   Fri,  6 Jan 2023 10:24:08 -0800

Universal Links: share notes!

Changelog-Added: Added universal link sharing of notes

Diffstat:
Mdamus/Nostr/NostrLink.swift | 25+++++++++++++++++++++++++
Mdamus/Nostr/RelayConnection.swift | 2+-
Mdamus/Views/EventActionBar.swift | 17++++++++++++++++-
Mdamus/damus.entitlements | 4++++
4 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/damus/Nostr/NostrLink.swift b/damus/Nostr/NostrLink.swift @@ -80,7 +80,32 @@ func parse_nostr_ref_uri(_ p: Parser) -> ReferencedId? { return ReferencedId(ref_id: pk, relay_id: nil, key: typ) } +func decode_universal_link(_ s: String) -> NostrLink? { + var uri = s.replacingOccurrences(of: "https://damus.io/r/", with: "") + uri = uri.replacingOccurrences(of: "https://damus.io/", with: "") + uri = uri.replacingOccurrences(of: "/", with: "") + + guard let decoded = try? bech32_decode(uri) else { + return nil + } + + let h = hex_encode(decoded.data) + + if decoded.hrp == "note" { + return .ref(ReferencedId(ref_id: h, relay_id: nil, key: "e")) + } else if decoded.hrp == "npub" { + return .ref(ReferencedId(ref_id: h, relay_id: nil, key: "p")) + } + // TODO: handle nprofile, etc + + return nil +} + func decode_nostr_uri(_ s: String) -> NostrLink? { + if s.starts(with: "https://damus.io/") { + return decode_universal_link(s) + } + var uri = s.replacingOccurrences(of: "nostr://", with: "") uri = uri.replacingOccurrences(of: "nostr:", with: "") diff --git a/damus/Nostr/RelayConnection.swift b/damus/Nostr/RelayConnection.swift @@ -38,7 +38,7 @@ class RelayConnection: WebSocketDelegate { self.connect(force: true) } } - + func connect(force: Bool = false){ if !force && (self.isConnected || self.isConnecting) { return diff --git a/damus/Views/EventActionBar.swift b/damus/Views/EventActionBar.swift @@ -24,6 +24,7 @@ struct EventActionBar: View { let generator = UIImpactFeedbackGenerator(style: .medium) @State var sheet: ActionBarSheet? = nil @State var confirm_boost: Bool = false + @State var show_share_sheet: Bool = false @StateObject var bar: ActionBarModel var body: some View { @@ -40,6 +41,7 @@ struct EventActionBar: View { EventActionButton(img: "bubble.left", col: nil) { notify(.reply, event) } + .frame(minWidth: 0, maxWidth: .infinity, alignment: .leading) } HStack(alignment: .bottom) { @@ -55,6 +57,7 @@ struct EventActionBar: View { } } } + .frame(minWidth: 0, maxWidth: .infinity, alignment: .leading) HStack(alignment: .bottom) { Text("\(bar.likes > 0 ? "\(bar.likes)" : "")") @@ -69,6 +72,12 @@ struct EventActionBar: View { } } } + .frame(minWidth: 0, maxWidth: .infinity, alignment: .leading) + + EventActionButton(img: "square.and.arrow.up", col: Color.gray) { + show_share_sheet = true + } + .frame(minWidth: 0, maxWidth: .infinity, alignment: .leading) /* HStack(alignment: .bottom) { @@ -86,6 +95,13 @@ struct EventActionBar: View { } */ } + .sheet(isPresented: $show_share_sheet) { + if let note_id = bech32_note_id(event.id) { + if let url = URL(string: "https://damus.io/" + note_id) { + ShareSheet(activityItems: [url]) + } + } + } .alert("Boost", isPresented: $confirm_boost) { Button("Cancel") { confirm_boost = false @@ -142,7 +158,6 @@ func EventActionButton(img: String, col: Color?, action: @escaping () -> ()) -> .font(.footnote.weight(.medium)) .foregroundColor(col == nil ? Color.gray : col!) } - .padding(.trailing, 40) } struct LikeButton: View { diff --git a/damus/damus.entitlements b/damus/damus.entitlements @@ -4,6 +4,10 @@ <dict> <key>aps-environment</key> <string>development</string> + <key>com.apple.developer.associated-domains</key> + <array> + <string>applinks:damus.io</string> + </array> <key>keychain-access-groups</key> <array> <string>$(AppIdentifierPrefix)com.jb55.damus2</string>