1
0
mirror of git://jb55.com/damus synced 2024-09-29 08:20:45 +00:00

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:
kernelkind 2024-01-29 18:51:18 -05:00 committed by William Casarin
parent 5c76ffda8c
commit 7cc2825d89
3 changed files with 8 additions and 2 deletions

View File

@ -13,6 +13,8 @@ class ProfileModel: ObservableObject, Equatable {
@Published var relays: [String: RelayInfo]? = nil
@Published var progress: Int = 0
private let MAX_SHARE_RELAYS = 4
var events: EventHolder
let pubkey: Pubkey
let damus: DamusState
@ -161,6 +163,10 @@ class ProfileModel: ObservableObject, Equatable {
func getRelayStrings() -> [String] {
return relays?.keys.map {$0} ?? []
}
func getCappedRelayStrings() -> [String] {
return relays?.keys.prefix(MAX_SHARE_RELAYS).map { $0 } ?? []
}
}

View File

@ -40,7 +40,7 @@ struct ShareAction: View {
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.getRelayStrings())))
UIPasteboard.general.string = "https://damus.io/" + Bech32Object.encode(.nevent(NEvent(noteid: event.id, relays: userProfile.getCappedRelayStrings())))
}
let bookmarkImg = isBookmarked ? "bookmark.fill" : "bookmark"

View File

@ -86,7 +86,7 @@ struct MenuItems: View {
}
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(NSLocalizedString("Copy user public key", comment: "Context menu option for copying the ID of the user who created the note."), image: "user")
}