diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index cc406729e428fc..5838490f517a0b 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -702,6 +702,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_settings_chat_quick_action_react" = "Send reaction with double click"; "lng_settings_chat_corner_reply" = "Reply button on messages"; "lng_settings_chat_corner_reaction" = "Reaction button on messages"; +"lng_settings_default_schedule_time" = "Default schedule time"; "lng_settings_shortcuts" = "Keyboard shortcuts"; diff --git a/Telegram/SourceFiles/core/core_settings.cpp b/Telegram/SourceFiles/core/core_settings.cpp index 2ab79584859b6c..4f5f4abccde866 100644 --- a/Telegram/SourceFiles/core/core_settings.cpp +++ b/Telegram/SourceFiles/core/core_settings.cpp @@ -271,6 +271,7 @@ QByteArray Settings::serialize() const { + Serialize::bytearraySize(value); } size += sizeof(qint32); // _audioPlaybackSpeed + size += sizeof(qint32); // _defaultScheduleTime auto result = QByteArray(); result.reserve(size); @@ -445,6 +446,7 @@ QByteArray Settings::serialize() const { stream << key << value; } stream << qint32(SerializePlaybackSpeed(_audioPlaybackSpeed.current())); + stream << qint32(_defaultScheduleTime); } Ensures(result.size() == size); @@ -959,6 +961,13 @@ void Settings::addFromSerialized(const QByteArray &serialized) { audioPlaybackSpeed = speed; } } + if (!stream.atEnd()) { + auto defaultScheduleTime = qint32(); + stream >> defaultScheduleTime; + if (stream.status() == QDataStream::Ok) { + _defaultScheduleTime = defaultScheduleTime; + } + } if (stream.status() != QDataStream::Ok) { LOG(("App Error: " "Bad data for Core::Settings::constructFromSerialized()")); diff --git a/Telegram/SourceFiles/core/core_settings.h b/Telegram/SourceFiles/core/core_settings.h index 26da92fd8f6b14..c07de46c04a7b7 100644 --- a/Telegram/SourceFiles/core/core_settings.h +++ b/Telegram/SourceFiles/core/core_settings.h @@ -1025,6 +1025,13 @@ class Settings final { _notificationsVolume = value; } + [[nodiscard]] TimeId defaultScheduleTime() const { + return _defaultScheduleTime; + } + void setDefaultScheduleTime(TimeId value) { + _defaultScheduleTime = value; + } + template void writePref(std::string_view key, Other &&value) { writePrefImpl(key, std::forward(value)); @@ -1202,6 +1209,8 @@ class Settings final { ushort _notificationsVolume = 100; + TimeId _defaultScheduleTime = 600; // 10 minutes in seconds + QByteArray _photoEditorBrush; }; diff --git a/Telegram/SourceFiles/history/view/history_view_schedule_box.cpp b/Telegram/SourceFiles/history/view/history_view_schedule_box.cpp index b42c48b1d91268..4aa1a64d7aa19a 100644 --- a/Telegram/SourceFiles/history/view/history_view_schedule_box.cpp +++ b/Telegram/SourceFiles/history/view/history_view_schedule_box.cpp @@ -9,6 +9,8 @@ For license and copyright information please follow this link: #include "api/api_common.h" #include "chat_helpers/compose/compose_show.h" +#include "core/application.h" +#include "core/core_settings.h" #include "data/data_peer.h" #include "data/data_peer_values.h" #include "data/data_user.h" @@ -207,7 +209,7 @@ ScheduleBoxStyleArgs::ScheduleBoxStyleArgs() } TimeId DefaultScheduleTime() { - return base::unixtime::now() + 600; + return base::unixtime::now() + Core::App().settings().defaultScheduleTime(); } bool CanScheduleUntilOnline(not_null peer) { diff --git a/Telegram/SourceFiles/settings/sections/settings_chat.cpp b/Telegram/SourceFiles/settings/sections/settings_chat.cpp index 6ab0a4d2b7f78f..9530f224fc1c9d 100644 --- a/Telegram/SourceFiles/settings/sections/settings_chat.cpp +++ b/Telegram/SourceFiles/settings/sections/settings_chat.cpp @@ -24,6 +24,7 @@ For license and copyright information please follow this link: #include "boxes/reactions_settings_box.h" #include "boxes/stickers_box.h" #include "ui/boxes/confirm_box.h" +#include "ui/boxes/single_choice_box.h" #include "boxes/background_box.h" #include "boxes/background_preview_box.h" #include "boxes/download_path_box.h" @@ -1802,6 +1803,94 @@ void SetupMessages( } }); } + Ui::AddSkip(inner, st::settingsCheckboxesSkip); + + // Default schedule time dropdown + const auto scheduleValues = std::make_shared>(std::vector{ + 300, // 5 minutes + 600, // 10 minutes (default) + 900, // 15 minutes + 1800, // 30 minutes + 3600, // 1 hour + 7200, // 2 hours + 14400, // 4 hours + 28800, // 8 hours + 86400, // 1 day + 172800, // 2 days + 259200, // 3 days + 604800, // 7 days + }); + + const auto formatScheduleTime = [](TimeId seconds, bool showDefault = false) -> QString { + QString result; + if (seconds < 60) { + result = QString::number(seconds) + u" seconds"_q; + } else if (seconds < 3600) { + const auto minutes = seconds / 60; + result = QString::number(minutes) + (minutes == 1 ? u" minute"_q : u" minutes"_q); + } else if (seconds < 86400) { + const auto hours = seconds / 3600; + result = QString::number(hours) + (hours == 1 ? u" hour"_q : u" hours"_q); + } else { + const auto days = seconds / 86400; + result = QString::number(days) + (days == 1 ? u" day"_q : u" days"_q); + } + if (showDefault && seconds == 600) { + result += u" (default)"_q; + } + return result; + }; + + const auto currentValue = inner->lifetime().make_state>( + Core::App().settings().defaultScheduleTime()); + + const auto scheduleButton = AddButtonWithLabel( + inner, + tr::lng_settings_default_schedule_time(), + currentValue->value() | rpl::map([=](TimeId seconds) { + return formatScheduleTime(seconds); + }), + st::settingsButton, + { &st::menuIconSchedule }); + + scheduleButton->addClickHandler([=, show = controller->uiShow()] { + auto list = std::vector(); + for (const auto value : *scheduleValues) { + list.push_back(formatScheduleTime(value, true)); + } + show->showBox(Box([=](not_null box) { + const auto save = [=](int index) { + if (index >= 0 && index < int(scheduleValues->size())) { + const auto newValue = (*scheduleValues)[index]; + Core::App().settings().setDefaultScheduleTime(newValue); + Core::App().saveSettingsDelayed(); + *currentValue = newValue; + box->closeBox(); + } + }; + SingleChoiceBox(box, { + .title = tr::lng_settings_default_schedule_time(), + .options = list, + .initialSelection = [&] { + const auto current = Core::App().settings().defaultScheduleTime(); + for (auto i = 0; i < int(scheduleValues->size()); ++i) { + if ((*scheduleValues)[i] == current) { + return i; + } + } + return 1; // Default to 10 minutes + }(), + .callback = save, + }); + })); + }); + if (highlights) { + highlights->push_back({ u"chat/default-schedule-time"_q, { + scheduleButton.get(), + { .rippleShape = true }, + } }); + } + Ui::AddSkip(inner); } @@ -2020,7 +2109,7 @@ void SetupChatBackground( row->chooseFromGallery(), SubsectionTitleHighlight(), } }); - highlights->push_back({ u"chat/wallpapers-choose-photo"_q, { + highlights->push_back({ u"chat/wallpapers-choose-photo"_q, { row->chooseFromFile(), SubsectionTitleHighlight(), } });