diff --git a/damus/Nostr/NostrLink.swift b/damus/Nostr/NostrLink.swift index ca6ff31..93ae2e1 100644 --- 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 index eb85057..3f3454e 100644 --- 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 index 9afaf9e..a882f44 100644 --- 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 index f8f9346..723c4f5 100644 --- a/damus/damus.entitlements +++ b/damus/damus.entitlements @@ -4,6 +4,10 @@ aps-environment development + com.apple.developer.associated-domains + + applinks:damus.io + keychain-access-groups $(AppIdentifierPrefix)com.jb55.damus2