mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-23 01:55:10 -07:00
[Client] Add setting to ignore all private messages (#1250)
This commit is contained in:
parent
0f003eabf9
commit
dfa738ffcb
7 changed files with 41 additions and 0 deletions
|
|
@ -59,6 +59,10 @@ MessagesSettingsPage::MessagesSettingsPage()
|
||||||
connect(&roomHistory, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance().chat(),
|
connect(&roomHistory, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance().chat(),
|
||||||
&ChatSettings::setRoomHistory);
|
&ChatSettings::setRoomHistory);
|
||||||
|
|
||||||
|
ignoreAllPrivateMessagesCheckBox.setChecked(SettingsCache::instance().chat().getIgnoreAllPrivateMessages());
|
||||||
|
connect(&ignoreAllPrivateMessagesCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance().chat(),
|
||||||
|
&ChatSettings::setIgnoreAllPrivateMessages);
|
||||||
|
|
||||||
customAlertString = new QLineEdit();
|
customAlertString = new QLineEdit();
|
||||||
customAlertString->setText(SettingsCache::instance().chat().getHighlightWords());
|
customAlertString->setText(SettingsCache::instance().chat().getHighlightWords());
|
||||||
connect(customAlertString, &QLineEdit::textChanged, &SettingsCache::instance().chat(),
|
connect(customAlertString, &QLineEdit::textChanged, &SettingsCache::instance().chat(),
|
||||||
|
|
@ -76,6 +80,7 @@ MessagesSettingsPage::MessagesSettingsPage()
|
||||||
chatGrid->addWidget(&messagePopups, 5, 0);
|
chatGrid->addWidget(&messagePopups, 5, 0);
|
||||||
chatGrid->addWidget(&mentionPopups, 6, 0);
|
chatGrid->addWidget(&mentionPopups, 6, 0);
|
||||||
chatGrid->addWidget(&roomHistory, 7, 0);
|
chatGrid->addWidget(&roomHistory, 7, 0);
|
||||||
|
chatGrid->addWidget(&ignoreAllPrivateMessagesCheckBox, 8, 0);
|
||||||
chatGroupBox = new QGroupBox;
|
chatGroupBox = new QGroupBox;
|
||||||
chatGroupBox->setLayout(chatGrid);
|
chatGroupBox->setLayout(chatGrid);
|
||||||
|
|
||||||
|
|
@ -256,6 +261,7 @@ void MessagesSettingsPage::retranslateUi()
|
||||||
messagePopups.setText(tr("Enable desktop notifications for private messages"));
|
messagePopups.setText(tr("Enable desktop notifications for private messages"));
|
||||||
mentionPopups.setText(tr("Enable desktop notification for mentions"));
|
mentionPopups.setText(tr("Enable desktop notification for mentions"));
|
||||||
roomHistory.setText(tr("Enable room message history on join"));
|
roomHistory.setText(tr("Enable room message history on join"));
|
||||||
|
ignoreAllPrivateMessagesCheckBox.setText(tr("Ignore all private messages"));
|
||||||
hexLabel.setText(tr("(Color is hexadecimal)"));
|
hexLabel.setText(tr("(Color is hexadecimal)"));
|
||||||
hexHighlightLabel.setText(tr("(Color is hexadecimal)"));
|
hexHighlightLabel.setText(tr("(Color is hexadecimal)"));
|
||||||
customAlertStringLabel.setText(tr("Separate words with a space, alphanumeric characters only"));
|
customAlertStringLabel.setText(tr("Separate words with a space, alphanumeric characters only"));
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ private:
|
||||||
QCheckBox messagePopups;
|
QCheckBox messagePopups;
|
||||||
QCheckBox mentionPopups;
|
QCheckBox mentionPopups;
|
||||||
QCheckBox roomHistory;
|
QCheckBox roomHistory;
|
||||||
|
QCheckBox ignoreAllPrivateMessagesCheckBox;
|
||||||
QGroupBox *chatGroupBox;
|
QGroupBox *chatGroupBox;
|
||||||
QGroupBox *highlightGroupBox;
|
QGroupBox *highlightGroupBox;
|
||||||
QGroupBox *messageGroupBox;
|
QGroupBox *messageGroupBox;
|
||||||
|
|
|
||||||
|
|
@ -1277,7 +1277,22 @@ void TabSupervisor::processGameEventContainer(const GameEventContainer &cont)
|
||||||
|
|
||||||
void TabSupervisor::processUserMessageEvent(const Event_UserMessage &event)
|
void TabSupervisor::processUserMessageEvent(const Event_UserMessage &event)
|
||||||
{
|
{
|
||||||
|
// "Ignore all private messages" silences every PM, including messages to
|
||||||
|
// already-open tabs — unlike the unregistered/non-buddy filters below,
|
||||||
|
// which only apply when creating a new tab. Messages from moderators/admins
|
||||||
|
// are exempt to ensure warnings still reach users.
|
||||||
QString senderName = QString::fromStdString(event.sender_name());
|
QString senderName = QString::fromStdString(event.sender_name());
|
||||||
|
if (SettingsCache::instance().chat().getIgnoreAllPrivateMessages()) {
|
||||||
|
const ServerInfo_User *onlineUserInfo = userListManager->getOnlineUser(senderName);
|
||||||
|
if (onlineUserInfo) {
|
||||||
|
const UserLevelFlags userLevel(onlineUserInfo->user_level());
|
||||||
|
if (!userLevel.testFlag(ServerInfo_User::IsModerator) && !userLevel.testFlag(ServerInfo_User::IsAdmin)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
TabMessage *tab = messageTabs.value(senderName);
|
TabMessage *tab = messageTabs.value(senderName);
|
||||||
if (!tab) {
|
if (!tab) {
|
||||||
tab = messageTabs.value(QString::fromStdString(event.receiver_name()));
|
tab = messageTabs.value(QString::fromStdString(event.receiver_name()));
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ public:
|
||||||
[[nodiscard]] virtual bool getShowMessagePopup() const = 0;
|
[[nodiscard]] virtual bool getShowMessagePopup() const = 0;
|
||||||
[[nodiscard]] virtual bool getShowMentionPopup() const = 0;
|
[[nodiscard]] virtual bool getShowMentionPopup() const = 0;
|
||||||
[[nodiscard]] virtual bool getRoomHistory() const = 0;
|
[[nodiscard]] virtual bool getRoomHistory() const = 0;
|
||||||
|
[[nodiscard]] virtual bool getIgnoreAllPrivateMessages() const = 0;
|
||||||
[[nodiscard]] virtual QString getHighlightWords() const = 0;
|
[[nodiscard]] virtual QString getHighlightWords() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,11 @@ bool ChatSettings::getRoomHistory() const
|
||||||
return getValue("roomHistory", QString(), QString(), true).toBool();
|
return getValue("roomHistory", QString(), QString(), true).toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ChatSettings::getIgnoreAllPrivateMessages() const
|
||||||
|
{
|
||||||
|
return getValue("ignoreAllPrivateMessages", QString(), QString(), false).toBool();
|
||||||
|
}
|
||||||
|
|
||||||
QString ChatSettings::getHighlightWords() const
|
QString ChatSettings::getHighlightWords() const
|
||||||
{
|
{
|
||||||
return getValue("highlightWords").toString();
|
return getValue("highlightWords").toString();
|
||||||
|
|
@ -131,6 +136,11 @@ void ChatSettings::setRoomHistory(bool _roomHistory)
|
||||||
setValue(_roomHistory, "roomHistory");
|
setValue(_roomHistory, "roomHistory");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChatSettings::setIgnoreAllPrivateMessages(bool _ignoreAllPrivateMessages)
|
||||||
|
{
|
||||||
|
setValue(_ignoreAllPrivateMessages, "ignoreAllPrivateMessages");
|
||||||
|
}
|
||||||
|
|
||||||
void ChatSettings::setHighlightWords(const QString &_highlightWords)
|
void ChatSettings::setHighlightWords(const QString &_highlightWords)
|
||||||
{
|
{
|
||||||
setValue(_highlightWords, "highlightWords");
|
setValue(_highlightWords, "highlightWords");
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ public:
|
||||||
[[nodiscard]] bool getShowMessagePopup() const override;
|
[[nodiscard]] bool getShowMessagePopup() const override;
|
||||||
[[nodiscard]] bool getShowMentionPopup() const override;
|
[[nodiscard]] bool getShowMentionPopup() const override;
|
||||||
[[nodiscard]] bool getRoomHistory() const override;
|
[[nodiscard]] bool getRoomHistory() const override;
|
||||||
|
[[nodiscard]] bool getIgnoreAllPrivateMessages() const override;
|
||||||
[[nodiscard]] QString getHighlightWords() const override;
|
[[nodiscard]] QString getHighlightWords() const override;
|
||||||
|
|
||||||
void setChatMention(bool _chatMention);
|
void setChatMention(bool _chatMention);
|
||||||
|
|
@ -37,6 +38,7 @@ public:
|
||||||
void setShowMessagePopups(bool _showMessagePopups);
|
void setShowMessagePopups(bool _showMessagePopups);
|
||||||
void setShowMentionPopups(bool _showMentionPopups);
|
void setShowMentionPopups(bool _showMentionPopups);
|
||||||
void setRoomHistory(bool _roomHistory);
|
void setRoomHistory(bool _roomHistory);
|
||||||
|
void setIgnoreAllPrivateMessages(bool _ignoreAllPrivateMessages);
|
||||||
void setHighlightWords(const QString &_highlightWords);
|
void setHighlightWords(const QString &_highlightWords);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
|
||||||
|
|
@ -300,6 +300,12 @@ TEST_F(SettingsDefaultsTest, Chat_RoomHistory_Default)
|
||||||
ASSERT_EQ(s.getRoomHistory(), true);
|
ASSERT_EQ(s.getRoomHistory(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(SettingsDefaultsTest, Chat_IgnoreAllPrivateMessages_Default)
|
||||||
|
{
|
||||||
|
ChatSettings s(settingsPath, nullptr);
|
||||||
|
ASSERT_EQ(s.getIgnoreAllPrivateMessages(), false);
|
||||||
|
}
|
||||||
|
|
||||||
// --- PersonalSettings ---
|
// --- PersonalSettings ---
|
||||||
|
|
||||||
TEST_F(SettingsDefaultsTest, Personal_Lang_Default)
|
TEST_F(SettingsDefaultsTest, Personal_Lang_Default)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue