From b920f8d7cab932a8a4afa967ebd0a67ded865da8 Mon Sep 17 00:00:00 2001 From: Joe Donofry Date: Mon, 29 Nov 2021 00:59:57 +0000 Subject: Change QML UI for redactions --- src/timeline/TimelineModel.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/timeline/TimelineModel.h | 2 ++ 2 files changed, 39 insertions(+) (limited to 'src') 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 #include #include +#include #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>(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 #include #include +#include #include @@ -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); -- cgit 1.5.1