From 10667f98efabc6a7219139c217f79f161bc9c283 Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Sun, 23 Oct 2022 17:44:53 +0200 Subject: [PATCH] Always pass displayName without matrix id to avatar name BUG: 456638 --- imports/NeoChat/Component/Timeline/StateDelegate.qml | 2 +- imports/NeoChat/Component/Timeline/TimelineContainer.qml | 2 +- src/messageeventmodel.cpp | 6 ++++++ src/messageeventmodel.h | 3 +++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/imports/NeoChat/Component/Timeline/StateDelegate.qml b/imports/NeoChat/Component/Timeline/StateDelegate.qml index 595e00800..f54c3a92b 100644 --- a/imports/NeoChat/Component/Timeline/StateDelegate.qml +++ b/imports/NeoChat/Component/Timeline/StateDelegate.qml @@ -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 diff --git a/imports/NeoChat/Component/Timeline/TimelineContainer.qml b/imports/NeoChat/Component/Timeline/TimelineContainer.qml index ce0f90081..5f3e38b1d 100644 --- a/imports/NeoChat/Component/Timeline/TimelineContainer.qml +++ b/imports/NeoChat/Component/Timeline/TimelineContainer.qml @@ -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 diff --git a/src/messageeventmodel.cpp b/src/messageeventmodel.cpp index 84369939a..b73b9c6b2 100644 --- a/src/messageeventmodel.cpp +++ b/src/messageeventmodel.cpp @@ -59,6 +59,7 @@ QHash 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(isPending ? m_currentRoom->localUser() : m_currentRoom->user(evt.senderId())); + return user->displayname(m_currentRoom).remove(QStringLiteral(" (%1)").arg(user->id())); + } + return {}; } diff --git a/src/messageeventmodel.h b/src/messageeventmodel.h index 3fd1f5b3d..b371ffad9 100644 --- a/src/messageeventmodel.h +++ b/src/messageeventmodel.h @@ -48,6 +48,9 @@ public: EventResolvedTypeRole, AuthorIdRole, VerifiedRole, + + // Sender's displayname, always without the matrix id + DisplayNameForInitialsRole, LastRole, // Keep this last }; Q_ENUM(EventRoles)