Moved DBINotifyView to Core::Settings.

This commit is contained in:
23rd 2021-05-27 23:41:48 +03:00
parent 5334372671
commit da3e140069
7 changed files with 42 additions and 34 deletions

View file

@ -432,11 +432,11 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
_soundNotify = (soundNotify == 1); _soundNotify = (soundNotify == 1);
_desktopNotify = (desktopNotify == 1); _desktopNotify = (desktopNotify == 1);
_flashBounceNotify = (flashBounceNotify == 1); _flashBounceNotify = (flashBounceNotify == 1);
const auto uncheckedNotifyView = static_cast<DBINotifyView>(notifyView); const auto uncheckedNotifyView = static_cast<NotifyView>(notifyView);
switch (uncheckedNotifyView) { switch (uncheckedNotifyView) {
case dbinvShowNothing: case NotifyView::ShowNothing:
case dbinvShowName: case NotifyView::ShowName:
case dbinvShowPreview: _notifyView = uncheckedNotifyView; break; case NotifyView::ShowPreview: _notifyView = uncheckedNotifyView; break;
} }
switch (nativeNotifications) { switch (nativeNotifications) {
case 0: _nativeNotifications = std::nullopt; break; case 0: _nativeNotifications = std::nullopt; break;
@ -732,7 +732,7 @@ void Settings::resetOnLastLogout() {
_soundNotify = true; _soundNotify = true;
_desktopNotify = true; _desktopNotify = true;
_flashBounceNotify = true; _flashBounceNotify = true;
_notifyView = dbinvShowPreview; _notifyView = NotifyView::ShowPreview;
//_nativeNotifications = std::nullopt; //_nativeNotifications = std::nullopt;
//_notificationsCount = 3; //_notificationsCount = 3;
//_notificationsCorner = ScreenCorner::BottomRight; //_notificationsCorner = ScreenCorner::BottomRight;

View file

@ -48,6 +48,11 @@ public:
BottomRight = 2, BottomRight = 2,
BottomLeft = 3, BottomLeft = 3,
}; };
enum class NotifyView {
ShowPreview = 0,
ShowName = 1,
ShowNothing = 2,
};
static constexpr auto kDefaultVolume = 0.9; static constexpr auto kDefaultVolume = 0.9;
@ -147,10 +152,10 @@ public:
void setFlashBounceNotify(bool value) { void setFlashBounceNotify(bool value) {
_flashBounceNotify = value; _flashBounceNotify = value;
} }
[[nodiscard]] DBINotifyView notifyView() const { [[nodiscard]] NotifyView notifyView() const {
return _notifyView; return _notifyView;
} }
void setNotifyView(DBINotifyView value) { void setNotifyView(NotifyView value) {
_notifyView = value; _notifyView = value;
} }
[[nodiscard]] bool nativeNotifications() const { [[nodiscard]] bool nativeNotifications() const {
@ -598,7 +603,7 @@ private:
bool _soundNotify = true; bool _soundNotify = true;
bool _desktopNotify = true; bool _desktopNotify = true;
bool _flashBounceNotify = true; bool _flashBounceNotify = true;
DBINotifyView _notifyView = dbinvShowPreview; NotifyView _notifyView = NotifyView::ShowPreview;
std::optional<bool> _nativeNotifications; std::optional<bool> _nativeNotifications;
int _notificationsCount = 3; int _notificationsCount = 3;
ScreenCorner _notificationsCorner = ScreenCorner::BottomRight; ScreenCorner _notificationsCorner = ScreenCorner::BottomRight;

View file

@ -121,12 +121,6 @@ void memset_rand(void *data, uint32 len);
QString translitRusEng(const QString &rus); QString translitRusEng(const QString &rus);
QString rusKeyboardLayoutSwitch(const QString &from); QString rusKeyboardLayoutSwitch(const QString &from);
enum DBINotifyView {
dbinvShowPreview = 0,
dbinvShowName = 1,
dbinvShowNothing = 2,
};
enum DBIWorkMode { enum DBIWorkMode {
dbiwmWindowAndTray = 0, dbiwmWindowAndTray = 0,
dbiwmTrayOnly = 1, dbiwmTrayOnly = 1,

View file

@ -582,6 +582,7 @@ void SetupMultiAccountNotifications(
void SetupNotificationsContent( void SetupNotificationsContent(
not_null<Window::SessionController*> controller, not_null<Window::SessionController*> controller,
not_null<Ui::VerticalLayout*> container) { not_null<Ui::VerticalLayout*> container) {
using NotifyView = Core::Settings::NotifyView;
SetupMultiAccountNotifications(controller, container); SetupMultiAccountNotifications(controller, container);
AddSubsectionTitle(container, tr::lng_settings_notify_title()); AddSubsectionTitle(container, tr::lng_settings_notify_title());
@ -612,10 +613,10 @@ void SetupNotificationsContent(
settings.desktopNotify()); settings.desktopNotify());
const auto name = addSlidingCheckbox( const auto name = addSlidingCheckbox(
tr::lng_settings_show_name(tr::now), tr::lng_settings_show_name(tr::now),
(settings.notifyView() <= dbinvShowName)); (settings.notifyView() <= NotifyView::ShowName));
const auto preview = addSlidingCheckbox( const auto preview = addSlidingCheckbox(
tr::lng_settings_show_preview(tr::now), tr::lng_settings_show_preview(tr::now),
(settings.notifyView() <= dbinvShowPreview)); (settings.notifyView() <= NotifyView::ShowPreview));
const auto sound = addCheckbox( const auto sound = addCheckbox(
tr::lng_settings_sound_notify(tr::now), tr::lng_settings_sound_notify(tr::now),
settings.soundNotify()); settings.soundNotify());
@ -752,14 +753,14 @@ void SetupNotificationsContent(
name->entity()->checkedChanges( name->entity()->checkedChanges(
) | rpl::map([=](bool checked) { ) | rpl::map([=](bool checked) {
if (!checked) { if (!checked) {
return dbinvShowNothing; return NotifyView::ShowNothing;
} else if (!preview->entity()->checked()) { } else if (!preview->entity()->checked()) {
return dbinvShowName; return NotifyView::ShowName;
} }
return dbinvShowPreview; return NotifyView::ShowPreview;
}) | rpl::filter([=](DBINotifyView value) { }) | rpl::filter([=](NotifyView value) {
return (value != Core::App().settings().notifyView()); return (value != Core::App().settings().notifyView());
}) | rpl::start_with_next([=](DBINotifyView value) { }) | rpl::start_with_next([=](NotifyView value) {
Core::App().settings().setNotifyView(value); Core::App().settings().setNotifyView(value);
changed(Change::ViewParams); changed(Change::ViewParams);
}, name->lifetime()); }, name->lifetime());
@ -767,14 +768,14 @@ void SetupNotificationsContent(
preview->entity()->checkedChanges( preview->entity()->checkedChanges(
) | rpl::map([=](bool checked) { ) | rpl::map([=](bool checked) {
if (checked) { if (checked) {
return dbinvShowPreview; return NotifyView::ShowPreview;
} else if (name->entity()->checked()) { } else if (name->entity()->checked()) {
return dbinvShowName; return NotifyView::ShowName;
} }
return dbinvShowNothing; return NotifyView::ShowNothing;
}) | rpl::filter([=](DBINotifyView value) { }) | rpl::filter([=](NotifyView value) {
return (value != Core::App().settings().notifyView()); return (value != Core::App().settings().notifyView());
}) | rpl::start_with_next([=](DBINotifyView value) { }) | rpl::start_with_next([=](NotifyView value) {
Core::App().settings().setNotifyView(value); Core::App().settings().setNotifyView(value);
changed(Change::ViewParams); changed(Change::ViewParams);
}, preview->lifetime()); }, preview->lifetime());

View file

@ -881,11 +881,16 @@ bool ReadSetting(
stream >> v; stream >> v;
if (!CheckStreamStatus(stream)) return false; if (!CheckStreamStatus(stream)) return false;
switch (v) { const auto newView = [&] {
case dbinvShowNothing: Core::App().settings().setNotifyView(dbinvShowNothing); break; using Notify = Core::Settings::NotifyView;
case dbinvShowName: Core::App().settings().setNotifyView(dbinvShowName); break; switch (static_cast<Notify>(v)) {
default: Core::App().settings().setNotifyView(dbinvShowPreview); break; case Notify::ShowNothing: return Notify::ShowNothing;
} case Notify::ShowName: return Notify::ShowName;
}
return Notify::ShowPreview;
}();
Core::App().settings().setNotifyView(newView);
context.legacyRead = true; context.legacyRead = true;
} break; } break;

View file

@ -594,8 +594,10 @@ Manager::DisplayOptions Manager::getNotificationOptions(
const auto view = Core::App().settings().notifyView(); const auto view = Core::App().settings().notifyView();
DisplayOptions result; DisplayOptions result;
result.hideNameAndPhoto = hideEverything || (view > dbinvShowName); result.hideNameAndPhoto = hideEverything
result.hideMessageText = hideEverything || (view > dbinvShowPreview); || (view > Core::Settings::NotifyView::ShowName);
result.hideMessageText = hideEverything
|| (view > Core::Settings::NotifyView::ShowPreview);
result.hideReplyButton = result.hideMessageText result.hideReplyButton = result.hideMessageText
|| !item || !item
|| ((item->out() || item->history()->peer->isSelf()) || ((item->out() || item->history()->peer->isSelf())

View file

@ -902,7 +902,8 @@ bool Notification::canReply() const {
return !_hideReplyButton return !_hideReplyButton
&& (_item != nullptr) && (_item != nullptr)
&& !Core::App().passcodeLocked() && !Core::App().passcodeLocked()
&& (Core::App().settings().notifyView() <= dbinvShowPreview); && (Core::App().settings().notifyView()
<= Core::Settings::NotifyView::ShowPreview);
} }
void Notification::unlinkHistoryInManager() { void Notification::unlinkHistoryInManager() {