forked from shadowfacts/Tusker
Fix custom emoji not being stripped from usernames in VoiceOver labels
This commit is contained in:
parent
a79b3cfd70
commit
cde061c77a
|
@ -20,18 +20,30 @@ extension AccountMO {
|
||||||
}
|
}
|
||||||
|
|
||||||
var displayNameWithoutCustomEmoji: String {
|
var displayNameWithoutCustomEmoji: String {
|
||||||
if displayName.isEmpty {
|
let stripped = stripCustomEmoji(from: displayName)
|
||||||
|
if stripped.isEmpty {
|
||||||
return username
|
return username
|
||||||
} else {
|
} else {
|
||||||
return stripCustomEmoji(from: displayName)
|
return stripped
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static let customEmojiRegex = try! NSRegularExpression(pattern: ":[a-zA-Z0-9_]+:", options: [])
|
}
|
||||||
|
|
||||||
|
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 {
|
private func stripCustomEmoji(from string: String) -> String {
|
||||||
let range = NSRange(location: 0, length: string.utf16.count)
|
let range = NSRange(location: 0, length: string.utf16.count)
|
||||||
return AccountMO.customEmojiRegex.stringByReplacingMatches(in: string, options: [], range: range, withTemplate: "")
|
return customEmojiRegex.stringByReplacingMatches(in: string, options: [], range: range, withTemplate: "")
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,7 +135,7 @@ class FeaturedProfileCollectionViewCell: UICollectionViewCell {
|
||||||
guard let account else {
|
guard let account else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
let s = NSMutableAttributedString(string: "\(account.displayName), ")
|
let s = NSMutableAttributedString(string: "\(account.displayNameWithoutCustomEmoji), ")
|
||||||
s.append(noteTextView.attributedText)
|
s.append(noteTextView.attributedText)
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,7 +94,7 @@ class AccountCollectionViewCell: UICollectionViewListCell {
|
||||||
let account = mastodonController.persistentContainer.account(for: accountID) else {
|
let account = mastodonController.persistentContainer.account(for: accountID) else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
var str = AttributedString(account.displayOrUserName)
|
var str = AttributedString(account.displayNameWithoutCustomEmoji)
|
||||||
str += ", @"
|
str += ", @"
|
||||||
str += AttributedString(account.acct)
|
str += AttributedString(account.acct)
|
||||||
return NSAttributedString(str)
|
return NSAttributedString(str)
|
||||||
|
|
|
@ -372,9 +372,9 @@ class TimelineStatusCollectionViewCell: UICollectionViewListCell, StatusCollecti
|
||||||
var str: AttributedString = ""
|
var str: AttributedString = ""
|
||||||
if let rebloggerID,
|
if let rebloggerID,
|
||||||
let reblogger = mastodonController.persistentContainer.account(for: 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 += ", "
|
str += ", "
|
||||||
if statusState.collapsed ?? false {
|
if statusState.collapsed ?? false {
|
||||||
if !status.spoilerText.isEmpty {
|
if !status.spoilerText.isEmpty {
|
||||||
|
|
|
@ -257,9 +257,9 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell {
|
||||||
var str: AttributedString = ""
|
var str: AttributedString = ""
|
||||||
if let rebloggerID,
|
if let rebloggerID,
|
||||||
let reblogger = mastodonController.persistentContainer.account(for: 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 += ", "
|
str += ", "
|
||||||
if statusState.collapsed ?? false {
|
if statusState.collapsed ?? false {
|
||||||
if !status.spoilerText.isEmpty {
|
if !status.spoilerText.isEmpty {
|
||||||
|
|
Loading…
Reference in New Issue