Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Telegram/Resources/langs/lang.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
9 changes: 9 additions & 0 deletions Telegram/SourceFiles/core/core_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -445,6 +446,7 @@ QByteArray Settings::serialize() const {
stream << key << value;
}
stream << qint32(SerializePlaybackSpeed(_audioPlaybackSpeed.current()));
stream << qint32(_defaultScheduleTime);
}

Ensures(result.size() == size);
Expand Down Expand Up @@ -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()"));
Expand Down
9 changes: 9 additions & 0 deletions Telegram/SourceFiles/core/core_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,13 @@ class Settings final {
_notificationsVolume = value;
}

[[nodiscard]] TimeId defaultScheduleTime() const {
return _defaultScheduleTime;
}
void setDefaultScheduleTime(TimeId value) {
_defaultScheduleTime = value;
}

template <typename Type, typename Other>
void writePref(std::string_view key, Other &&value) {
writePrefImpl<Type>(key, std::forward<Other>(value));
Expand Down Expand Up @@ -1202,6 +1209,8 @@ class Settings final {

ushort _notificationsVolume = 100;

TimeId _defaultScheduleTime = 600; // 10 minutes in seconds

QByteArray _photoEditorBrush;

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<PeerData*> peer) {
Expand Down
91 changes: 90 additions & 1 deletion Telegram/SourceFiles/settings/sections/settings_chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -1802,6 +1803,94 @@ void SetupMessages(
} });
}

Ui::AddSkip(inner, st::settingsCheckboxesSkip);

// Default schedule time dropdown
const auto scheduleValues = std::make_shared<std::vector<TimeId>>(std::vector<TimeId>{
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<rpl::variable<TimeId>>(
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<QString>();
for (const auto value : *scheduleValues) {
list.push_back(formatScheduleTime(value, true));
}
show->showBox(Box([=](not_null<Ui::GenericBox*> 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);
}

Expand Down Expand Up @@ -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(),
} });
Expand Down