Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
feat(settings): add group chat local member black list
Browse files Browse the repository at this point in the history
  • Loading branch information
drswinghead committed Sep 16, 2017
1 parent 776b37f commit 27ecace
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 2 deletions.
4 changes: 4 additions & 0 deletions doc/user_manual_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 Settings

Expand Down
18 changes: 18 additions & 0 deletions src/persistence/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ void Settings::loadPersonal(Profile* profile)
{
typingNotification = ps.value("typingNotification", true).toBool();
enableLogging = ps.value("enableLogging", true).toBool();
blackList = ps.value("blackList").toString().split('\n');
}
ps.endGroup();

Expand Down Expand Up @@ -686,6 +687,7 @@ void Settings::savePersonal(QString profileName, const ToxEncrypt* passkey)
{
ps.setValue("typingNotification", typingNotification);
ps.setValue("enableLogging", enableLogging);
ps.setValue("blackList", blackList.join('\n'));
}
ps.endGroup();

Expand Down Expand Up @@ -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
{
QMutexLocker locker{&bigLock};
Expand Down
5 changes: 5 additions & 0 deletions src/persistence/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class Settings : public QObject
// Privacy
Q_PROPERTY(bool typingNotification READ getTypingNotification WRITE setTypingNotification NOTIFY
typingNotificationChanged FINAL)
Q_PROPERTY(QStringList blackList READ getBlackList WRITE setBlackList NOTIFY blackListChanged FINAL)

// Audio
Q_PROPERTY(QString inDev READ getInDev WRITE setInDev NOTIFY inDevChanged FINAL)
Expand Down Expand Up @@ -227,6 +228,7 @@ public slots:
// Privacy
void typingNotificationChanged(bool enabled);
void dbSyncTypeChanged(Db::syncType type);
void blackListChanged(QStringList& blist);

// Audio
void inDevChanged(const QString& name);
Expand Down Expand Up @@ -436,6 +438,8 @@ public slots:
// Privacy
bool getTypingNotification() const;
void setTypingNotification(bool enabled);
QStringList getBlackList() const;
void setBlackList(const QStringList& blist);

// State
QByteArray getWindowGeometry() const;
Expand Down Expand Up @@ -614,6 +618,7 @@ public slots:
// Privacy
bool typingNotification;
Db::syncType dbSyncType;
QStringList blackList;

// Audio
QString inDev;
Expand Down
7 changes: 7 additions & 0 deletions src/widget/form/settings/privacyform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ void PrivacyForm::showEvent(QShowEvent*)
bodyUI->nospamLineEdit->setText(Core::getInstance()->getSelfId().getNoSpamString());
bodyUI->cbTypingNotification->setChecked(s.getTypingNotification());
bodyUI->cbKeepHistory->setChecked(Settings::getInstance().getEnableLogging());
bodyUI->blackListTextEdit->setText(s.getBlackList().join('\n'));
}

void PrivacyForm::on_randomNosapamButton_clicked()
Expand All @@ -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()
{
bodyUI->retranslateUi(this);
Expand Down
1 change: 1 addition & 0 deletions src/widget/form/settings/privacyform.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ private slots:
void on_nospamLineEdit_editingFinished();
void on_randomNosapamButton_clicked();
void on_nospamLineEdit_textChanged();
void on_blackListTextEdit_textChanged();
virtual void showEvent(QShowEvent*) final override;

private:
Expand Down
23 changes: 21 additions & 2 deletions src/widget/form/settings/privacysettings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>384</width>
<height>343</height>
<width>364</width>
<height>509</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
Expand Down Expand Up @@ -117,6 +117,25 @@ If you are getting spammed with friend requests, change the NoSpam.</string>
</layout>
</widget>
</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>
<spacer name="verticalSpacer">
<property name="orientation">
Expand Down
6 changes: 6 additions & 0 deletions src/widget/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1689,6 +1689,12 @@ void Widget::onGroupMessageReceived(int groupnumber, int peernumber, const QStri
ToxPk author = core->getGroupPeerPk(groupnumber, peernumber);
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 =
!isSelf && (message.contains(nameMention) || message.contains(sanitizedNameMention));
if (targeted && !isAction) {
Expand Down

0 comments on commit 27ecace

Please sign in to comment.