From 39b0d9e46f83bd6b1f28e9f2d37c56a131001b3c Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 10 Jul 2018 23:15:54 +0300 Subject: [PATCH] Handle the outdated app error in passport. --- Telegram/Resources/langs/lang.strings | 1 + Telegram/SourceFiles/core/update_checker.cpp | 1 + .../passport/passport_form_controller.cpp | 8 ++++++-- .../passport/passport_form_view_controller.h | 1 + .../SourceFiles/passport/passport_panel.cpp | 1 + .../passport/passport_panel_controller.cpp | 19 +++++++++++++++++++ .../passport/passport_panel_controller.h | 1 + .../SourceFiles/ui/widgets/separate_panel.cpp | 6 ++++-- 8 files changed, 34 insertions(+), 4 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index ef23987eb..aa0919c03 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1665,6 +1665,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_passport_error_cant_read" = "Can't read this file. Please choose an image."; "lng_passport_bad_name" = "Please use latin characters only."; "lng_passport_wait_upload" = "Please wait while upload is finished."; +"lng_passport_app_out_of_date" = "Sorry, your Telegram app is out of date and can't handle this request. Please update Telegram."; "lng_export_title" = "Export Personal Data"; "lng_export_progress_title" = "Exporting personal data"; diff --git a/Telegram/SourceFiles/core/update_checker.cpp b/Telegram/SourceFiles/core/update_checker.cpp index e8236c472..c797d9001 100644 --- a/Telegram/SourceFiles/core/update_checker.cpp +++ b/Telegram/SourceFiles/core/update_checker.cpp @@ -2108,6 +2108,7 @@ void UpdateApplication() { if (weak) { weak->scrollToUpdateRow(); } + window->showFromTray(); } } diff --git a/Telegram/SourceFiles/passport/passport_form_controller.cpp b/Telegram/SourceFiles/passport/passport_form_controller.cpp index 5b2602fa9..d12aab3e8 100644 --- a/Telegram/SourceFiles/passport/passport_form_controller.cpp +++ b/Telegram/SourceFiles/passport/passport_form_controller.cpp @@ -2060,8 +2060,12 @@ void FormController::parseForm(const MTPaccount_AuthorizationForm &result) { void FormController::formFail(const QString &error) { _savedPasswordValue = QByteArray(); _serviceErrorText = error; - _view->showCriticalError( - lang(lng_passport_form_error) + "\n" + error); + if (error == "APP_VERSION_OUTDATED") { + _view->showUpdateAppBox(); + } else { + _view->showCriticalError( + lang(lng_passport_form_error) + "\n" + error); + } } void FormController::requestPassword() { diff --git a/Telegram/SourceFiles/passport/passport_form_view_controller.h b/Telegram/SourceFiles/passport/passport_form_view_controller.h index c06165e3d..b32729345 100644 --- a/Telegram/SourceFiles/passport/passport_form_view_controller.h +++ b/Telegram/SourceFiles/passport/passport_form_view_controller.h @@ -43,6 +43,7 @@ public: virtual void showAskPassword() = 0; virtual void showNoPassword() = 0; virtual void showCriticalError(const QString &error) = 0; + virtual void showUpdateAppBox() = 0; virtual void editScope(int index) = 0; virtual void showBox( diff --git a/Telegram/SourceFiles/passport/passport_panel.cpp b/Telegram/SourceFiles/passport/passport_panel.cpp index 754bb7e23..fbf159f53 100644 --- a/Telegram/SourceFiles/passport/passport_panel.cpp +++ b/Telegram/SourceFiles/passport/passport_panel.cpp @@ -98,6 +98,7 @@ void Panel::showBox( LayerOptions options, anim::type animated) { _widget->showBox(std::move(box), options, animated); + _widget->showAndActivate(); } void Panel::showToast(const QString &text) { diff --git a/Telegram/SourceFiles/passport/passport_panel_controller.cpp b/Telegram/SourceFiles/passport/passport_panel_controller.cpp index 7da74a454..da0c3f9b5 100644 --- a/Telegram/SourceFiles/passport/passport_panel_controller.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_controller.cpp @@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/toast/toast.h" #include "ui/rp_widget.h" #include "ui/countryinput.h" +#include "core/update_checker.h" #include "layout.h" #include "styles/style_boxes.h" @@ -812,6 +813,24 @@ void PanelController::showCriticalError(const QString &error) { _panel->showCriticalError(error); } +void PanelController::showUpdateAppBox() { + ensurePanelCreated(); + + const auto box = std::make_shared>(); + const auto callback = [=] { + _form->cancelSure(); + Core::UpdateApplication(); + }; + *box = show( + Box( + lang(lng_passport_app_out_of_date), + lang(lng_menu_update), + callback, + [=] { _form->cancelSure(); }), + LayerOption::KeepOther, + anim::type::instant); +} + void PanelController::ensurePanelCreated() { if (!_panel) { _panel = std::make_unique(this); diff --git a/Telegram/SourceFiles/passport/passport_panel_controller.h b/Telegram/SourceFiles/passport/passport_panel_controller.h index 87b3623f4..b13d03152 100644 --- a/Telegram/SourceFiles/passport/passport_panel_controller.h +++ b/Telegram/SourceFiles/passport/passport_panel_controller.h @@ -97,6 +97,7 @@ public: void showAskPassword() override; void showNoPassword() override; void showCriticalError(const QString &error) override; + void showUpdateAppBox() override; void fillRows( FnsetFocus(); + if (_inner) { + _inner->setFocus(); + } } else { finishClose(); } @@ -317,7 +319,7 @@ void SeparatePanel::focusInEvent(QFocusEvent *e) { crl::on_main(this, [=] { if (_layer) { _layer->setInnerFocus(); - } else if (!_inner->isHidden()) { + } else if (_inner && !_inner->isHidden()) { _inner->setFocus(); } });