nip19: fix shared nevents that are too long
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>
This commit is contained in:
committed by
William Casarin
parent
5c76ffda8c
commit
7cc2825d89
@@ -13,6 +13,8 @@ class ProfileModel: ObservableObject, Equatable {
|
|||||||
@Published var relays: [String: RelayInfo]? = nil
|
@Published var relays: [String: RelayInfo]? = nil
|
||||||
@Published var progress: Int = 0
|
@Published var progress: Int = 0
|
||||||
|
|
||||||
|
private let MAX_SHARE_RELAYS = 4
|
||||||
|
|
||||||
var events: EventHolder
|
var events: EventHolder
|
||||||
let pubkey: Pubkey
|
let pubkey: Pubkey
|
||||||
let damus: DamusState
|
let damus: DamusState
|
||||||
@@ -161,6 +163,10 @@ class ProfileModel: ObservableObject, Equatable {
|
|||||||
func getRelayStrings() -> [String] {
|
func getRelayStrings() -> [String] {
|
||||||
return relays?.keys.map {$0} ?? []
|
return relays?.keys.map {$0} ?? []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getCappedRelayStrings() -> [String] {
|
||||||
|
return relays?.keys.prefix(MAX_SHARE_RELAYS).map { $0 } ?? []
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ struct ShareAction: View {
|
|||||||
|
|
||||||
ShareActionButton(img: "link", text: NSLocalizedString("Copy Link", comment: "Button to copy link to note")) {
|
ShareActionButton(img: "link", text: NSLocalizedString("Copy Link", comment: "Button to copy link to note")) {
|
||||||
dismiss()
|
dismiss()
|
||||||
UIPasteboard.general.string = "https://damus.io/" + Bech32Object.encode(.nevent(NEvent(noteid: event.id, relays: userProfile.getRelayStrings())))
|
UIPasteboard.general.string = "https://damus.io/" + Bech32Object.encode(.nevent(NEvent(noteid: event.id, relays: userProfile.getCappedRelayStrings())))
|
||||||
}
|
}
|
||||||
|
|
||||||
let bookmarkImg = isBookmarked ? "bookmark.fill" : "bookmark"
|
let bookmarkImg = isBookmarked ? "bookmark.fill" : "bookmark"
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ struct MenuItems: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Button {
|
Button {
|
||||||
UIPasteboard.general.string = Bech32Object.encode(.nprofile(NProfile(author: target_pubkey, relays: profileModel.getRelayStrings())))
|
UIPasteboard.general.string = Bech32Object.encode(.nprofile(NProfile(author: target_pubkey, relays: profileModel.getCappedRelayStrings())))
|
||||||
} label: {
|
} label: {
|
||||||
Label(NSLocalizedString("Copy user public key", comment: "Context menu option for copying the ID of the user who created the note."), image: "user")
|
Label(NSLocalizedString("Copy user public key", comment: "Context menu option for copying the ID of the user who created the note."), image: "user")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user