diff --git a/doc/user_manual_en.md b/doc/user_manual_en.md index d6a3ee55c..45ba50615 100644 --- a/doc/user_manual_en.md +++ b/doc/user_manual_en.md @@ -69,6 +69,8 @@ right-clicking on a contact a menu appears that has the following options: * __Move to circle:__ offers an option to move friend to a new [circle](#circles), or to an existing one. * __Set alias:__ set alias that will be displayed instead of contact's name. +* __Auto accept group invites:__ if enabled, all group chat invites from this + friend are automatically accepted. * __Auto accept files from this friend:__ option to automatically save files from the selected contact in a chosen directory. * __Remove friend:__ option to remove the contact. Confirmation is needed to diff --git a/src/persistence/settings.cpp b/src/persistence/settings.cpp index 0c682168f..e4ec43e49 100644 --- a/src/persistence/settings.cpp +++ b/src/persistence/settings.cpp @@ -369,6 +369,7 @@ void Settings::loadPersonal(Profile* profile) fp.autoAcceptCall = Settings::AutoAcceptCallFlags(QFlag(ps.value("autoAcceptCall", 0).toInt())); + fp.autoGroupInvite = ps.value("autoGroupInvite").toBool(); fp.circleID = ps.value("circle", -1).toInt(); if (getEnableLogging()) @@ -646,6 +647,7 @@ void Settings::savePersonal(QString profileName, const QString& password) ps.setValue("note", frnd.note); ps.setValue("autoAcceptDir", frnd.autoAcceptDir); ps.setValue("autoAcceptCall", static_cast(frnd.autoAcceptCall)); + ps.setValue("autoGroupInvite", frnd.autoGroupInvite); ps.setValue("circle", frnd.circleID); if (getEnableLogging()) @@ -1416,6 +1418,29 @@ void Settings::setAutoAcceptCall(const ToxPk& id, AutoAcceptCallFlags accept) } } +bool Settings::getAutoGroupInvite(const ToxPk& id) const +{ + QMutexLocker locker{&bigLock}; + + auto it = friendLst.find(id.getKey()); + if (it != friendLst.end()) { + return it->autoGroupInvite; + } + + return false; +} + +void Settings::setAutoGroupInvite(const ToxPk& id, bool accept) +{ + QMutexLocker locker{&bigLock}; + + auto it = friendLst.find(id.getKey()); + if (it != friendLst.end()) { + it->autoGroupInvite = accept; + emit autoGroupInviteChanged(id, accept); + } +} + QString Settings::getContactNote(const ToxPk& id) const { QMutexLocker locker{&bigLock}; diff --git a/src/persistence/settings.h b/src/persistence/settings.h index 5a47c4367..1376afd23 100644 --- a/src/persistence/settings.h +++ b/src/persistence/settings.h @@ -192,6 +192,7 @@ signals: void checkUpdatesChanged(bool enabled); void widgetDataChanged(const QString& key); void autoAcceptCallChanged(const ToxPk& id, AutoAcceptCallFlags accept); + void autoGroupInviteChanged(const ToxPk& id, bool accept); // GUI void autoLoginChanged(bool enabled); @@ -407,6 +408,9 @@ public: QString getGlobalAutoAcceptDir() const; void setGlobalAutoAcceptDir(const QString& dir); + bool getAutoGroupInvite(const ToxPk& id) const; + void setAutoGroupInvite(const ToxPk& id, bool accept); + // ChatView const QFont& getChatMessageFont() const; void setChatMessageFont(const QFont& font); @@ -629,6 +633,7 @@ private: int circleID = -1; QDate activity = QDate(); AutoAcceptCallFlags autoAcceptCall; + bool autoGroupInvite = false; }; struct circleProp diff --git a/src/widget/about/aboutuser.cpp b/src/widget/about/aboutuser.cpp index 8a71cd444..7969f4d1d 100644 --- a/src/widget/about/aboutuser.cpp +++ b/src/widget/about/aboutuser.cpp @@ -19,19 +19,23 @@ AboutUser::AboutUser(ToxPk& toxId, QWidget* parent) connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &AboutUser::onAcceptedClicked); connect(ui->autoacceptfile, &QCheckBox::clicked, this, &AboutUser::onAutoAcceptDirClicked); connect(ui->autoacceptcall, SIGNAL(activated(int)), this, SLOT(onAutoAcceptCallClicked(void))); + connect(ui->autogroupinvite, &QCheckBox::clicked, this, &AboutUser::onAutoGroupInvite); connect(ui->selectSaveDir, &QPushButton::clicked, this, &AboutUser::onSelectDirClicked); connect(ui->removeHistory, &QPushButton::clicked, this, &AboutUser::onRemoveHistoryClicked); this->friendPk = toxId; - QString dir = Settings::getInstance().getAutoAcceptDir(this->friendPk); + Settings& s = Settings::getInstance(); + QString dir = s.getAutoAcceptDir(this->friendPk); ui->autoacceptfile->setChecked(!dir.isEmpty()); - ui->autoacceptcall->setCurrentIndex(Settings::getInstance().getAutoAcceptCall(this->friendPk)); + ui->autoacceptcall->setCurrentIndex(s.getAutoAcceptCall(this->friendPk)); ui->selectSaveDir->setEnabled(ui->autoacceptfile->isChecked()); + ui->autogroupinvite->setChecked(s.getAutoGroupInvite(this->friendPk)); - if (ui->autoacceptfile->isChecked()) - ui->selectSaveDir->setText(Settings::getInstance().getAutoAcceptDir(this->friendPk)); + if (ui->autoacceptfile->isChecked()) { + ui->selectSaveDir->setText(s.getAutoAcceptDir(this->friendPk)); + } } void AboutUser::setFriend(Friend* f) @@ -82,6 +86,15 @@ void AboutUser::onAutoAcceptCallClicked() Settings::getInstance().savePersonal(); } +/** + * @brief Sets the AutoGroupinvite status and saves the settings. + */ +void AboutUser::onAutoGroupInvite() +{ + Settings::getInstance().setAutoGroupInvite(this->friendPk, ui->autogroupinvite->isChecked()); + Settings::getInstance().savePersonal(); +} + void AboutUser::onSelectDirClicked() { QString dir; diff --git a/src/widget/about/aboutuser.h b/src/widget/about/aboutuser.h index 5a8cdf253..4b2b40ba5 100644 --- a/src/widget/about/aboutuser.h +++ b/src/widget/about/aboutuser.h @@ -26,6 +26,7 @@ private slots: void onAcceptedClicked(); void onAutoAcceptDirClicked(); void onAutoAcceptCallClicked(); + void onAutoGroupInvite(); void onSelectDirClicked(); void onRemoveHistoryClicked(); }; diff --git a/src/widget/about/aboutuser.ui b/src/widget/about/aboutuser.ui index f40ad223a..41d6d1042 100644 --- a/src/widget/about/aboutuser.ui +++ b/src/widget/about/aboutuser.ui @@ -218,6 +218,16 @@ + + + + Automatically accept group chat invitations from this contact if set. + + + Auto accept group invites + + + diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index a879d905a..d00d3e180 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -118,7 +118,7 @@ void Widget::init() actionShow = new QAction(this); connect(actionShow, &QAction::triggered, this, &Widget::forceShow); - //Preparing icons and set their size + // Preparing icons and set their size statusOnline = new QAction(this); statusOnline->setIcon(prepareIcon(getStatusIconPath(Status::Online), icon_size, icon_size)); connect(statusOnline, &QAction::triggered, this, &Widget::setStatusOnline); @@ -1556,13 +1556,18 @@ void Widget::copyFriendIdToClipboard(int friendId) void Widget::onGroupInviteReceived(int32_t friendId, uint8_t type, QByteArray invite) { - updateFriendActivity(FriendList::findFriend(friendId)); + Friend* f = FriendList::findFriend(friendId); + updateFriendActivity(f); if (type == TOX_CONFERENCE_TYPE_TEXT || type == TOX_CONFERENCE_TYPE_AV) { - ++unreadGroupInvites; - groupInvitesUpdate(); - newMessageAlert(window(), isActiveWindow(), true, true); - groupInviteForm->addGroupInvite(friendId, type, invite); + if (Settings::getInstance().getAutoGroupInvite(f->getPublicKey())) { + onGroupInviteAccepted(friendId, type, invite); + } else { + ++unreadGroupInvites; + groupInvitesUpdate(); + newMessageAlert(window(), isActiveWindow(), true, true); + groupInviteForm->addGroupInvite(friendId, type, invite); + } } else { qWarning() << "onGroupInviteReceived: Unknown groupchat type:" << type; return; @@ -2070,22 +2075,20 @@ QString Widget::getStatusIconPath(Status status) assert(false); } -//Preparing needed to set correct size of icons for GTK tray backend +// Preparing needed to set correct size of icons for GTK tray backend inline QIcon Widget::prepareIcon(QString path, int w, int h) { #ifdef Q_OS_LINUX QString desktop = getenv("XDG_CURRENT_DESKTOP"); - if (desktop.isEmpty()) - { + if (desktop.isEmpty()) { desktop = getenv("DESKTOP_SESSION"); } desktop = desktop.toLower(); - if (desktop == "xfce" || desktop.contains("gnome") || desktop == "mate" || desktop == "x-cinnamon") - { - if (w > 0 && h > 0) - { + if (desktop == "xfce" || desktop.contains("gnome") || desktop == "mate" + || desktop == "x-cinnamon") { + if (w > 0 && h > 0) { QSvgRenderer renderer(path); QPixmap pm(w, h);