summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorJoe Donofry <rubberduckie3554@gmail.com>2021-11-29 00:59:57 +0000
committerNicolas Werner <nicolas.werner@hotmail.de>2021-11-29 00:59:57 +0000
commitb920f8d7cab932a8a4afa967ebd0a67ded865da8 (patch)
tree0f78fe8cfaa52d0240ea7edd13eb3ca865bd9503 /src
parentIf the locale is set to C, force english locale (diff)
downloadnheko-b920f8d7cab932a8a4afa967ebd0a67ded865da8.tar.xz
Change QML UI for redactions
Diffstat (limited to 'src')
-rw-r--r--src/timeline/TimelineModel.cpp37
-rw-r--r--src/timeline/TimelineModel.h2
2 files changed, 39 insertions, 0 deletions
diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp

index 4a81b243..79d6883f 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp
@@ -17,6 +17,7 @@ #include <QRegularExpression> #include <QSettings> #include <QStandardPaths> +#include <QVariant> #include "Cache_p.h" #include "ChatPage.h" @@ -1797,6 +1798,42 @@ TimelineModel::formatPowerLevelEvent(QString id) return tr("%1 has changed the room's permissions.").arg(name); } +QVariantMap +TimelineModel::formatRedactedEvent(QString id) +{ + QVariantMap pair{{"first", ""}, {"second", ""}}; + mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), ""); + if (!e) + return pair; + + auto event = std::get_if<mtx::events::RoomEvent<mtx::events::msg::Redacted>>(e); + if (!event) + return pair; + + QString dateTime = QDateTime::fromMSecsSinceEpoch(event->origin_server_ts).toString(); + QString reason = ""; + auto because = event->unsigned_data.redacted_because; + // User info about who actually sent the redacted event. + QString redactedUser = QString::fromStdString(because->sender).toHtmlEscaped(); + QString redactedName = utils::replaceEmoji(displayName(redactedUser)); + + if (because.has_value()) { + reason = QString::fromStdString(because->content.reason).toHtmlEscaped(); + } + + if (reason.isEmpty()) { + pair["first"] = tr("Removed by %1").arg(redactedName); + pair["second"] = + tr("%1 (%2) removed this message at %3").arg(redactedName, redactedUser, dateTime); + } else { + pair["first"] = tr("Removed by %1 because: %2").arg(redactedName, reason); + pair["second"] = tr("%1 (%2) removed this message at %3\nReason: %4") + .arg(redactedName, redactedUser, dateTime, reason); + } + + return pair; +} + void TimelineModel::acceptKnock(QString id) { diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h
index af067476..fe09af75 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h
@@ -10,6 +10,7 @@ #include <QHash> #include <QSet> #include <QTimer> +#include <QVariant> #include <mtxclient/http/errors.hpp> @@ -247,6 +248,7 @@ public: Q_INVOKABLE QString formatHistoryVisibilityEvent(QString id); Q_INVOKABLE QString formatGuestAccessEvent(QString id); Q_INVOKABLE QString formatPowerLevelEvent(QString id); + Q_INVOKABLE QVariantMap formatRedactedEvent(QString id); Q_INVOKABLE void viewRawMessage(QString id); Q_INVOKABLE void forwardMessage(QString eventId, QString roomId);