damus

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

commit 7cc2825d898cd9b61b53e3f77b0459006ce26417
parent 5c76ffda8ca0fb7f4d0833c3950c315eabaf25ec
Author: kernelkind <kernelkind@gmail.com>
Date:   Mon, 29 Jan 2024 18:51:18 -0500

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>

Diffstat:
Mdamus/Models/ProfileModel.swift | 6++++++
Mdamus/Views/ActionBar/ShareAction.swift | 2+-
Mdamus/Views/Events/EventMenu.swift | 2+-
3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/damus/Models/ProfileModel.swift b/damus/Models/ProfileModel.swift @@ -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 } ?? [] + } } diff --git a/damus/Views/ActionBar/ShareAction.swift b/damus/Views/ActionBar/ShareAction.swift @@ -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" diff --git a/damus/Views/Events/EventMenu.swift b/damus/Views/Events/EventMenu.swift @@ -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") }