Fixed a keeping online status after application quit.

Fixes https://github.com/telegramdesktop/tdesktop/issues/5528.
This commit is contained in:
23rd 2019-01-31 23:36:15 +03:00 committed by John Preston
parent 27528d084f
commit 769923c6cc
3 changed files with 39 additions and 1 deletions

View File

@ -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;
}

View File

@ -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();

View File

@ -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<MTPint> ids, const MTPVector<MTPint> &result, mtpRequestId req);
bool viewsIncrementFail(const RPCError &error, mtpRequestId req);
void updateStatusDone(const MTPBool &result);
bool updateStatusFail(const RPCError &error);
void refreshResizeAreas();
template <typename MoveCallback, typename FinishCallback>
void createResizeArea(