2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Suggest start export when time comes.

This commit is contained in:
John Preston
2018-06-23 00:18:43 +01:00
parent 844d030332
commit 0143fd28af
12 changed files with 123 additions and 11 deletions

View File

@@ -20,7 +20,6 @@ namespace Export {
struct Settings;
namespace Data {
using TimeId = int32;
using Utf8String = QByteArray;
using PeerId = uint64;

View File

@@ -180,7 +180,7 @@ struct ApiWrap::LeftChannelsProcess : ChatsProcess {
struct ApiWrap::DialogsProcess : ChatsProcess {
int splitIndexPlusOne = 0;
Data::TimeId offsetDate = 0;
TimeId offsetDate = 0;
int32 offsetId = 0;
MTPInputPeer offsetPeer = MTP_inputPeerEmpty();
};

View File

@@ -76,6 +76,8 @@ struct Settings {
Types fullChats = DefaultFullChats();
MediaSettings media;
TimeId availableAt = 0;
static inline Types DefaultTypes() {
return Type::PersonalInfo
| Type::Userpics

View File

@@ -17,6 +17,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "storage/localstorage.h"
#include "core/file_utilities.h"
#include "platform/platform_specific.h"
#include "auth_session.h"
#include "data/data_session.h"
#include "styles/style_export.h"
#include "styles/style_boxes.h"
@@ -24,11 +26,72 @@ namespace Export {
namespace View {
namespace {
constexpr auto kAddDelay = TimeId(60);
constexpr auto kSaveSettingsTimeout = TimeMs(1000);
class SuggestBox : public BoxContent {
public:
SuggestBox(QWidget*);
protected:
void prepare() override;
private:
bool _cleared = false;
};
SuggestBox::SuggestBox(QWidget*) {
}
void SuggestBox::prepare() {
setTitle(langFactory(lng_export_suggest_title));
const auto clear = [=] {
if (_cleared) {
return;
}
_cleared = true;
auto settings = Local::ReadExportSettings();
settings.availableAt = 0;
Local::WriteExportSettings(settings);
};
addButton(langFactory(lng_box_ok), [=] {
clear();
closeBox();
Auth().data().startExport();
});
addButton(langFactory(lng_export_suggest_cancel), [=] { closeBox(); });
setCloseByOutsideClick(false);
const auto content = Ui::CreateChild<Ui::FlatLabel>(
this,
lang(lng_export_suggest_text),
Ui::FlatLabel::InitType::Simple,
st::boxLabel);
widthValue(
) | rpl::start_with_next([=](int width) {
const auto contentWidth = width
- st::boxPadding.left()
- st::boxPadding.right();
content->resizeToWidth(contentWidth);
content->moveToLeft(st::boxPadding.left(), 0);
}, content->lifetime());
content->heightValue(
) | rpl::start_with_next([=](int height) {
setDimensions(st::boxWidth, height + st::boxPadding.bottom());
}, content->lifetime());
boxClosing() | rpl::start_with_next(clear, lifetime());
}
} // namespace
void SuggestStart() {
Ui::show(Box<SuggestBox>(), LayerOption::KeepOther);
}
PanelController::PanelController(not_null<ControllerWrap*> process)
: _process(process)
, _settings(std::make_unique<Settings>(Local::ReadExportSettings()))
@@ -91,10 +154,15 @@ void PanelController::showError(const ApiErrorState &error) {
showError(lang(lng_export_invalid));
} else if (error.data.type().startsWith(qstr("TAKEOUT_INIT_DELAY_"))) {
const auto seconds = std::max(error.data.type().mid(
qstr("TAKEOUT_INIT_DELAY_").size()).toInt(), 0) + kAddDelay;
qstr("TAKEOUT_INIT_DELAY_").size()).toInt(), 1);
const auto now = QDateTime::currentDateTime();
const auto when = now.addSecs(seconds);
showError(lng_export_delay(lt_date, langDateTimeFull(when)));
_settings->availableAt = unixtime() + seconds;
_saveSettingsTimer.callOnce(kSaveSettingsTimeout);
Auth().data().suggestStartExport(_settings->availableAt);
} else {
showCriticalError("API Error happened :(\n"
+ QString::number(error.data.code()) + ": " + error.data.type()

View File

@@ -21,6 +21,8 @@ class SeparatePanel;
namespace Export {
namespace View {
void SuggestStart();
class Panel;
class PanelController {