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 6b79795229)
This commit is contained in:
Joshua Goins
2024-11-16 12:08:45 -05:00
parent 51727dd345
commit ae12c838bd
12 changed files with 20 additions and 20 deletions

View File

@@ -212,7 +212,7 @@ QVariant RoomListModel::data(const QModelIndex &index, int role) const
return room->displayName().toHtmlEscaped(); return room->displayName().toHtmlEscaped();
} }
if (role == AvatarRole) { if (role == AvatarRole) {
return room->avatarMediaId(); return room->avatarMediaUrl();
} }
if (role == CanonicalAliasRole) { if (role == CanonicalAliasRole) {
return room->canonicalAlias(); return room->canonicalAlias();

View File

@@ -324,7 +324,7 @@ QVariant RoomTreeModel::data(const QModelIndex &index, int role) const
return room->displayName(); return room->displayName();
} }
if (role == AvatarRole) { if (role == AvatarRole) {
return room->avatarMediaId(); return room->avatarMediaUrl();
} }
if (role == CanonicalAliasRole) { if (role == CanonicalAliasRole) {
return room->canonicalAlias(); return room->canonicalAlias();

View File

@@ -431,9 +431,9 @@ QDateTime NeoChatRoom::lastActiveTime()
return messageEvents().rbegin()->get()->originTimestamp(); 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; return avatar;
} }
@@ -441,7 +441,7 @@ QString NeoChatRoom::avatarMediaId() const
const auto directChatMembers = this->directChatMembers(); const auto directChatMembers = this->directChatMembers();
for (const auto member : directChatMembers) { for (const auto member : directChatMembers) {
if (member != localMember()) { if (member != localMember()) {
return member.avatarMediaId(); return member.avatarUrl();
} }
} }

View File

@@ -69,9 +69,9 @@ class NeoChatRoom : public Quotient::Room
Q_PROPERTY(bool readMarkerLoaded READ readMarkerLoaded NOTIFY readMarkerLoadedChanged) 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. * @brief Get a RoomMember object for the other person in a direct chat.
@@ -320,7 +320,7 @@ public:
[[nodiscard]] bool readMarkerLoaded() const; [[nodiscard]] bool readMarkerLoaded() const;
[[nodiscard]] QString avatarMediaId() const; [[nodiscard]] QUrl avatarMediaUrl() const;
NeochatRoomMember *directChatRemoteMember(); NeochatRoomMember *directChatRemoteMember();

View File

@@ -18,7 +18,7 @@ QQC2.ItemDelegate {
required property NeoChatRoom currentRoom required property NeoChatRoom currentRoom
required property bool categoryVisible required property bool categoryVisible
required property string filterText required property string filterText
required property string avatar required property url avatar
required property string displayName required property string displayName
topPadding: Kirigami.Units.largeSpacing topPadding: Kirigami.Units.largeSpacing
@@ -32,7 +32,7 @@ QQC2.ItemDelegate {
visible: root.categoryVisible || filterText.length > 0 visible: root.categoryVisible || filterText.length > 0
contentItem: KirigamiComponents.Avatar { contentItem: KirigamiComponents.Avatar {
source: root.avatar ? root.currentRoom.connection.makeMediaUrl("mxc://" + root.avatar) : "" source: root.avatar
name: root.displayName name: root.displayName
sourceSize { sourceSize {

View File

@@ -163,7 +163,7 @@ Loader {
spacing: Kirigami.Units.largeSpacing spacing: Kirigami.Units.largeSpacing
KirigamiComponents.Avatar { KirigamiComponents.Avatar {
id: avatar id: avatar
source: room.avatarMediaId ? root.connection.makeMediaUrl("mxc://" + room.avatarMediaId) : "" source: room.avatarMediaUrl
name: room.displayName name: room.displayName
Layout.preferredWidth: Kirigami.Units.gridUnit * 3 Layout.preferredWidth: Kirigami.Units.gridUnit * 3
Layout.preferredHeight: Kirigami.Units.gridUnit * 3 Layout.preferredHeight: Kirigami.Units.gridUnit * 3

View File

@@ -38,7 +38,7 @@ ColumnLayout {
contentItem: KirigamiComponents.Avatar { contentItem: KirigamiComponents.Avatar {
name: root.room ? root.room.displayName : "" name: root.room ? root.room.displayName : ""
source: root.room ? root.room.connection.makeMediaUrl("mxc://" + root.room.avatarMediaId) : "" source: root.room ? root.room.avatarMediaUrl : ""
Rectangle { Rectangle {
visible: root.room.usesEncryption visible: root.room.usesEncryption

View File

@@ -34,7 +34,7 @@ ColumnLayout {
Layout.preferredHeight: Kirigami.Units.iconSizes.large Layout.preferredHeight: Kirigami.Units.iconSizes.large
name: root.room ? root.room.displayName : "" name: root.room ? root.room.displayName : ""
source: root.room ? root.room.connection.makeMediaUrl("mxc://" + root.room.avatarMediaId) : "" source: root.room ? root.room.avatarMediaUrl : ""
Rectangle { Rectangle {
visible: room.usesEncryption visible: room.usesEncryption
@@ -93,7 +93,7 @@ ColumnLayout {
text: barcode.content, text: barcode.content,
title: root.room ? root.room.displayName : "", title: root.room ? root.room.displayName : "",
subtitle: root.room ? root.room.id : "", 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(); map.open();
} }

View File

@@ -21,7 +21,7 @@ Delegates.RoundedItemDelegate {
required property bool hasHighlightNotifications required property bool hasHighlightNotifications
required property NeoChatRoom currentRoom required property NeoChatRoom currentRoom
required property NeoChatConnection connection required property NeoChatConnection connection
required property string avatar required property url avatar
required property string subtitleText required property string subtitleText
required property string displayName required property string displayName
@@ -55,7 +55,7 @@ Delegates.RoundedItemDelegate {
spacing: Kirigami.Units.largeSpacing spacing: Kirigami.Units.largeSpacing
AvatarNotification { AvatarNotification {
source: root.avatar ? root.connection.makeMediaUrl("mxc://" + root.avatar) : "" source: root.avatar
name: root.displayName name: root.displayName
visible: NeoChatConfig.showAvatarInRoomDrawer visible: NeoChatConfig.showAvatarInRoomDrawer
implicitHeight: Kirigami.Units.gridUnit + (NeoChatConfig.compactRoomList ? 0 : Kirigami.Units.largeSpacing * 2) implicitHeight: Kirigami.Units.gridUnit + (NeoChatConfig.compactRoomList ? 0 : Kirigami.Units.largeSpacing * 2)

View File

@@ -182,7 +182,7 @@ QQC2.Control {
id: spaceDelegate id: spaceDelegate
required property string displayName required property string displayName
required property string avatar required property url avatar
required property string roomId required property string roomId
required property var currentRoom required property var currentRoom
@@ -191,7 +191,7 @@ QQC2.Control {
Layout.maximumHeight: width - Kirigami.Units.smallSpacing Layout.maximumHeight: width - Kirigami.Units.smallSpacing
text: displayName text: displayName
source: avatar ? root.connection.makeMediaUrl("mxc://" + avatar) : "" source: avatar
notificationCount: spaceDelegate.currentRoom.childrenNotificationCount notificationCount: spaceDelegate.currentRoom.childrenNotificationCount
notificationHighlight: spaceDelegate.currentRoom.childrenHaveHighlightNotifications notificationHighlight: spaceDelegate.currentRoom.childrenHaveHighlightNotifications

View File

@@ -96,7 +96,7 @@ Loader {
KirigamiComponents.Avatar { KirigamiComponents.Avatar {
id: avatar id: avatar
source: room.avatarMediaId ? root.room.connection.makeMediaUrl("mxc://" + room.avatarMediaId) : "" source: room.avatarMediaUrl
Layout.preferredWidth: Kirigami.Units.gridUnit * 3 Layout.preferredWidth: Kirigami.Units.gridUnit * 3
Layout.preferredHeight: Kirigami.Units.gridUnit * 3 Layout.preferredHeight: Kirigami.Units.gridUnit * 3
Layout.alignment: Qt.AlignTop Layout.alignment: Qt.AlignTop

View File

@@ -26,7 +26,7 @@ FormCard.FormCardPage {
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
Layout.topMargin: Kirigami.Units.gridUnit Layout.topMargin: Kirigami.Units.gridUnit
name: room.name name: room.name
source: room.avatarMediaId ? root.connection.makeMediaUrl("mxc://" + room.avatarMediaId) : "" source: room.avatarMediaUrl
implicitWidth: Kirigami.Units.iconSizes.enormous implicitWidth: Kirigami.Units.iconSizes.enormous
implicitHeight: Kirigami.Units.iconSizes.enormous implicitHeight: Kirigami.Units.iconSizes.enormous