feat(groups): add option to automatically accept groupchat invites

Allows to accept group chat invites from select contacts automatically.

fix #1197
reviewable/pr4250/r3
sudden6 2017-03-12 17:37:38 +01:00
parent 9236763865
commit 6a16a2bdbc
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
7 changed files with 76 additions and 17 deletions

View File

@ -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

View File

@ -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<int>(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};

View File

@ -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

View File

@ -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;

View File

@ -26,6 +26,7 @@ private slots:
void onAcceptedClicked();
void onAutoAcceptDirClicked();
void onAutoAcceptCallClicked();
void onAutoGroupInvite();
void onSelectDirClicked();
void onRemoveHistoryClicked();
};

View File

@ -218,6 +218,16 @@
</item>
</layout>
</item>
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="autogroupinvite">
<property name="accessibleDescription">
<string>Automatically accept group chat invitations from this contact if set.</string>
</property>
<property name="text">
<string>Auto accept group invites</string>
</property>
</widget>
</item>
</layout>
</item>
<item>

View File

@ -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);