diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index 8a11e9c8a..e645c4651 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -1047,6 +1047,11 @@ void Application::preventWindowActivation() { void Application::QuitAttempt() { auto prevents = false; if (AuthSession::Exists() && !Sandbox::Instance().isSavingSession()) { + if (auto mainwidget = App::main()) { + if (mainwidget->isQuitPrevent()) { + prevents = true; + } + } if (Auth().api().isQuitPrevent()) { prevents = true; } diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 859b2143d..6a2970ade 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -3777,7 +3777,14 @@ void MainWidget::updateOnline(bool gotOtherOffline) { _lastWasOnline = isOnline; _lastSetOnline = ms; - _onlineRequest = MTP::send(MTPaccount_UpdateStatus(MTP_bool(!isOnline))); + if (!App::quitting()) { + _onlineRequest = MTP::send(MTPaccount_UpdateStatus(MTP_bool(!isOnline))); + } else { + _onlineRequest = MTP::send( + MTPaccount_UpdateStatus(MTP_bool(!isOnline)), + rpcDone(&MainWidget::updateStatusDone), + rpcFail(&MainWidget::updateStatusFail)); + } const auto self = session().user(); self->onlineTill = unixtime() + (isOnline ? (Global::OnlineUpdatePeriod() / 1000) : -1); @@ -3795,6 +3802,27 @@ void MainWidget::updateOnline(bool gotOtherOffline) { _onlineTimer.callOnce(updateIn); } +void MainWidget::updateStatusDone(const MTPBool &result) { + Core::App().quitPreventFinished(); +} + +bool MainWidget::updateStatusFail(const RPCError &error) { + if (MTP::isDefaultHandledError(error)) { + return false; + } + Core::App().quitPreventFinished(); + return true; +} + +bool MainWidget::isQuitPrevent() { + if (!_lastWasOnline) { + return false; + } + LOG(("MainWidget prevents quit, sending offline status...")); + updateOnline(); + return true; +} + void MainWidget::saveDraftToCloud() { _history->saveFieldToHistoryLocalDraft(); diff --git a/Telegram/SourceFiles/mainwidget.h b/Telegram/SourceFiles/mainwidget.h index 3b39af153..ef1d6b17b 100644 --- a/Telegram/SourceFiles/mainwidget.h +++ b/Telegram/SourceFiles/mainwidget.h @@ -300,6 +300,8 @@ public: void notify_userIsBotChanged(UserData *bot); void notify_historyMuteUpdated(History *history); + bool isQuitPrevent(); + ~MainWidget(); signals: @@ -445,6 +447,9 @@ private: void viewsIncrementDone(QVector ids, const MTPVector &result, mtpRequestId req); bool viewsIncrementFail(const RPCError &error, mtpRequestId req); + void updateStatusDone(const MTPBool &result); + bool updateStatusFail(const RPCError &error); + void refreshResizeAreas(); template void createResizeArea(