Compare commits
2 Commits
a79b3cfd70
...
f96acd33f2
Author | SHA1 | Date |
---|---|---|
Shadowfacts | f96acd33f2 | |
Shadowfacts | cde061c77a |
|
@ -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: "")
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
@ -386,15 +386,28 @@ class TimelineStatusCollectionViewCell: UICollectionViewListCell, StatusCollecti
|
|||
str += AttributedString(contentTextView.attributedText)
|
||||
|
||||
if status.attachments.count > 0 {
|
||||
if status.attachments.count == 1 {
|
||||
let attachment = status.attachments[0]
|
||||
let desc = attachment.description?.isEmpty == false ? attachment.description! : "no description"
|
||||
str += AttributedString(", attachment: \(desc)")
|
||||
} else {
|
||||
for (index, attachment) in status.attachments.enumerated() {
|
||||
let includeDescriptions: Bool
|
||||
switch Preferences.shared.attachmentBlurMode {
|
||||
case .useStatusSetting:
|
||||
includeDescriptions = !Preferences.shared.blurMediaBehindContentWarning || status.spoilerText.isEmpty
|
||||
case .always:
|
||||
includeDescriptions = true
|
||||
case .never:
|
||||
includeDescriptions = false
|
||||
}
|
||||
if includeDescriptions {
|
||||
if status.attachments.count == 1 {
|
||||
let attachment = status.attachments[0]
|
||||
let desc = attachment.description?.isEmpty == false ? attachment.description! : "no description"
|
||||
str += AttributedString(", attachment \(index + 1): \(desc)")
|
||||
str += AttributedString(", attachment: \(desc)")
|
||||
} else {
|
||||
for (index, attachment) in status.attachments.enumerated() {
|
||||
let desc = attachment.description?.isEmpty == false ? attachment.description! : "no description"
|
||||
str += AttributedString(", attachment \(index + 1): \(desc)")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
str += AttributedString(", \(status.attachments.count) attachment\(status.attachments.count == 1 ? "" : "s")")
|
||||
}
|
||||
}
|
||||
if status.poll != nil {
|
||||
|
|
|
@ -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 {
|
||||
|
@ -271,15 +271,28 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell {
|
|||
str += AttributedString(contentTextView.attributedText)
|
||||
|
||||
if status.attachments.count > 0 {
|
||||
if status.attachments.count == 1 {
|
||||
let attachment = status.attachments[0]
|
||||
let desc = attachment.description?.isEmpty == false ? attachment.description! : "no description"
|
||||
str += AttributedString(", attachment: \(desc)")
|
||||
} else {
|
||||
for (index, attachment) in status.attachments.enumerated() {
|
||||
let includeDescriptions: Bool
|
||||
switch Preferences.shared.attachmentBlurMode {
|
||||
case .useStatusSetting:
|
||||
includeDescriptions = !Preferences.shared.blurMediaBehindContentWarning || status.spoilerText.isEmpty
|
||||
case .always:
|
||||
includeDescriptions = true
|
||||
case .never:
|
||||
includeDescriptions = false
|
||||
}
|
||||
if includeDescriptions {
|
||||
if status.attachments.count == 1 {
|
||||
let attachment = status.attachments[0]
|
||||
let desc = attachment.description?.isEmpty == false ? attachment.description! : "no description"
|
||||
str += AttributedString(", attachment \(index + 1): \(desc)")
|
||||
str += AttributedString(", attachment: \(desc)")
|
||||
} else {
|
||||
for (index, attachment) in status.attachments.enumerated() {
|
||||
let desc = attachment.description?.isEmpty == false ? attachment.description! : "no description"
|
||||
str += AttributedString(", attachment \(index + 1): \(desc)")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
str += AttributedString(", \(status.attachments.count) attachment\(status.attachments.count == 1 ? "" : "s")")
|
||||
}
|
||||
}
|
||||
if status.poll != nil {
|
||||
|
|
Loading…
Reference in New Issue