diff --git a/src/notifications/Manager.cpp b/src/notifications/Manager.cpp
index 895beaf7..d15eea51 100644
--- a/src/notifications/Manager.cpp
+++ b/src/notifications/Manager.cpp
@@ -22,14 +22,31 @@ NotificationsManager::getMessageTemplate(const mtx::responses::Notification ¬
return tr("%1 sent an encrypted message").arg(sender);
}
- if (mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Emote) {
- return QStringLiteral("* %1 %2").arg(sender);
- } else if (utils::isReply(notification.event)) {
- return tr("%1 replied: %2",
- "Format a reply in a notification. %1 is the sender, %2 the message")
- .arg(sender);
+ bool containsSpoiler =
+ mtx::accessors::formatted_body(notification.event).find("<span data-mx-spoiler") !=
+ std::string::npos;
+
+ if (containsSpoiler) {
+ // Because we skip the %2 here, this might cause a warning in some cases.
+ if (mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Emote) {
+ return QStringLiteral("* %1 spoils something.").arg(sender);
+ } else if (utils::isReply(notification.event)) {
+ return tr("%1 replied with a spoiler.",
+ "Format a reply in a notification. %1 is the sender.")
+ .arg(sender);
+ } else {
+ return QStringLiteral("%1 sent a spoiler.").arg(sender);
+ }
} else {
- return QStringLiteral("%1: %2").arg(sender);
+ if (mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Emote) {
+ return QStringLiteral("* %1 %2").arg(sender);
+ } else if (utils::isReply(notification.event)) {
+ return tr("%1 replied: %2",
+ "Format a reply in a notification. %1 is the sender, %2 the message")
+ .arg(sender);
+ } else {
+ return QStringLiteral("%1: %2").arg(sender);
+ }
}
}
diff --git a/src/notifications/ManagerLinux.cpp b/src/notifications/ManagerLinux.cpp
index 11a7c1a1..75ba1886 100644
--- a/src/notifications/ManagerLinux.cpp
+++ b/src/notifications/ManagerLinux.cpp
@@ -107,7 +107,8 @@ NotificationsManager::postNotification(const mtx::responses::Notification ¬if
QString template_ = getMessageTemplate(notification);
// TODO: decrypt this message if the decryption setting is on in the UserSettings
if (std::holds_alternative<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>(
- notification.event)) {
+ notification.event) ||
+ !template_.contains("%2")) {
postNotif(template_);
return;
}
@@ -115,7 +116,7 @@ NotificationsManager::postNotification(const mtx::responses::Notification ¬if
if (hasMarkup_) {
if (hasImages_ &&
(mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Image ||
- mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Image)) {
+ mtx::accessors::event_type(notification.event) == mtx::events::EventType::Sticker)) {
MxcImageProvider::download(
QString::fromStdString(mtx::accessors::url(notification.event))
.remove(QStringLiteral("mxc://")),
diff --git a/src/notifications/ManagerMac.cpp b/src/notifications/ManagerMac.cpp
index 627e9315..ee5639e4 100644
--- a/src/notifications/ManagerMac.cpp
+++ b/src/notifications/ManagerMac.cpp
@@ -4,6 +4,7 @@
#include "Manager.h"
+#include <QCoreApplication>
#include <QRegularExpression>
#include <QTextDocumentFragment>
@@ -19,7 +20,13 @@
static QString
formatNotification(const mtx::responses::Notification ¬ification)
{
- return utils::stripReplyFallbacks(notification.event, {}, {}).quoted_body;
+ auto fallbacks = utils::stripReplyFallbacks(notification.event, {}, {});
+
+ bool containsSpoiler = fallbacks.quoted_formatted_body.contains("<span data-mx-spoiler");
+ if (containsSpoiler)
+ return QCoreApplication::translate("macosNotification", "Message contains spoiler.");
+ else
+ return fallbacks.quoted_body;
}
NotificationsManager::NotificationsManager(QObject *parent)
diff --git a/src/notifications/ManagerWin.cpp b/src/notifications/ManagerWin.cpp
index f1d3797b..a69afa4e 100644
--- a/src/notifications/ManagerWin.cpp
+++ b/src/notifications/ManagerWin.cpp
@@ -70,7 +70,8 @@ NotificationsManager::postNotification(const mtx::responses::Notification ¬if
auto formatNotification = [this, notification] {
const auto template_ = getMessageTemplate(notification);
if (std::holds_alternative<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>(
- notification.event)) {
+ notification.event) ||
+ !template_.contains("%2")) {
return template_;
}
|