From 1be5b99d1741b0f4c92f9e8b51150e0d44ca0a42 Mon Sep 17 00:00:00 2001
From: Anthony Bilinski <me@abilinski.com>
Date: Mon, 14 Feb 2022 02:28:57 -0800
Subject: [PATCH] feat(Settings): Add setting for hiding group join and leave
 system messages

Messages can become spammy is long lasting quiet groups, drowning out real user
messages
---
 src/persistence/igroupsettings.h           |  4 ++++
 src/persistence/settings.cpp               | 15 +++++++++++++++
 src/persistence/settings.h                 |  6 +++++-
 test/model/groupmessagedispatcher_test.cpp |  5 ++++-
 4 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/src/persistence/igroupsettings.h b/src/persistence/igroupsettings.h
index bd67112df..0f8a780d1 100644
--- a/src/persistence/igroupsettings.h
+++ b/src/persistence/igroupsettings.h
@@ -36,5 +36,9 @@ public:
     virtual QStringList getBlackList() const = 0;
     virtual void setBlackList(const QStringList& blist) = 0;
 
+    virtual bool getShowGroupJoinLeaveMessages() const = 0;
+    virtual void setShowGroupJoinLeaveMessages(bool newValue) = 0;
+
     DECLARE_SIGNAL(blackListChanged, QStringList const& blist);
+    DECLARE_SIGNAL(showGroupJoinLeaveMessagesChanged, bool show);
 };
diff --git a/src/persistence/settings.cpp b/src/persistence/settings.cpp
index 8e5610205..b84017bfb 100644
--- a/src/persistence/settings.cpp
+++ b/src/persistence/settings.cpp
@@ -200,6 +200,7 @@ void Settings::loadGlobal()
         lightTrayIcon = s.value("lightTrayIcon", false).toBool();
         useEmoticons = s.value("useEmoticons", true).toBool();
         statusChangeNotificationEnabled = s.value("statusChangeNotificationEnabled", false).toBool();
+        showGroupJoinLeaveMessages = s.value("showGroupJoinLeaveMessages", true).toBool();
         spellCheckingEnabled = s.value("spellCheckingEnabled", true).toBool();
         themeColor = s.value("themeColor", 0).toInt();
         style = s.value("style", "").toString();
@@ -663,6 +664,7 @@ void Settings::saveGlobal()
         s.setValue("style", style);
         s.setValue("nameColors", nameColors);
         s.setValue("statusChangeNotificationEnabled", statusChangeNotificationEnabled);
+        s.setValue("showGroupJoinLeaveMessages", showGroupJoinLeaveMessages);
         s.setValue("spellCheckingEnabled", spellCheckingEnabled);
     }
     s.endGroup();
@@ -1023,6 +1025,19 @@ void Settings::setStatusChangeNotificationEnabled(bool newValue)
     }
 }
 
+bool Settings::getShowGroupJoinLeaveMessages() const
+{
+    QMutexLocker locker{&bigLock};
+    return showGroupJoinLeaveMessages;
+}
+
+void Settings::setShowGroupJoinLeaveMessages(bool newValue)
+{
+    if (setVal(showGroupJoinLeaveMessages, newValue)) {
+        emit showGroupJoinLeaveMessagesChanged(newValue);
+    }
+}
+
 bool Settings::getSpellCheckingEnabled() const
 {
     const QMutexLocker locker{&bigLock};
diff --git a/src/persistence/settings.h b/src/persistence/settings.h
index 2d24f2923..d165a6e61 100644
--- a/src/persistence/settings.h
+++ b/src/persistence/settings.h
@@ -463,9 +463,12 @@ public:
 
     QStringList getBlackList() const override;
     void setBlackList(const QStringList& blist) override;
-
     SIGNAL_IMPL(Settings, blackListChanged, QStringList const& blist)
 
+    bool getShowGroupJoinLeaveMessages() const override;
+    void setShowGroupJoinLeaveMessages(bool newValue) override;
+    SIGNAL_IMPL(Settings, showGroupJoinLeaveMessagesChanged, bool show)
+
     // State
     QByteArray getWindowGeometry() const;
     void setWindowGeometry(const QByteArray& value);
@@ -655,6 +658,7 @@ private:
     QString timestampFormat;
     QString dateFormat;
     bool statusChangeNotificationEnabled;
+    bool showGroupJoinLeaveMessages;
     bool spellCheckingEnabled;
 
     // Privacy
diff --git a/test/model/groupmessagedispatcher_test.cpp b/test/model/groupmessagedispatcher_test.cpp
index 051a3aea2..af7b62c3a 100644
--- a/test/model/groupmessagedispatcher_test.cpp
+++ b/test/model/groupmessagedispatcher_test.cpp
@@ -63,9 +63,12 @@ class MockGroupSettings : public QObject, public IGroupSettings
 public:
     QStringList getBlackList() const override;
     void setBlackList(const QStringList& blist) override;
-
     SIGNAL_IMPL(MockGroupSettings, blackListChanged, QStringList const& blist)
 
+    bool getShowGroupJoinLeaveMessages() const override { return true; };
+    void setShowGroupJoinLeaveMessages(bool newValue) override {};
+    SIGNAL_IMPL(MockGroupSettings, showGroupJoinLeaveMessagesChanged, bool show)
+
 private:
     QStringList blacklist;
 };