Move displayName logic to TalkActor

Signed-off-by: Marcel Müller <marcel-mueller@gmx.de>
This commit is contained in:
Marcel Müller 2024-08-08 18:34:16 +02:00
Родитель 3d43372a39
Коммит 09abd4e188
2 изменённых файлов: 26 добавлений и 20 удалений

Просмотреть файл

@ -144,12 +144,7 @@ class BaseChatTableViewCell: UITableViewCell, ReactionsViewDelegate {
self.dateLabel.text = NCUtils.getTime(fromDate: date)
let messageActor = message.actor
let titleLabel = messageActor.displayNameProcessed.withTextColor(.secondaryLabel)
if let remoteServer = messageActor.cloudId {
let remoteServerString = " (\(String(remoteServer)))"
titleLabel.append(remoteServerString.withTextColor(.tertiaryLabel))
}
let titleLabel = messageActor.attributedDisplayName
if let lastEditActorDisplayName = message.lastEditActorDisplayName, message.lastEditTimestamp > 0 {
var editedString = ""
@ -186,14 +181,7 @@ class BaseChatTableViewCell: UITableViewCell, ReactionsViewDelegate {
let quoteString = parent.parsedMarkdownForChat()?.string ?? ""
self.quotedMessageView?.messageLabel.text = quoteString
var parentActorDisplayName = parent.actorDisplayName ?? ""
if parentActorDisplayName.isEmpty {
parentActorDisplayName = NSLocalizedString("Guest", comment: "")
}
self.quotedMessageView?.actorLabel.text = parentActorDisplayName
self.quotedMessageView?.actorLabel.attributedText = parent.actor.attributedDisplayName
self.quotedMessageView?.highlighted = parent.isMessage(from: activeAccount.userId)
self.quotedMessageView?.avatarView.setActorAvatar(forMessage: parent)
}

Просмотреть файл

@ -4,29 +4,47 @@
//
import Foundation
import SwiftyAttributes
@objcMembers public class TalkActor: NSObject {
public var id: String?
public var type: String?
public var displayName: String
public var displayNameProcessed: String {
if displayName.isEmpty {
if id == "deleted_users", type == "deleted_users" {
/// Contains the raw displayName that was used to create the TalkActor
public var rawDisplayName: String
/// Takes deleted users and guests into account and returns the correct displayName
/// Does **not** append a potential `cloudId`
public var displayName: String {
if rawDisplayName.isEmpty {
if isDeleted {
return NSLocalizedString("Deleted user", comment: "")
} else {
return NSLocalizedString("Guest", comment: "")
}
}
return displayName
return rawDisplayName
}
/// Takes deleted users and guests into account and returns it as `secondaryLabel`
/// This also appends a potential `cloudId` as `tertiaryLabel` in parentheses
public var attributedDisplayName: NSMutableAttributedString {
let titleLabel = displayName.withTextColor(.secondaryLabel)
if let remoteServer = cloudId {
let remoteServerString = " (\(String(remoteServer)))"
titleLabel.append(remoteServerString.withTextColor(.tertiaryLabel))
}
return titleLabel
}
init(actorId: String? = nil, actorType: String? = nil, actorDisplayName: String? = nil) {
self.id = actorId
self.type = actorType
self.displayName = actorDisplayName ?? ""
self.rawDisplayName = actorDisplayName ?? ""
}
public var isDeleted: Bool {