diff --git a/src/persistence/igroupsettings.h b/src/persistence/igroupsettings.h index ce9a94db5..ab48b3d10 100644 --- a/src/persistence/igroupsettings.h +++ b/src/persistence/igroupsettings.h @@ -20,6 +20,8 @@ #ifndef IGROUP_SETTINGS_H #define IGROUP_SETTINGS_H +#include "src/model/interface.h" + #include class IGroupSettings @@ -30,6 +32,8 @@ public: virtual void setBlackList(const QStringList& blist) = 0; virtual bool getGroupAlwaysNotify() const = 0; virtual void setGroupAlwaysNotify(bool newValue) = 0; + + DECLARE_SIGNAL(blackListChanged, QStringList const& blist); }; #endif /*IGROUP_SETTINGS_H*/ diff --git a/src/persistence/settings.h b/src/persistence/settings.h index 0effc96c1..a8fd1525d 100644 --- a/src/persistence/settings.h +++ b/src/persistence/settings.h @@ -232,7 +232,6 @@ signals: // Privacy void typingNotificationChanged(bool enabled); void dbSyncTypeChanged(Db::syncType type); - void blackListChanged(QStringList& blist); public: bool applyCommandLineOptions(const QCommandLineParser& parser); @@ -462,9 +461,12 @@ public: // Privacy bool getTypingNotification() const; void setTypingNotification(bool enabled); + QStringList getBlackList() const override; void setBlackList(const QStringList& blist) override; + SIGNAL_IMPL(Settings, blackListChanged, QStringList const& blist) + // State QByteArray getWindowGeometry() const; void setWindowGeometry(const QByteArray& value); diff --git a/src/widget/form/groupchatform.cpp b/src/widget/form/groupchatform.cpp index 054e2a6b0..3795a4f36 100644 --- a/src/widget/form/groupchatform.cpp +++ b/src/widget/form/groupchatform.cpp @@ -37,7 +37,7 @@ #include "src/widget/style.h" #include "src/widget/tool/croppinglabel.h" #include "src/widget/translator.h" -#include "src/persistence/settings.h" +#include "src/persistence/igroupsettings.h" #include #include @@ -82,10 +82,11 @@ QString editName(const QString& name) * @brief Timeout = peer stopped sending audio. */ -GroupChatForm::GroupChatForm(Group* chatGroup, IChatLog& chatLog, IMessageDispatcher& messageDispatcher) +GroupChatForm::GroupChatForm(Group* chatGroup, IChatLog& chatLog, IMessageDispatcher& messageDispatcher, IGroupSettings& _settings) : GenericChatForm(chatGroup, chatLog, messageDispatcher) , group(chatGroup) , inCall(false) + , settings(_settings) { nusersLabel = new QLabel(); @@ -129,7 +130,7 @@ GroupChatForm::GroupChatForm(Group* chatGroup, IChatLog& chatLog, IMessageDispat connect(group, &Group::userLeft, this, &GroupChatForm::onUserLeft); connect(group, &Group::peerNameChanged, this, &GroupChatForm::onPeerNameChanged); connect(group, &Group::numPeersChanged, this, &GroupChatForm::updateUserCount); - connect(&Settings::getInstance(), &Settings::blackListChanged, this, &GroupChatForm::updateUserNames); + settings.connectTo_blackListChanged(this, [this](QStringList const&) { this->updateUserNames(); }); updateUserNames(); setAcceptDrops(true); @@ -198,12 +199,11 @@ void GroupChatForm::updateUserNames() label->setTextFormat(Qt::PlainText); label->setContextMenuPolicy(Qt::CustomContextMenu); - const Settings& s = Settings::getInstance(); connect(label, &QLabel::customContextMenuRequested, this, &GroupChatForm::onLabelContextMenuRequested); if (peerPk == selfPk) { label->setProperty("peerType", LABEL_PEER_TYPE_OUR); - } else if (s.getBlackList().contains(peerPk.toString())) { + } else if (settings.getBlackList().contains(peerPk.toString())) { label->setProperty("peerType", LABEL_PEER_TYPE_MUTED); } @@ -415,8 +415,7 @@ void GroupChatForm::onLabelContextMenuRequested(const QPoint& localPos) const QPoint pos = label->mapToGlobal(localPos); const QString muteString = tr("mute"); const QString unmuteString = tr("unmute"); - Settings& s = Settings::getInstance(); - QStringList blackList = s.getBlackList(); + QStringList blackList = settings.getBlackList(); QMenu* const contextMenu = new QMenu(this); const ToxPk selfPk = Core::getInstance()->getSelfPublicKey(); ToxPk peerPk; @@ -457,7 +456,7 @@ void GroupChatForm::onLabelContextMenuRequested(const QPoint& localPos) blackList << peerPk.toString(); } - s.setBlackList(blackList); + settings.setBlackList(blackList); } } diff --git a/src/widget/form/groupchatform.h b/src/widget/form/groupchatform.h index e163c48cd..d039bcffe 100644 --- a/src/widget/form/groupchatform.h +++ b/src/widget/form/groupchatform.h @@ -33,13 +33,14 @@ class FlowLayout; class QTimer; class GroupId; class IMessageDispatcher; -class Message; +struct Message; +class IGroupSettings; class GroupChatForm : public GenericChatForm { Q_OBJECT public: - explicit GroupChatForm(Group* chatGroup, IChatLog& chatLog, IMessageDispatcher& messageDispatcher); + GroupChatForm(Group* chatGroup, IChatLog& chatLog, IMessageDispatcher& messageDispatcher, IGroupSettings& _settings); ~GroupChatForm(); void peerAudioPlaying(ToxPk peerPk); @@ -79,6 +80,7 @@ private: QLabel* nusersLabel; TabCompleter* tabber; bool inCall; + IGroupSettings& settings; }; #endif // GROUPCHATFORM_H diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index a48ac5cfe..1ba25ee58 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -2115,7 +2115,7 @@ Group* Widget::createGroup(uint32_t groupnumber, const GroupId& groupId) connect(messageDispatcher.get(), &IMessageDispatcher::messageReceived, notifyReceivedCallback); groupAlertConnections.insert(groupId, notifyReceivedConnection); - auto form = new GroupChatForm(newgroup, *groupChatLog, *messageDispatcher); + auto form = new GroupChatForm(newgroup, *groupChatLog, *messageDispatcher, settings); connect(&settings, &Settings::nameColorsChanged, form, &GenericChatForm::setColorizedNames); form->setColorizedNames(settings.getEnableGroupChatsColor()); groupMessageDispatchers[groupId] = messageDispatcher; diff --git a/test/model/groupmessagedispatcher_test.cpp b/test/model/groupmessagedispatcher_test.cpp index 30591b373..323cd0f2b 100644 --- a/test/model/groupmessagedispatcher_test.cpp +++ b/test/model/groupmessagedispatcher_test.cpp @@ -22,6 +22,8 @@ #include "src/model/groupmessagedispatcher.h" #include "src/model/message.h" #include "src/persistence/settings.h" +#include "src/persistence/igroupsettings.h" +#include "src/model/interface.h" #include #include @@ -126,8 +128,10 @@ public: } }; -class MockGroupSettings : public IGroupSettings +class MockGroupSettings : public QObject, public IGroupSettings { + Q_OBJECT + public: QStringList getBlackList() const override { @@ -145,6 +149,7 @@ public: } void setGroupAlwaysNotify(bool newValue) override {} + SIGNAL_IMPL(MockGroupSettings, blackListChanged, QStringList const& blist) private: QStringList blacklist;