From f3d956aebcd34ecf8c4e2c44acd39d5de380233f Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sat, 22 May 2021 10:16:42 +0200 Subject: [PATCH] Fix emoji in new RoomList --- resources/qml/ElidedLabel.qml | 2 +- resources/qml/RoomList.qml | 2 ++ src/timeline/RoomlistModel.cpp | 2 +- src/timeline/TimelineModel.cpp | 11 +++++++++++ src/timeline/TimelineModel.h | 1 + src/timeline/TimelineViewManager.h | 1 + 6 files changed, 17 insertions(+), 2 deletions(-) diff --git a/resources/qml/ElidedLabel.qml b/resources/qml/ElidedLabel.qml index 5ae99de7..1f4aeeea 100644 --- a/resources/qml/ElidedLabel.qml +++ b/resources/qml/ElidedLabel.qml @@ -13,7 +13,7 @@ Label { property alias elideWidth: metrics.elideWidth color: Nheko.colors.text - text: metrics.elidedText + text: (textFormat == Text.PlainText) ? metrics.elidedText : TimelineManager.escapeEmoji(TimelineManager.htmlEscape(metrics.elidedText)) maximumLineCount: 1 elide: Text.ElideRight textFormat: Text.PlainText diff --git a/resources/qml/RoomList.qml b/resources/qml/RoomList.qml index f2a957c9..89af78a5 100644 --- a/resources/qml/RoomList.qml +++ b/resources/qml/RoomList.qml @@ -119,6 +119,7 @@ Page { color: roomItem.importantText elideWidth: textContent.width - timestamp.width - Nheko.paddingMedium fullText: model.roomName + textFormat: Text.RichText } Item { @@ -146,6 +147,7 @@ Page { font.pixelSize: fontMetrics.font.pixelSize * 0.9 elideWidth: textContent.width - (notificationBubble.visible ? notificationBubble.width : 0) - Nheko.paddingSmall fullText: model.lastMessage + textFormat: Text.RichText } Item { diff --git a/src/timeline/RoomlistModel.cpp b/src/timeline/RoomlistModel.cpp index afe9679a..6d741322 100644 --- a/src/timeline/RoomlistModel.cpp +++ b/src/timeline/RoomlistModel.cpp @@ -62,7 +62,7 @@ RoomlistModel::data(const QModelIndex &index, int role) const case Roles::AvatarUrl: return room->roomAvatarUrl(); case Roles::RoomName: - return room->roomName(); + return room->plainRoomName(); case Roles::RoomId: return room->roomId(); case Roles::LastMessage: diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 2625127c..8f4a8564 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -1890,6 +1890,17 @@ TimelineModel::roomName() const QString::fromStdString(info[room_id_].name).toHtmlEscaped()); } +QString +TimelineModel::plainRoomName() const +{ + auto info = cache::getRoomInfo({room_id_.toStdString()}); + + if (!info.count(room_id_)) + return ""; + else + return QString::fromStdString(info[room_id_].name); +} + QString TimelineModel::roomAvatarUrl() const { diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index b3d3b663..3ebbe120 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -307,6 +307,7 @@ public slots: } QString roomName() const; + QString plainRoomName() const; QString roomTopic() const; InputBar *input() { return &input_; } Permissions *permissions() { return &permissions_; } diff --git a/src/timeline/TimelineViewManager.h b/src/timeline/TimelineViewManager.h index f4297243..609f5a4a 100644 --- a/src/timeline/TimelineViewManager.h +++ b/src/timeline/TimelineViewManager.h @@ -67,6 +67,7 @@ public: Q_INVOKABLE void openImageOverlay(QString mxcUrl, QString eventId); Q_INVOKABLE QColor userColor(QString id, QColor background); Q_INVOKABLE QString escapeEmoji(QString str) const; + Q_INVOKABLE QString htmlEscape(QString str) const { return str.toHtmlEscaped(); } Q_INVOKABLE QString userPresence(QString id) const; Q_INVOKABLE QString userStatus(QString id) const;