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 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/timeline/TimelineModel.cpp') 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) { -- cgit 1.5.1