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

@@ -65,7 +65,7 @@ struct ProfileName: View {
}
var name_choice: String {
return prefix == "@" ? current_display_name.username : current_display_name.display_name
return prefix == "@" ? current_display_name.username.truncate(maxLength: 50) : current_display_name.display_name.truncate(maxLength: 50)
}
var onlyzapper: Bool {

View File

@@ -93,6 +93,7 @@ struct ProfileView: View {
let damus_state: DamusState
let pfp_size: CGFloat = 90.0
let bannerHeight: CGFloat = 150.0
let max_about_length = 280
static let markdown = Markdown()
@@ -103,6 +104,7 @@ struct ProfileView: View {
@State var action_sheet_presented: Bool = false
@State var filter_state : FilterState = .posts
@State var yOffset: CGFloat = 0
@State var show_full_about: Bool = false
@StateObject var profile: ProfileModel
@StateObject var followers: FollowersModel
@@ -403,7 +405,23 @@ struct ProfileView: View {
if let about = profile_data?.about {
let blocks = parse_mentions(content: about, tags: [])
let about_string = render_blocks(blocks: blocks, profiles: damus_state.profiles).content.attributed
SelectableText(attributedString: about_string, size: .subheadline)
let truncated_about = show_full_about ? about_string : about_string.truncateOrNil(maxLength: max_about_length)
SelectableText(attributedString: truncated_about ?? about_string, size: .subheadline)
if truncated_about != nil {
if show_full_about {
Button(NSLocalizedString("Show less", comment: "Button to show less of a long profile description.")) {
show_full_about = false
}
.font(.footnote)
} else {
Button(NSLocalizedString("Show more", comment: "Button to show more of a long profile description.")) {
show_full_about = true
}
.font(.footnote)
}
}
} else {
Text(verbatim: "")
.font(.subheadline)