Change QML UI for redactions

This commit is contained in:
Joe Donofry 2021-11-29 00:59:57 +00:00 committed by Nicolas Werner
parent bd020bb473
commit b920f8d7ca
29 changed files with 1644 additions and 868 deletions

View file

@ -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)
{