Add option to disable typing notifications

fixes #131
This commit is contained in:
Konstantinos Sideris 2018-01-14 15:57:58 +02:00
parent c4fa8c844d
commit 4521837765
3 changed files with 52 additions and 5 deletions

View file

@ -61,10 +61,17 @@ public:
save();
};
void setTypingNotifications(bool state)
{
isTypingNotificationsEnabled_ = state;
save();
};
QString theme() const { return !theme_.isEmpty() ? theme_ : "light"; }
bool isTrayEnabled() const { return isTrayEnabled_; }
bool isOrderingEnabled() const { return isOrderingEnabled_; }
bool isGroupViewEnabled() const { return isGroupViewEnabled_; }
bool isTypingNotificationsEnabled() const { return isTypingNotificationsEnabled_; }
signals:
void groupViewStateChanged(bool state);
@ -74,6 +81,7 @@ private:
bool isTrayEnabled_;
bool isOrderingEnabled_;
bool isGroupViewEnabled_;
bool isTypingNotificationsEnabled_;
};
class HorizontalLine : public QFrame
@ -114,6 +122,7 @@ private:
Toggle *trayToggle_;
Toggle *roomOrderToggle_;
Toggle *groupViewToggle_;
Toggle *typingNotifications_;
QComboBox *themeCombo_;

View file

@ -155,6 +155,11 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client,
connect(room_list_, &RoomList::roomChanged, this, [=](const QString &roomid) {
QStringList users;
if (!userSettings_->isTypingNotificationsEnabled()) {
typingDisplay_->setUsers(users);
return;
}
if (typingUsers_.contains(roomid))
users = typingUsers_[roomid];
@ -190,16 +195,25 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client,
});
connect(text_input_, &TextInputWidget::startedTyping, this, [=]() {
if (!userSettings_->isTypingNotificationsEnabled())
return;
typingRefresher_->start();
client_->sendTypingNotification(current_room_);
});
connect(text_input_, &TextInputWidget::stoppedTyping, this, [=]() {
if (!userSettings_->isTypingNotificationsEnabled())
return;
typingRefresher_->stop();
client_->removeTypingNotification(current_room_);
});
connect(typingRefresher_, &QTimer::timeout, this, [=]() {
if (!userSettings_->isTypingNotificationsEnabled())
return;
client_->sendTypingNotification(current_room_);
});
@ -773,6 +787,9 @@ ChatPage::removeInvite(const QString &room_id)
void
ChatPage::updateTypingUsers(const QString &roomid, const std::vector<std::string> &user_ids)
{
if (!userSettings_->isTypingNotificationsEnabled())
return;
QStringList users;
QSettings settings;

View file

@ -20,6 +20,7 @@
#include <QDebug>
#include <QLabel>
#include <QPushButton>
#include <QScrollArea>
#include <QSettings>
#include "Config.h"
@ -36,6 +37,7 @@ UserSettings::load()
isTrayEnabled_ = settings.value("user/window/tray", true).toBool();
isOrderingEnabled_ = settings.value("user/room_ordering", true).toBool();
isGroupViewEnabled_ = settings.value("user/group_view", true).toBool();
isTypingNotificationsEnabled_ = settings.value("user/typing_notifications", true).toBool();
theme_ = settings.value("user/theme", "light").toString();
applyTheme();
@ -83,6 +85,7 @@ UserSettings::save()
settings.endGroup();
settings.setValue("room_ordering", isOrderingEnabled_);
settings.setValue("typing_notifications", isTypingNotificationsEnabled_);
settings.setValue("group_view", isGroupViewEnabled_);
settings.setValue("theme", theme());
settings.endGroup();
@ -152,9 +155,20 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
groupViewLayout->addWidget(groupViewLabel);
groupViewLayout->addWidget(groupViewToggle_, 0, Qt::AlignBottom | Qt::AlignRight);
auto typingLayout = new QHBoxLayout;
typingLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin);
auto typingLabel = new QLabel(tr("Typing notifications"), this);
typingNotifications_ = new Toggle(this);
typingNotifications_->setActiveColor(QColor("#38A3D8"));
typingNotifications_->setInactiveColor(QColor("gray"));
typingLabel->setStyleSheet("font-size: 15px;");
typingLayout->addWidget(typingLabel);
typingLayout->addWidget(typingNotifications_, 0, Qt::AlignBottom | Qt::AlignRight);
auto themeOptionLayout_ = new QHBoxLayout;
themeOptionLayout_->setContentsMargins(0, OptionMargin, 0, OptionMargin);
auto themeLabel_ = new QLabel(tr("App theme"), this);
auto themeLabel_ = new QLabel(tr("Theme"), this);
themeCombo_ = new QComboBox(this);
themeCombo_->addItem("Light");
themeCombo_->addItem("Dark");
@ -179,6 +193,8 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
mainLayout_->addWidget(new HorizontalLine(this));
mainLayout_->addLayout(groupViewLayout);
mainLayout_->addWidget(new HorizontalLine(this));
mainLayout_->addLayout(typingLayout);
mainLayout_->addWidget(new HorizontalLine(this));
mainLayout_->addLayout(themeOptionLayout_);
mainLayout_->addWidget(new HorizontalLine(this));
@ -203,6 +219,10 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
settings_->setGroupView(!isDisabled);
});
connect(typingNotifications_, &Toggle::toggled, this, [=](bool isDisabled) {
settings_->setTypingNotifications(!isDisabled);
});
connect(backBtn_, &QPushButton::clicked, this, [=]() {
settings_->save();
emit moveBack();
@ -218,6 +238,7 @@ UserSettingsPage::showEvent(QShowEvent *)
trayToggle_->setState(!settings_->isTrayEnabled());
roomOrderToggle_->setState(!settings_->isOrderingEnabled());
groupViewToggle_->setState(!settings_->isGroupViewEnabled());
typingNotifications_->setState(!settings_->isTypingNotificationsEnabled());
}
void