From ae12c838bd228a50bc572bd7f02e99f08430ec46 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sat, 16 Nov 2024 12:08:45 -0500 Subject: [PATCH] Change how room avatars are passed, fix friend avatars not loading The problem lies in how media URLs work, in this case it the old NeoChatRoom::avatarMediaId could pass a mxc url *or* a path that can be put into root.connection.makeMediaUrl. So normal rooms with avatars loaded, but never friends because room members gave the mxc URL. Instead, change everything to use avatarMediaUrl which corrects this issue by always passing a mxc URL to QML. This also removes the need to call makeMediaUrl. Fixes #675 (cherry picked from commit 6b797952299288f062900c8efdeb47f40a34b5cf) --- src/models/roomlistmodel.cpp | 2 +- src/models/roomtreemodel.cpp | 2 +- src/neochatroom.cpp | 6 +++--- src/neochatroom.h | 6 +++--- src/qml/CollapsedRoomDelegate.qml | 4 ++-- src/qml/ContextMenu.qml | 2 +- src/qml/DirectChatDrawerHeader.qml | 2 +- src/qml/GroupChatDrawerHeader.qml | 4 ++-- src/qml/RoomDelegate.qml | 4 ++-- src/qml/SpaceDrawer.qml | 4 ++-- src/qml/SpaceListContextMenu.qml | 2 +- src/settings/RoomGeneralPage.qml | 2 +- 12 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/models/roomlistmodel.cpp b/src/models/roomlistmodel.cpp index 03f4a72a1..6e4db5c33 100644 --- a/src/models/roomlistmodel.cpp +++ b/src/models/roomlistmodel.cpp @@ -212,7 +212,7 @@ QVariant RoomListModel::data(const QModelIndex &index, int role) const return room->displayName().toHtmlEscaped(); } if (role == AvatarRole) { - return room->avatarMediaId(); + return room->avatarMediaUrl(); } if (role == CanonicalAliasRole) { return room->canonicalAlias(); diff --git a/src/models/roomtreemodel.cpp b/src/models/roomtreemodel.cpp index 574033e60..0742c7988 100644 --- a/src/models/roomtreemodel.cpp +++ b/src/models/roomtreemodel.cpp @@ -324,7 +324,7 @@ QVariant RoomTreeModel::data(const QModelIndex &index, int role) const return room->displayName(); } if (role == AvatarRole) { - return room->avatarMediaId(); + return room->avatarMediaUrl(); } if (role == CanonicalAliasRole) { return room->canonicalAlias(); diff --git a/src/neochatroom.cpp b/src/neochatroom.cpp index 3d4343069..d8ef7aac0 100644 --- a/src/neochatroom.cpp +++ b/src/neochatroom.cpp @@ -431,9 +431,9 @@ QDateTime NeoChatRoom::lastActiveTime() return messageEvents().rbegin()->get()->originTimestamp(); } -QString NeoChatRoom::avatarMediaId() const +QUrl NeoChatRoom::avatarMediaUrl() const { - if (const auto avatar = Room::avatarMediaId(); !avatar.isEmpty()) { + if (const auto avatar = Room::avatarUrl(); !avatar.isEmpty()) { return avatar; } @@ -441,7 +441,7 @@ QString NeoChatRoom::avatarMediaId() const const auto directChatMembers = this->directChatMembers(); for (const auto member : directChatMembers) { if (member != localMember()) { - return member.avatarMediaId(); + return member.avatarUrl(); } } diff --git a/src/neochatroom.h b/src/neochatroom.h index cfbacecd7..849ca5707 100644 --- a/src/neochatroom.h +++ b/src/neochatroom.h @@ -69,9 +69,9 @@ class NeoChatRoom : public Quotient::Room Q_PROPERTY(bool readMarkerLoaded READ readMarkerLoaded NOTIFY readMarkerLoadedChanged) /** - * @brief The avatar image to be used for the room. + * @brief The avatar image to be used for the room, as a mxc:// URL. */ - Q_PROPERTY(QString avatarMediaId READ avatarMediaId NOTIFY avatarChanged STORED false) + Q_PROPERTY(QUrl avatarMediaUrl READ avatarMediaUrl NOTIFY avatarChanged STORED false) /** * @brief Get a RoomMember object for the other person in a direct chat. @@ -320,7 +320,7 @@ public: [[nodiscard]] bool readMarkerLoaded() const; - [[nodiscard]] QString avatarMediaId() const; + [[nodiscard]] QUrl avatarMediaUrl() const; NeochatRoomMember *directChatRemoteMember(); diff --git a/src/qml/CollapsedRoomDelegate.qml b/src/qml/CollapsedRoomDelegate.qml index 0c59ca75d..33c0be854 100644 --- a/src/qml/CollapsedRoomDelegate.qml +++ b/src/qml/CollapsedRoomDelegate.qml @@ -18,7 +18,7 @@ QQC2.ItemDelegate { required property NeoChatRoom currentRoom required property bool categoryVisible required property string filterText - required property string avatar + required property url avatar required property string displayName topPadding: Kirigami.Units.largeSpacing @@ -32,7 +32,7 @@ QQC2.ItemDelegate { visible: root.categoryVisible || filterText.length > 0 contentItem: KirigamiComponents.Avatar { - source: root.avatar ? root.currentRoom.connection.makeMediaUrl("mxc://" + root.avatar) : "" + source: root.avatar name: root.displayName sourceSize { diff --git a/src/qml/ContextMenu.qml b/src/qml/ContextMenu.qml index bff25c285..cc48376a5 100644 --- a/src/qml/ContextMenu.qml +++ b/src/qml/ContextMenu.qml @@ -163,7 +163,7 @@ Loader { spacing: Kirigami.Units.largeSpacing KirigamiComponents.Avatar { id: avatar - source: room.avatarMediaId ? root.connection.makeMediaUrl("mxc://" + room.avatarMediaId) : "" + source: room.avatarMediaUrl name: room.displayName Layout.preferredWidth: Kirigami.Units.gridUnit * 3 Layout.preferredHeight: Kirigami.Units.gridUnit * 3 diff --git a/src/qml/DirectChatDrawerHeader.qml b/src/qml/DirectChatDrawerHeader.qml index a0873fd16..9c433d130 100644 --- a/src/qml/DirectChatDrawerHeader.qml +++ b/src/qml/DirectChatDrawerHeader.qml @@ -38,7 +38,7 @@ ColumnLayout { contentItem: KirigamiComponents.Avatar { name: root.room ? root.room.displayName : "" - source: root.room ? root.room.connection.makeMediaUrl("mxc://" + root.room.avatarMediaId) : "" + source: root.room ? root.room.avatarMediaUrl : "" Rectangle { visible: root.room.usesEncryption diff --git a/src/qml/GroupChatDrawerHeader.qml b/src/qml/GroupChatDrawerHeader.qml index a7efc13cc..6ecf96849 100644 --- a/src/qml/GroupChatDrawerHeader.qml +++ b/src/qml/GroupChatDrawerHeader.qml @@ -34,7 +34,7 @@ ColumnLayout { Layout.preferredHeight: Kirigami.Units.iconSizes.large name: root.room ? root.room.displayName : "" - source: root.room ? root.room.connection.makeMediaUrl("mxc://" + root.room.avatarMediaId) : "" + source: root.room ? root.room.avatarMediaUrl : "" Rectangle { visible: room.usesEncryption @@ -93,7 +93,7 @@ ColumnLayout { text: barcode.content, title: root.room ? root.room.displayName : "", subtitle: root.room ? root.room.id : "", - avatarSource: root.room && root.room.avatarMediaId ? root.room.connection.makeMediaUrl("mxc://" + root.room.avatarMediaId) : "" + avatarSource: root.room ? root.room.avatarMediaUrl : "" }); map.open(); } diff --git a/src/qml/RoomDelegate.qml b/src/qml/RoomDelegate.qml index 6938d814b..850eb0fed 100644 --- a/src/qml/RoomDelegate.qml +++ b/src/qml/RoomDelegate.qml @@ -21,7 +21,7 @@ Delegates.RoundedItemDelegate { required property bool hasHighlightNotifications required property NeoChatRoom currentRoom required property NeoChatConnection connection - required property string avatar + required property url avatar required property string subtitleText required property string displayName @@ -55,7 +55,7 @@ Delegates.RoundedItemDelegate { spacing: Kirigami.Units.largeSpacing AvatarNotification { - source: root.avatar ? root.connection.makeMediaUrl("mxc://" + root.avatar) : "" + source: root.avatar name: root.displayName visible: NeoChatConfig.showAvatarInRoomDrawer implicitHeight: Kirigami.Units.gridUnit + (NeoChatConfig.compactRoomList ? 0 : Kirigami.Units.largeSpacing * 2) diff --git a/src/qml/SpaceDrawer.qml b/src/qml/SpaceDrawer.qml index 239ea9d93..45b3699bc 100644 --- a/src/qml/SpaceDrawer.qml +++ b/src/qml/SpaceDrawer.qml @@ -182,7 +182,7 @@ QQC2.Control { id: spaceDelegate required property string displayName - required property string avatar + required property url avatar required property string roomId required property var currentRoom @@ -191,7 +191,7 @@ QQC2.Control { Layout.maximumHeight: width - Kirigami.Units.smallSpacing text: displayName - source: avatar ? root.connection.makeMediaUrl("mxc://" + avatar) : "" + source: avatar notificationCount: spaceDelegate.currentRoom.childrenNotificationCount notificationHighlight: spaceDelegate.currentRoom.childrenHaveHighlightNotifications diff --git a/src/qml/SpaceListContextMenu.qml b/src/qml/SpaceListContextMenu.qml index b004677e0..4da64acdd 100644 --- a/src/qml/SpaceListContextMenu.qml +++ b/src/qml/SpaceListContextMenu.qml @@ -96,7 +96,7 @@ Loader { KirigamiComponents.Avatar { id: avatar - source: room.avatarMediaId ? root.room.connection.makeMediaUrl("mxc://" + room.avatarMediaId) : "" + source: room.avatarMediaUrl Layout.preferredWidth: Kirigami.Units.gridUnit * 3 Layout.preferredHeight: Kirigami.Units.gridUnit * 3 Layout.alignment: Qt.AlignTop diff --git a/src/settings/RoomGeneralPage.qml b/src/settings/RoomGeneralPage.qml index eb70ef665..66435f111 100644 --- a/src/settings/RoomGeneralPage.qml +++ b/src/settings/RoomGeneralPage.qml @@ -26,7 +26,7 @@ FormCard.FormCardPage { Layout.alignment: Qt.AlignHCenter Layout.topMargin: Kirigami.Units.gridUnit name: room.name - source: room.avatarMediaId ? root.connection.makeMediaUrl("mxc://" + room.avatarMediaId) : "" + source: room.avatarMediaUrl implicitWidth: Kirigami.Units.iconSizes.enormous implicitHeight: Kirigami.Units.iconSizes.enormous