Add max length truncation to displayed profile attributes to mitigate spam

Changelog-Fixed: Add max length truncation to displayed profile attributes to mitigate spam
Fixes: #1237
This commit is contained in:
2023-06-04 17:49:37 -04:00
parent 952d6746d5
commit 8ca377bec9
15 changed files with 71 additions and 23 deletions

View File

@@ -12,7 +12,7 @@ struct TruncatedText: View {
let maxChars: Int = 280
var body: some View {
let truncatedAttributedString: AttributedString? = getTruncatedString()
let truncatedAttributedString: AttributedString? = text.attributed.truncateOrNil(maxLength: maxChars)
if let truncatedAttributedString {
Text(truncatedAttributedString)
@@ -28,16 +28,6 @@ struct TruncatedText: View {
.allowsHitTesting(false)
}
}
func getTruncatedString() -> AttributedString? {
let nsAttributedString = NSAttributedString(text.attributed)
if nsAttributedString.length < maxChars { return nil }
let range = NSRange(location: 0, length: maxChars)
let truncatedAttributedString = nsAttributedString.attributedSubstring(from: range)
return AttributedString(truncatedAttributedString) + "..."
}
}
struct TruncatedText_Previews: PreviewProvider {

View File

@@ -23,6 +23,8 @@ struct WebsiteLink: View {
Text(link_text)
.font(.footnote)
.foregroundColor(.accentColor)
.truncationMode(.tail)
.lineLimit(1)
})
}
}