diff --git a/src/models/reactionmodel.cpp b/src/models/reactionmodel.cpp index 87107d3ce..b4f8cab9d 100644 --- a/src/models/reactionmodel.cpp +++ b/src/models/reactionmodel.cpp @@ -80,7 +80,7 @@ QVariant ReactionModel::data(const QModelIndex &index, int role) const "%2 reacted with %3", reaction.authors.count(), text, - reactionText(reaction.reaction)); + m_shortcodes.contains(reaction.reaction) ? m_shortcodes[reaction.reaction] : reactionText(reaction.reaction)); return text; } @@ -111,6 +111,7 @@ void ReactionModel::updateReactions() beginResetModel(); m_reactions.clear(); + m_shortcodes.clear(); const auto &annotations = m_room->relatedEvents(*m_event, Quotient::EventRelation::AnnotationType); if (annotations.isEmpty()) { @@ -125,6 +126,9 @@ void ReactionModel::updateReactions() } if (const auto &e = eventCast(a)) { reactions[e->key()].append(m_room->user(e->senderId())); + if (e->contentJson()[QStringLiteral("shortcode")].toString().length()) { + m_shortcodes[e->key()] = e->contentJson()[QStringLiteral("shortcode")].toString().toHtmlEscaped(); + } } } @@ -158,8 +162,18 @@ QHash ReactionModel::roleNames() const }; } -QString ReactionModel::reactionText(const QString &text) +QString ReactionModel::reactionText(QString text) const { + text = text.toHtmlEscaped(); + if (text.startsWith(QStringLiteral("mxc://"))) { + static QFont font; + static int size = font.pixelSize(); + if (size == -1) { + size = font.pointSizeF() * 1.333; + } + return QStringLiteral("") + .arg(m_room->connection()->makeMediaUrl(QUrl(text)).toString(), QString::number(size)); + } const auto isEmoji = [](const QString &text) { #ifdef HAVE_ICU QTextBoundaryFinder finder(QTextBoundaryFinder::Grapheme, text); diff --git a/src/models/reactionmodel.h b/src/models/reactionmodel.h index 09b31355d..a80bfa467 100644 --- a/src/models/reactionmodel.h +++ b/src/models/reactionmodel.h @@ -71,8 +71,9 @@ private: const NeoChatRoom *m_room; const Quotient::RoomMessageEvent *m_event; QList m_reactions; + QMap m_shortcodes; void updateReactions(); - static QString reactionText(const QString &text); + QString reactionText(QString text) const; }; Q_DECLARE_METATYPE(ReactionModel *) diff --git a/src/qml/ReactionDelegate.qml b/src/qml/ReactionDelegate.qml index 293fc18fe..2c7156a05 100644 --- a/src/qml/ReactionDelegate.qml +++ b/src/qml/ReactionDelegate.qml @@ -39,14 +39,17 @@ Flow { width: Math.max(contentItem.implicitWidth + leftPadding + rightPadding, height) height: Math.round(Kirigami.Units.gridUnit * 1.5) - contentItem: QQC2.Label { - id: reactionLabel - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - text: reactionDelegate.textContent - background: null - wrapMode: TextEdit.NoWrap - textFormat: Text.RichText + contentItem: Item { + QQC2.Label { + id: reactionLabel + anchors.centerIn: parent + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + text: reactionDelegate.textContent + background: null + wrapMode: TextEdit.NoWrap + textFormat: Text.RichText + } } padding: Kirigami.Units.smallSpacing @@ -66,6 +69,7 @@ Flow { hoverEnabled: true + QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay QQC2.ToolTip.visible: hovered QQC2.ToolTip.text: reactionDelegate.toolTip }