Texthandler edited
Move the handling of adding whether the message has been edited to texthandler.
This commit is contained in:
@@ -57,7 +57,6 @@ QHash<int, QByteArray> MessageEventModel::roleNames() const
|
||||
roles[ReadMarkersStringRole] = "readMarkersString";
|
||||
roles[ShowReadMarkersRole] = "showReadMarkers";
|
||||
roles[ReactionRole] = "reaction";
|
||||
roles[IsEditedRole] = "isEdited";
|
||||
roles[SourceRole] = "source";
|
||||
roles[MimeTypeRole] = "mimeType";
|
||||
roles[FormattedBodyRole] = "formattedBody";
|
||||
@@ -662,14 +661,6 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
|
||||
return EventStatus::Normal;
|
||||
}
|
||||
|
||||
if (role == IsEditedRole) {
|
||||
if (auto e = eventCast<const RoomMessageEvent>(&evt)) {
|
||||
return !e->unsignedJson().isEmpty() && e->unsignedJson().contains("m.relations")
|
||||
&& e->unsignedJson()["m.relations"].toObject().contains("m.replace");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (role == EventIdRole) {
|
||||
return !evt.id().isEmpty() ? evt.id() : evt.transactionId();
|
||||
}
|
||||
|
||||
@@ -63,7 +63,6 @@ public:
|
||||
ShowReadMarkersRole, /**< bool with whether there are any other user read markers to be shown. */
|
||||
ReactionRole,
|
||||
|
||||
IsEditedRole,
|
||||
SourceRole,
|
||||
MediaUrlRole,
|
||||
// For debugging
|
||||
|
||||
@@ -96,7 +96,6 @@ Item {
|
||||
RichLabel {
|
||||
textMessage: reply.display
|
||||
textFormat: Text.RichText
|
||||
isReplyLabel: true
|
||||
|
||||
HoverHandler {
|
||||
enabled: !hoveredLink
|
||||
|
||||
@@ -14,7 +14,6 @@ TextEdit {
|
||||
readonly property var isEmoji: /^(<span style='.*'>)?(\u00a9|\u00ae|[\u20D0-\u2fff]|[\u3190-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])+(<\/span>)?$/
|
||||
readonly property var hasSpoiler: /data-mx-spoiler/g
|
||||
|
||||
property bool isReplyLabel: false
|
||||
property string textMessage: model.display
|
||||
property bool spoilerRevealed: !hasSpoiler.test(textMessage)
|
||||
|
||||
@@ -59,7 +58,7 @@ a{
|
||||
background: " + Kirigami.Theme.textColor + ";
|
||||
}
|
||||
" : "") + "
|
||||
</style>" + textMessage + (isEdited && !contentLabel.isReplyLabel ? (" <span style=\"color: " + Kirigami.Theme.disabledTextColor + "\">" + "<span style='font-size: " + Kirigami.Theme.defaultFont.pixelSize +"px'>" + i18n(" (edited)") + "</span>") : "")
|
||||
</style>" + textMessage
|
||||
|
||||
color: Kirigami.Theme.textColor
|
||||
selectedTextColor: Kirigami.Theme.highlightedTextColor
|
||||
|
||||
@@ -7,10 +7,13 @@
|
||||
#include <QUrl>
|
||||
|
||||
#include <events/roommessageevent.h>
|
||||
#include <qstringliteral.h>
|
||||
#include <util.h>
|
||||
|
||||
#include <cmark.h>
|
||||
|
||||
#include <Kirigami/PlatformTheme>
|
||||
|
||||
static const QStringList allowedTags = {
|
||||
QStringLiteral("font"), QStringLiteral("del"), QStringLiteral("h1"), QStringLiteral("h2"), QStringLiteral("h3"), QStringLiteral("h4"),
|
||||
QStringLiteral("h5"), QStringLiteral("h6"), QStringLiteral("blockquote"), QStringLiteral("p"), QStringLiteral("a"), QStringLiteral("ul"),
|
||||
@@ -150,6 +153,31 @@ QString TextHandler::handleRecieveRichText(Qt::TextFormat inputFormat, const Neo
|
||||
}
|
||||
}
|
||||
|
||||
if (auto e = eventCast<const Quotient::RoomMessageEvent>(event)) {
|
||||
bool isEdited =
|
||||
!e->unsignedJson().isEmpty() && e->unsignedJson().contains("m.relations") && e->unsignedJson()["m.relations"].toObject().contains("m.replace");
|
||||
if (isEdited) {
|
||||
Kirigami::PlatformTheme *theme = static_cast<Kirigami::PlatformTheme *>(qmlAttachedPropertiesObject<Kirigami::PlatformTheme>(this, true));
|
||||
|
||||
QString editTextColor;
|
||||
if (theme != nullptr) {
|
||||
editTextColor = theme->disabledTextColor().name();
|
||||
} else {
|
||||
editTextColor = QStringLiteral("#000000");
|
||||
}
|
||||
QString editedString = QStringLiteral(" <span style=\"color:") + editTextColor + QStringLiteral("\">(edited)</span>");
|
||||
if (outputString.endsWith(QStringLiteral("</p>"))) {
|
||||
outputString.insert(outputString.length() - 4, editedString);
|
||||
} else if (outputString.endsWith(QStringLiteral("</pre>")) || outputString.endsWith(QStringLiteral("</blockquote>"))
|
||||
|| outputString.endsWith(QStringLiteral("</table>")) || outputString.endsWith(QStringLiteral("</ol>"))
|
||||
|| outputString.endsWith(QStringLiteral("</ul>"))) {
|
||||
outputString.append("<p>" + editedString + "</p>");
|
||||
} else {
|
||||
outputString.append(editedString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace <del> with <s>
|
||||
* Note: <s> is still not a valid tag for the message from the server. We
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <QHash>
|
||||
#include <QObject>
|
||||
#include <QRegularExpression>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
@@ -39,8 +40,10 @@ static const QRegularExpression mxId(QStringLiteral(R"((^|[][[:space:](){}`'";])
|
||||
* be present as per the matrix spec
|
||||
* (https://spec.matrix.org/v1.5/client-server-api/#mroommessage-msgtypes).
|
||||
*/
|
||||
class TextHandler
|
||||
class TextHandler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief List of token types
|
||||
|
||||
Reference in New Issue
Block a user