summary refs log tree commit diff
path: root/src/timeline/TimelineModel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/timeline/TimelineModel.cpp')
-rw-r--r--src/timeline/TimelineModel.cpp37
1 files changed, 37 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) {