1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

feat(settings): add group chat local member black list

This commit is contained in:
drswinghead 2017-09-09 16:10:08 +08:00
parent 776b37f689
commit 27ecace752
7 changed files with 62 additions and 2 deletions

View File

@ -268,6 +268,10 @@ will alter your Tox ID. You don't need to tell your existing contacts your new
Tox ID, but you have to tell new contacts your new Tox ID. Your Tox ID can be Tox ID, but you have to tell new contacts your new Tox ID. Your Tox ID can be
found in your [User Profile](#user-profile). found in your [User Profile](#user-profile).
#### BlackList
BlackList is a feature of qTox that locally blocks a group member's messages across all your joined groups, in case someone spams a group. You need to put a members public key into the BlackList text box one per line to activate it. Currently qTox doesn't have a method to get the public key from a group member, this will be added in the future.
### Audio/Video ### Audio/Video
#### Audio Settings #### Audio Settings

View File

@ -336,6 +336,7 @@ void Settings::loadPersonal(Profile* profile)
{ {
typingNotification = ps.value("typingNotification", true).toBool(); typingNotification = ps.value("typingNotification", true).toBool();
enableLogging = ps.value("enableLogging", true).toBool(); enableLogging = ps.value("enableLogging", true).toBool();
blackList = ps.value("blackList").toString().split('\n');
} }
ps.endGroup(); ps.endGroup();
@ -686,6 +687,7 @@ void Settings::savePersonal(QString profileName, const ToxEncrypt* passkey)
{ {
ps.setValue("typingNotification", typingNotification); ps.setValue("typingNotification", typingNotification);
ps.setValue("enableLogging", enableLogging); ps.setValue("enableLogging", enableLogging);
ps.setValue("blackList", blackList.join('\n'));
} }
ps.endGroup(); ps.endGroup();
@ -1733,6 +1735,22 @@ void Settings::setTypingNotification(bool enabled)
} }
} }
QStringList Settings::getBlackList() const
{
QMutexLocker locker{&bigLock};
return blackList;
}
void Settings::setBlackList(const QStringList& blist)
{
QMutexLocker locker{&bigLock};
if (blist != blackList) {
blackList = blist;
emit blackListChanged(blackList);
}
}
QString Settings::getInDev() const QString Settings::getInDev() const
{ {
QMutexLocker locker{&bigLock}; QMutexLocker locker{&bigLock};

View File

@ -89,6 +89,7 @@ class Settings : public QObject
// Privacy // Privacy
Q_PROPERTY(bool typingNotification READ getTypingNotification WRITE setTypingNotification NOTIFY Q_PROPERTY(bool typingNotification READ getTypingNotification WRITE setTypingNotification NOTIFY
typingNotificationChanged FINAL) typingNotificationChanged FINAL)
Q_PROPERTY(QStringList blackList READ getBlackList WRITE setBlackList NOTIFY blackListChanged FINAL)
// Audio // Audio
Q_PROPERTY(QString inDev READ getInDev WRITE setInDev NOTIFY inDevChanged FINAL) Q_PROPERTY(QString inDev READ getInDev WRITE setInDev NOTIFY inDevChanged FINAL)
@ -227,6 +228,7 @@ signals:
// Privacy // Privacy
void typingNotificationChanged(bool enabled); void typingNotificationChanged(bool enabled);
void dbSyncTypeChanged(Db::syncType type); void dbSyncTypeChanged(Db::syncType type);
void blackListChanged(QStringList& blist);
// Audio // Audio
void inDevChanged(const QString& name); void inDevChanged(const QString& name);
@ -436,6 +438,8 @@ public:
// Privacy // Privacy
bool getTypingNotification() const; bool getTypingNotification() const;
void setTypingNotification(bool enabled); void setTypingNotification(bool enabled);
QStringList getBlackList() const;
void setBlackList(const QStringList& blist);
// State // State
QByteArray getWindowGeometry() const; QByteArray getWindowGeometry() const;
@ -614,6 +618,7 @@ private:
// Privacy // Privacy
bool typingNotification; bool typingNotification;
Db::syncType dbSyncType; Db::syncType dbSyncType;
QStringList blackList;
// Audio // Audio
QString inDev; QString inDev;

View File

@ -92,6 +92,7 @@ void PrivacyForm::showEvent(QShowEvent*)
bodyUI->nospamLineEdit->setText(Core::getInstance()->getSelfId().getNoSpamString()); bodyUI->nospamLineEdit->setText(Core::getInstance()->getSelfId().getNoSpamString());
bodyUI->cbTypingNotification->setChecked(s.getTypingNotification()); bodyUI->cbTypingNotification->setChecked(s.getTypingNotification());
bodyUI->cbKeepHistory->setChecked(Settings::getInstance().getEnableLogging()); bodyUI->cbKeepHistory->setChecked(Settings::getInstance().getEnableLogging());
bodyUI->blackListTextEdit->setText(s.getBlackList().join('\n'));
} }
void PrivacyForm::on_randomNosapamButton_clicked() void PrivacyForm::on_randomNosapamButton_clicked()
@ -118,6 +119,12 @@ void PrivacyForm::on_nospamLineEdit_textChanged()
}; };
} }
void PrivacyForm::on_blackListTextEdit_textChanged()
{
const QStringList strlist = bodyUI->blackListTextEdit->toPlainText().split('\n');
Settings::getInstance().setBlackList(strlist);
}
void PrivacyForm::retranslateUi() void PrivacyForm::retranslateUi()
{ {
bodyUI->retranslateUi(this); bodyUI->retranslateUi(this);

View File

@ -43,6 +43,7 @@ private slots:
void on_nospamLineEdit_editingFinished(); void on_nospamLineEdit_editingFinished();
void on_randomNosapamButton_clicked(); void on_randomNosapamButton_clicked();
void on_nospamLineEdit_textChanged(); void on_nospamLineEdit_textChanged();
void on_blackListTextEdit_textChanged();
virtual void showEvent(QShowEvent*) final override; virtual void showEvent(QShowEvent*) final override;
private: private:

View File

@ -36,8 +36,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>384</width> <width>364</width>
<height>343</height> <height>509</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
@ -117,6 +117,25 @@ If you are getting spammed with friend requests, change the NoSpam.</string>
</layout> </layout>
</widget> </widget>
</item> </item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="toolTip">
<string/>
</property>
<property name="title">
<string>BlackList</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QTextEdit" name="blackListTextEdit">
<property name="toolTip">
<string>Filter group message by group member's public key. Put public key here, one per line.</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item> <item>
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">

View File

@ -1689,6 +1689,12 @@ void Widget::onGroupMessageReceived(int groupnumber, int peernumber, const QStri
ToxPk author = core->getGroupPeerPk(groupnumber, peernumber); ToxPk author = core->getGroupPeerPk(groupnumber, peernumber);
bool isSelf = author == core->getSelfId().getPublicKey(); bool isSelf = author == core->getSelfId().getPublicKey();
const Settings& s = Settings::getInstance();
if (s.getBlackList().contains(author.toString())) {
qDebug() << "onGroupMessageReceived: Filtered:" << author.toString();
return;
}
bool targeted = bool targeted =
!isSelf && (message.contains(nameMention) || message.contains(sanitizedNameMention)); !isSelf && (message.contains(nameMention) || message.contains(sanitizedNameMention));
if (targeted && !isAction) { if (targeted && !isAction) {