Allow turning off inactive accounts notifications.

This commit is contained in:
John Preston 2020-06-30 22:11:48 +04:00
parent 5cc7c2b6c6
commit 1dc31c7f2f
5 changed files with 61 additions and 2 deletions

View File

@ -292,6 +292,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_settings_empty_bio" = "None";
"lng_settings_section_notify" = "Notifications";
"lng_settings_show_from" = "Show notifications from";
"lng_settings_notify_all" = "All accounts";
"lng_settings_notify_all_about" = "Turn this off if you want to receive notifications only from the account you are currently using.";
"lng_settings_notify_title" = "Notifications for chats";
"lng_settings_desktop_notify" = "Desktop notifications";
"lng_settings_show_name" = "Show sender's name";

View File

@ -104,7 +104,8 @@ QByteArray Settings::serialize() const {
0,
1000000))
<< qint32(_thirdColumnWidth.current())
<< qint32(_thirdSectionExtendedBy);
<< qint32(_thirdSectionExtendedBy)
<< qint32(_notifyFromAll ? 1 : 0);
}
return result;
}
@ -167,6 +168,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
float64 dialogsWidthRatio = _dialogsWidthRatio.current();
qint32 thirdColumnWidth = _thirdColumnWidth.current();
qint32 thirdSectionExtendedBy = _thirdSectionExtendedBy;
qint32 notifyFromAll = _notifyFromAll ? 1 : 0;
stream >> themesAccentColors;
if (!stream.atEnd()) {
@ -237,7 +239,8 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
>> thirdSectionInfoEnabled
>> dialogsWidthRatioInt
>> thirdColumnWidth
>> thirdSectionExtendedBy;
>> thirdSectionExtendedBy
>> notifyFromAll;
dialogsWidthRatio = snap(dialogsWidthRatioInt / 1000000., 0., 1.);
}
if (stream.status() != QDataStream::Ok) {
@ -331,6 +334,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
if (_thirdSectionInfoEnabled) {
_tabbedSelectorSectionEnabled = false;
}
_notifyFromAll = (notifyFromAll == 1);
}
bool Settings::chatWide() const {
@ -462,6 +466,7 @@ void Settings::resetOnLastLogout() {
_thirdSectionExtendedBy = -1; // per-window
_dialogsWidthRatio = DefaultDialogsWidthRatio(); // per-window
_thirdColumnWidth = kDefaultThirdColumnWidth; // p-w
_notifyFromAll = true;
_tabbedReplacedWithInfo = false; // per-window
}

View File

@ -401,6 +401,12 @@ public:
void setThirdColumnWidth(int width);
[[nodiscard]] int thirdColumnWidth() const;
[[nodiscard]] rpl::producer<int> thirdColumnWidthChanges() const;
void setNotifyFromAll(bool value) {
_notifyFromAll = value;
}
[[nodiscard]] bool notifyFromAll() const {
return _notifyFromAll;
}
[[nodiscard]] static bool ThirdColumnByDefault();
[[nodiscard]] float64 DefaultDialogsWidthRatio();
@ -467,6 +473,7 @@ private:
int _thirdSectionExtendedBy = -1; // per-window
rpl::variable<float64> _dialogsWidthRatio; // per-window
rpl::variable<int> _thirdColumnWidth = kDefaultThirdColumnWidth; // p-w
bool _notifyFromAll = true;
bool _tabbedReplacedWithInfo = false; // per-window
rpl::event_stream<bool> _tabbedReplacedWithInfoValue; // per-window

View File

@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mainwindow.h"
#include "core/application.h"
#include "main/main_session.h"
#include "main/main_account.h"
#include "main/main_domain.h"
#include "apiwrap.h"
#include "facades.h"
@ -540,9 +541,49 @@ void SetupAdvancedNotifications(
AddSkip(container, st::settingsCheckboxesSkip);
}
void SetupMultiAccountNotifications(
not_null<Window::SessionController*> controller,
not_null<Ui::VerticalLayout*> container) {
if (Core::App().domain().accounts().size() < 2) {
return;
}
AddSubsectionTitle(container, tr::lng_settings_show_from());
const auto fromAll = container->add(
object_ptr<Ui::Checkbox>(
container,
tr::lng_settings_notify_all(tr::now),
Core::App().settings().notifyFromAll(),
st::settingsCheckbox),
st::settingsCheckboxPadding);
fromAll->checkedChanges(
) | rpl::filter([](bool checked) {
return (checked != Core::App().settings().notifyFromAll());
}) | rpl::start_with_next([=](bool checked) {
Core::App().settings().setNotifyFromAll(checked);
Core::App().saveSettingsDelayed();
if (!checked) {
auto &notifications = Core::App().notifications();
const auto &list = Core::App().domain().accounts();
for (const auto &[index, account] : list) {
if (account.get() == &Core::App().domain().active()) {
continue;
} else if (const auto session = account->maybeSession()) {
notifications.clearFromSession(session);
}
}
}
}, fromAll->lifetime());
AddSkip(container);
AddDividerText(container, tr::lng_settings_notify_all_about());
}
void SetupNotificationsContent(
not_null<Window::SessionController*> controller,
not_null<Ui::VerticalLayout*> container) {
SetupMultiAccountNotifications(controller, container);
AddSubsectionTitle(container, tr::lng_settings_notify_title());
const auto session = &controller->session();

View File

@ -89,6 +89,9 @@ System::SkipState System::skipNotification(
const auto notifyBy = item->specialNotificationPeer();
if (App::quitting() || !history->currentNotification()) {
return { SkipState::Skip };
} else if (!Core::App().settings().notifyFromAll()
&& &history->session().account() != &Core::App().domain().active()) {
return { SkipState::Skip };
}
const auto scheduled = item->out() && item->isFromScheduled();