7cc2825d89
There comes a point when the sharing a Nip19 mention becomes unwieldy when there is too much TLV data. This patch features a naive approach to making sure the relay portion of the TLV data doesn't contribute too much data to the mention. It adds a maximum number of relays that should be shared in the mention, right now it is set to four. Changelog-Fixed: Fix shared nevents that are too long Lightning-address: kernelkind@getalby.com Signed-off-by: kernelkind <kernelkind@gmail.com> Reviewed-by: William Casarin <jb55@jb55.com> Signed-off-by: William Casarin <jb55@jb55.com>
83 lines
2.9 KiB
Swift
83 lines
2.9 KiB
Swift
//
|
|
// ShareAction.swift
|
|
// damus
|
|
//
|
|
// Created by eric on 3/8/23.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct ShareAction: View {
|
|
let event: NostrEvent
|
|
let bookmarks: BookmarksManager
|
|
let userProfile: ProfileModel
|
|
@State private var isBookmarked: Bool = false
|
|
|
|
@Binding var show_share: Bool
|
|
|
|
@Environment(\.dismiss) var dismiss
|
|
|
|
init(event: NostrEvent, bookmarks: BookmarksManager, show_share: Binding<Bool>, userProfile: ProfileModel) {
|
|
let bookmarked = bookmarks.isBookmarked(event)
|
|
self._isBookmarked = State(initialValue: bookmarked)
|
|
|
|
self.bookmarks = bookmarks
|
|
self.event = event
|
|
self.userProfile = userProfile
|
|
self._show_share = show_share
|
|
}
|
|
|
|
var body: some View {
|
|
|
|
VStack {
|
|
Text("Share Note", comment: "Title text to indicate that the buttons below are meant to be used to share a note with others.")
|
|
.padding()
|
|
.font(.system(size: 17, weight: .bold))
|
|
|
|
Spacer()
|
|
|
|
HStack(alignment: .top, spacing: 25) {
|
|
|
|
ShareActionButton(img: "link", text: NSLocalizedString("Copy Link", comment: "Button to copy link to note")) {
|
|
dismiss()
|
|
UIPasteboard.general.string = "https://damus.io/" + Bech32Object.encode(.nevent(NEvent(noteid: event.id, relays: userProfile.getCappedRelayStrings())))
|
|
}
|
|
|
|
let bookmarkImg = isBookmarked ? "bookmark.fill" : "bookmark"
|
|
let bookmarkTxt = isBookmarked ? NSLocalizedString("Remove Bookmark", comment: "Button text to remove bookmark from a note.") : NSLocalizedString("Add Bookmark", comment: "Button text to add bookmark to a note.")
|
|
ShareActionButton(img: bookmarkImg, text: bookmarkTxt) {
|
|
dismiss()
|
|
self.bookmarks.updateBookmark(event)
|
|
isBookmarked = self.bookmarks.isBookmarked(event)
|
|
}
|
|
|
|
ShareActionButton(img: "globe", text: NSLocalizedString("Broadcast", comment: "Button to broadcast note to all your relays")) {
|
|
dismiss()
|
|
notify(.broadcast(event))
|
|
}
|
|
|
|
ShareActionButton(img: "upload", text: NSLocalizedString("Share Via...", comment: "Button to present iOS share sheet")) {
|
|
show_share = true
|
|
dismiss()
|
|
}
|
|
|
|
}
|
|
|
|
Spacer()
|
|
|
|
HStack {
|
|
BigButton(NSLocalizedString("Cancel", comment: "Button to cancel a repost.")) {
|
|
dismiss()
|
|
}
|
|
}
|
|
}
|
|
.onAppear() {
|
|
userProfile.subscribeToFindRelays()
|
|
}
|
|
.onDisappear() {
|
|
userProfile.unsubscribeFindRelays()
|
|
}
|
|
}
|
|
}
|
|
|