summary refs log tree commit diff
diff options
context:
space:
mode:
authorLoren Burkholder <computersemiexpert@outlook.com>2021-02-20 12:00:13 -0500
committerNicolas Werner <nicolas.werner@hotmail.de>2021-03-17 19:17:14 +0100
commit4a86e14d04d2f20d02f41801e755e1b2be803e48 (patch)
tree2c34837cac868d9319923f2cc1c81682eecfb15a
parentOnly HTML-format the body if it should be formatted (diff)
downloadnheko-4a86e14d04d2f20d02f41801e755e1b2be803e48.tar.xz
Simplify determination of whether markup is supported
This should also result in a speed increase (however slight), since the capabilities are now sorted through only once.
-rw-r--r--src/notifications/ManagerLinux.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/notifications/ManagerLinux.cpp b/src/notifications/ManagerLinux.cpp
index adaa0a35..ab4a6d93 100644
--- a/src/notifications/ManagerLinux.cpp
+++ b/src/notifications/ManagerLinux.cpp
@@ -9,6 +9,8 @@
 #include <QImage>
 #include <QTextDocumentFragment>
 
+#include <functional>
+
 #include "Utils.h"
 
 NotificationsManager::NotificationsManager(QObject *parent)
@@ -161,14 +163,18 @@ NotificationsManager::notificationClosed(uint id, uint reason)
 QString
 NotificationsManager::formatNotification(const QString &text)
 {
-        static auto capabilites = dbus.call("GetCapabilities").arguments();
-        for (auto x : capabilites)
-                if (x.toStringList().contains("body-markup"))
-                        return QString(text)
-                          .replace("<em>", "<i>")
-                          .replace("</em>", "</i>")
-                          .replace("<strong>", "<b>")
-                          .replace("</strong>", "</b>");
+        static const auto hasMarkup = std::invoke([this]() -> bool {
+                for (auto x : dbus.call("GetCapabilities").arguments())
+                        if (x.toStringList().contains("body-markup"))
+                                return true;
+                return false;
+        });
+        if (hasMarkup)
+                return QString(text)
+                  .replace("<em>", "<i>")
+                  .replace("</em>", "</i>")
+                  .replace("<strong>", "<b>")
+                  .replace("</strong>", "</b>");
 
         return QTextDocumentFragment::fromHtml(text).toPlainText();
 }