damus

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

commit 86e9ee16a0706296a3a3ecbab5bb260b31b2c417
parent 5f9477d55bb235625ff28a1e06f35d57ccdfd005
Author: kernelkind <kernelkind@gmail.com>
Date:   Tue, 30 Jan 2024 13:35:25 -0500

ui: truncate visible media URL

The URL shown to the user before they click the 'Load Media' button can
take up a large portion of the screen, and doesn't offer any value to
the user.

This patch features a naive approach to truncate the URL to be a certain
number of characters if it is greater than the specified value. Right
now the maximum number of characters is set to 80.

Closes: https://github.com/damus-io/damus/issues/1950
Lightning-address: kernelkind@getalby.com
Signed-off-by: kernelkind <kernelkind@gmail.com>
Link: 20240130183525.50446-1-kernelkind@gmail.com
Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mdamus/Util/URIParsing.swift | 11+++++++++++
Mdamus/Views/NoteContentView.swift | 2+-
2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/damus/Util/URIParsing.swift b/damus/Util/URIParsing.swift @@ -7,6 +7,8 @@ import Foundation +fileprivate let MAX_CHAR_URL = 80 + private func remove_damus_uri_prefix(_ s: String) -> String { var uri = s.replacingOccurrences(of: "https://damus.io/r/", with: "") uri = uri.replacingOccurrences(of: "https://damus.io/", with: "") @@ -32,3 +34,12 @@ func remove_nostr_uri_prefix(_ s: String) -> String { return uri } + +func abbreviateURL(_ url: URL) -> String { + let urlString = url.absoluteString + + if urlString.count > MAX_CHAR_URL { + return String(urlString.prefix(MAX_CHAR_URL)) + "..." + } + return urlString +} diff --git a/damus/Views/NoteContentView.swift b/damus/Views/NoteContentView.swift @@ -188,7 +188,7 @@ struct NoteContentView: View { .frame(height: 1) switch artifacts.media[index] { case .image(let url), .video(let url): - Text(url.absoluteString) + Text(abbreviateURL(url)) .font(eventviewsize_to_font(size, font_size: damus_state.settings.font_size)) .foregroundStyle(DamusColors.neutral6) .multilineTextAlignment(.leading)