Show reload toast inside Support::Templates.

This commit is contained in:
John Preston 2018-11-16 09:51:47 +04:00
parent 123523ef62
commit d6b4448d3c
3 changed files with 29 additions and 23 deletions

View File

@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "support/support_templates.h"
#include "ui/toast/toast.h"
#include "data/data_session.h"
#include "auth_session.h"
@ -447,10 +448,21 @@ struct Templates::Updates {
};
Templates::Templates(not_null<AuthSession*> session) : _session(session) {
reload();
load();
}
void Templates::reload() {
_reloadToastSubscription = errors(
) | rpl::start_with_next([=](QStringList errors) {
Ui::Toast::Show(errors.isEmpty()
? "Templates reloaded!"
: ("Errors:\n\n" + errors.join("\n\n")));
});
load();
}
void Templates::load() {
if (_reloadAfterRead) {
return;
} else if (_reading.alive() || _updates) {
@ -465,23 +477,23 @@ void Templates::reload() {
result.index = ComputeIndex(result.result);
crl::on_main([
=,
result = std::move(result),
guard = std::move(guard)
result = std::move(result),
guard = std::move(guard)
]() mutable {
if (!guard.alive()) {
return;
if (!guard.alive()) {
return;
}
setData(std::move(result.result));
_index = std::move(result.index);
_errors.fire(std::move(result.errors));
crl::on_main(this, [=] {
if (base::take(_reloadAfterRead)) {
reload();
} else {
update();
}
setData(std::move(result.result));
_index = std::move(result.index);
_errors.fire(std::move(result.errors));
crl::on_main(this, [=] {
if (base::take(_reloadAfterRead)) {
reload();
} else {
update();
}
});
});
});
});
}

View File

@ -68,6 +68,7 @@ public:
private:
struct Updates;
void load();
void update();
void ensureUpdatesCreated();
void updateRequestFinished(QNetworkReply *reply);
@ -81,6 +82,7 @@ private:
rpl::event_stream<QStringList> _errors;
base::binary_guard _reading;
bool _reloadAfterRead = false;
rpl::lifetime _reloadToastSubscription;
int _maxKeyLength = 0;

View File

@ -11,7 +11,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/buttons.h"
#include "ui/widgets/labels.h"
#include "ui/widgets/menu.h"
#include "ui/toast/toast.h"
#include "ui/special_buttons.h"
#include "ui/empty_userpic.h"
#include "mainwindow.h"
@ -212,14 +211,7 @@ void MainMenu::refreshMenu() {
(*fix)->setCheckable(true);
(*fix)->setChecked(Auth().settings().supportFixChatsOrder());
const auto subscription = Ui::AttachAsChild(_menu, rpl::lifetime());
_menu->addAction(qsl("Reload templates"), [=] {
*subscription = Auth().supportTemplates().errors(
) | rpl::start_with_next([=](QStringList errors) {
Ui::Toast::Show(errors.isEmpty()
? "Templates reloaded!"
: ("Errors:\n\n" + errors.join("\n\n")));
});
Auth().supportTemplates().reload();
}, &st::mainMenuReload, &st::mainMenuReloadOver);
}