Always pass displayName without matrix id to avatar name

BUG: 456638
This commit is contained in:
Tobias Fella
2022-10-23 17:44:53 +02:00
parent a287e61b5a
commit 10667f98ef
4 changed files with 11 additions and 2 deletions

View File

@@ -73,7 +73,7 @@ Control {
Layout.preferredHeight: Kirigami.Units.iconSizes.small
Layout.alignment: Qt.AlignTop
name: author.displayName
name: model.displayNameForInitials
source: author.avatarMediaId ? ("image://mxc/" + author.avatarMediaId) : ""
color: author.color

View File

@@ -140,7 +140,7 @@ QQC2.ItemDelegate {
visible: model.showAuthor &&
Config.showAvatarInTimeline &&
(Config.compactLayout || !showUserMessageOnRight)
name: model.author.name ?? model.author.displayName
name: model.displayNameForInitials
source: visible && model.author.avatarMediaId ? ("image://mxc/" + model.author.avatarMediaId) : ""
color: model.author.color

View File

@@ -59,6 +59,7 @@ QHash<int, QByteArray> MessageEventModel::roleNames() const
roles[AuthorIdRole] = "authorId";
roles[MediaUrlRole] = "mediaUrl";
roles[VerifiedRole] = "verified";
roles[DisplayNameForInitialsRole] = "displayNameForInitials";
return roles;
}
@@ -834,6 +835,11 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
#endif
}
if (role == DisplayNameForInitialsRole) {
auto user = static_cast<NeoChatUser *>(isPending ? m_currentRoom->localUser() : m_currentRoom->user(evt.senderId()));
return user->displayname(m_currentRoom).remove(QStringLiteral(" (%1)").arg(user->id()));
}
return {};
}

View File

@@ -48,6 +48,9 @@ public:
EventResolvedTypeRole,
AuthorIdRole,
VerifiedRole,
// Sender's displayname, always without the matrix id
DisplayNameForInitialsRole,
LastRole, // Keep this last
};
Q_ENUM(EventRoles)