Add regex to remove replies in notifications

This commit is contained in:
Loren Burkholder 2021-02-20 14:00:13 -05:00 committed by Nicolas Werner
parent c693d54598
commit 37acdad928
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
3 changed files with 16 additions and 5 deletions

View file

@ -7,6 +7,7 @@
#include <QDBusPendingReply> #include <QDBusPendingReply>
#include <QDebug> #include <QDebug>
#include <QImage> #include <QImage>
#include <QRegularExpression>
#include <QTextDocumentFragment> #include <QTextDocumentFragment>
#include <functional> #include <functional>
@ -176,9 +177,12 @@ NotificationsManager::formatNotification(const mtx::events::collections::Timelin
.replace("<em>", "<i>") .replace("<em>", "<i>")
.replace("</em>", "</i>") .replace("</em>", "</i>")
.replace("<strong>", "<b>") .replace("<strong>", "<b>")
.replace("</strong>", "</b>"); .replace("</strong>", "</b>")
.replace(QRegularExpression("(<mx-reply>.+\\<\\/mx-reply\\>)"), "");
return QTextDocumentFragment::fromHtml(mtx::accessors::formattedBodyWithFallback(e)) return QTextDocumentFragment::fromHtml(
mtx::accessors::formattedBodyWithFallback(e).replace(
QRegularExpression("(<mx-reply>.+\\<\\/mx-reply\\>)"), ""))
.toPlainText(); .toPlainText();
} }

View file

@ -1,5 +1,6 @@
#include "Manager.h" #include "Manager.h"
#include <QRegularExpression>
#include <QTextDocumentFragment> #include <QTextDocumentFragment>
#include "EventAccessors.h" #include "EventAccessors.h"
@ -8,5 +9,8 @@
QString QString
NotificationsManager::formatNotification(const mtx::events::collections::TimelineEvents &e) NotificationsManager::formatNotification(const mtx::events::collections::TimelineEvents &e)
{ {
return QTextDocumentFragment::fromHtml(mtx::accessors::formattedBodyWithFallback(e)).toPlainText(); return QTextDocumentFragment::fromHtml(
mtx::accessors::formattedBodyWithFallback(e).replace(
QRegularExpression("(<mx-reply>.+\\<\\/mx-reply\\>)"), ""))
.toPlainText();
} }

View file

@ -5,6 +5,7 @@
#include "notifications/Manager.h" #include "notifications/Manager.h"
#include "wintoastlib.h" #include "wintoastlib.h"
#include <QRegularExpression>
#include <QTextDocumentFragment> #include <QTextDocumentFragment>
#include "EventAccessors.h" #include "EventAccessors.h"
@ -80,6 +81,8 @@ NotificationsManager::removeNotification(const QString &, const QString &)
QString QString
NotificationsManager::formatNotification(const mtx::events::collections::TimelineEvents &e) NotificationsManager::formatNotification(const mtx::events::collections::TimelineEvents &e)
{ {
return QTextDocumentFragment::fromHtml(mtx::accessors::formattedBodyWithFallback(e)).toPlainText(); return QTextDocumentFragment::fromHtml(
mtx::accessors::formattedBodyWithFallback(e).replace(
QRegularExpression("(<mx-reply>.+\\<\\/mx-reply\\>)"), ""))
.toPlainText();
} }