diff --git a/Tusker/Extensions/Account+Preferences.swift b/Tusker/Extensions/Account+Preferences.swift index 9a5811be..b2cd6047 100644 --- a/Tusker/Extensions/Account+Preferences.swift +++ b/Tusker/Extensions/Account+Preferences.swift @@ -20,18 +20,30 @@ extension AccountMO { } var displayNameWithoutCustomEmoji: String { - if displayName.isEmpty { + let stripped = stripCustomEmoji(from: displayName) + if stripped.isEmpty { return username } else { - return stripCustomEmoji(from: displayName) + return stripped } } - private static let customEmojiRegex = try! NSRegularExpression(pattern: ":[a-zA-Z0-9_]+:", options: []) - - private func stripCustomEmoji(from string: String) -> String { - let range = NSRange(location: 0, length: string.utf16.count) - return AccountMO.customEmojiRegex.stringByReplacingMatches(in: string, options: [], range: range, withTemplate: "") - } - +} + +extension Account { + var displayNameWithoutCustomEmoji: String { + let stripped = stripCustomEmoji(from: displayName) + if stripped.isEmpty { + return username + } else { + return stripped + } + } +} + +private let customEmojiRegex = try! NSRegularExpression(pattern: ":[a-zA-Z0-9_]+:", options: []) + +private func stripCustomEmoji(from string: String) -> String { + let range = NSRange(location: 0, length: string.utf16.count) + return customEmojiRegex.stringByReplacingMatches(in: string, options: [], range: range, withTemplate: "") } diff --git a/Tusker/Screens/Explore/FeaturedProfileCollectionViewCell.swift b/Tusker/Screens/Explore/FeaturedProfileCollectionViewCell.swift index a1013c37..be065a1b 100644 --- a/Tusker/Screens/Explore/FeaturedProfileCollectionViewCell.swift +++ b/Tusker/Screens/Explore/FeaturedProfileCollectionViewCell.swift @@ -135,7 +135,7 @@ class FeaturedProfileCollectionViewCell: UICollectionViewCell { guard let account else { return nil } - let s = NSMutableAttributedString(string: "\(account.displayName), ") + let s = NSMutableAttributedString(string: "\(account.displayNameWithoutCustomEmoji), ") s.append(noteTextView.attributedText) return s } diff --git a/Tusker/Views/Account Cell/AccountCollectionViewCell.swift b/Tusker/Views/Account Cell/AccountCollectionViewCell.swift index b200dccf..cb90f4c5 100644 --- a/Tusker/Views/Account Cell/AccountCollectionViewCell.swift +++ b/Tusker/Views/Account Cell/AccountCollectionViewCell.swift @@ -94,7 +94,7 @@ class AccountCollectionViewCell: UICollectionViewListCell { let account = mastodonController.persistentContainer.account(for: accountID) else { return nil } - var str = AttributedString(account.displayOrUserName) + var str = AttributedString(account.displayNameWithoutCustomEmoji) str += ", @" str += AttributedString(account.acct) return NSAttributedString(str) diff --git a/Tusker/Views/Status/TimelineStatusCollectionViewCell.swift b/Tusker/Views/Status/TimelineStatusCollectionViewCell.swift index 423419a5..5a7fb166 100644 --- a/Tusker/Views/Status/TimelineStatusCollectionViewCell.swift +++ b/Tusker/Views/Status/TimelineStatusCollectionViewCell.swift @@ -372,9 +372,9 @@ class TimelineStatusCollectionViewCell: UICollectionViewListCell, StatusCollecti var str: AttributedString = "" if let rebloggerID, let reblogger = mastodonController.persistentContainer.account(for: rebloggerID) { - str += AttributedString("Reblogged by \(reblogger.displayOrUserName): ") + str += AttributedString("Reblogged by \(reblogger.displayNameWithoutCustomEmoji): ") } - str += AttributedString(status.account.displayOrUserName) + str += AttributedString(status.account.displayNameWithoutCustomEmoji) str += ", " if statusState.collapsed ?? false { if !status.spoilerText.isEmpty { diff --git a/Tusker/Views/Status/TimelineStatusTableViewCell.swift b/Tusker/Views/Status/TimelineStatusTableViewCell.swift index 538a3f79..ce3bfb63 100644 --- a/Tusker/Views/Status/TimelineStatusTableViewCell.swift +++ b/Tusker/Views/Status/TimelineStatusTableViewCell.swift @@ -257,9 +257,9 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell { var str: AttributedString = "" if let rebloggerID, let reblogger = mastodonController.persistentContainer.account(for: rebloggerID) { - str += AttributedString("Reblogged by \(reblogger.displayOrUserName): ") + str += AttributedString("Reblogged by \(reblogger.displayNameWithoutCustomEmoji): ") } - str += AttributedString(status.account.displayOrUserName) + str += AttributedString(status.account.displayNameWithoutCustomEmoji) str += ", " if statusState.collapsed ?? false { if !status.spoilerText.isEmpty {