diff --git a/Telegram/SourceFiles/application.cpp b/Telegram/SourceFiles/application.cpp index e0c0a1505..db33f9226 100644 --- a/Telegram/SourceFiles/application.cpp +++ b/Telegram/SourceFiles/application.cpp @@ -296,6 +296,14 @@ void Application::cancelPhotoUpdate(const PeerId &peer) { } } +void Application::mtpUnpause() { + QTimer::singleShot(1, this, SLOT(doMtpUnpause())); +} + +void Application::doMtpUnpause() { + MTP::unpause(); +} + void Application::selfPhotoCleared(const MTPUserProfilePhoto &result) { if (!App::self()) return; App::self()->setPhoto(result); diff --git a/Telegram/SourceFiles/application.h b/Telegram/SourceFiles/application.h index 09fb85c22..5876e93b4 100644 --- a/Telegram/SourceFiles/application.h +++ b/Telegram/SourceFiles/application.h @@ -55,6 +55,7 @@ public: #ifndef TDESKTOP_DISABLE_AUTOUPDATE int32 updatingSize(); int32 updatingReady(); + void stopUpdate(); #endif FileUploader *uploader(); @@ -64,7 +65,7 @@ public: bool isPhotoUpdating(const PeerId &peer); void cancelPhotoUpdate(const PeerId &peer); - void stopUpdate(); + void mtpUnpause(); void selfPhotoCleared(const MTPUserProfilePhoto &result); void chatPhotoCleared(PeerId peer, const MTPUpdates &updates); @@ -109,6 +110,8 @@ public slots: void newInstanceConnected(); void closeApplication(); + void doMtpUnpause(); + void readClients(); void removeClients(); diff --git a/Telegram/SourceFiles/dialogswidget.cpp b/Telegram/SourceFiles/dialogswidget.cpp index 11602cb12..1c0c5435c 100644 --- a/Telegram/SourceFiles/dialogswidget.cpp +++ b/Telegram/SourceFiles/dialogswidget.cpp @@ -22,6 +22,7 @@ Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org #include "style.h" #include "lang.h" +#include "application.h" #include "window.h" #include "dialogswidget.h" #include "mainwidget.h" @@ -1572,6 +1573,8 @@ void DialogsWidget::dialogsToUp() { } void DialogsWidget::animShow(const QPixmap &bgAnimCache) { + MTP::pause(); + _bgAnimCache = bgAnimCache; _animCache = myGrab(this, rect()); _scroll.hide(); @@ -1600,6 +1603,8 @@ bool DialogsWidget::animStep(float64 ms) { _filter.show(); onFilterUpdate(true); activate(); + + if (App::app()) App::app()->mtpUnpause(); } else { a_bgCoord.update(dt1, st::introHideFunc); a_bgAlpha.update(dt1, st::introAlphaHideFunc); diff --git a/Telegram/SourceFiles/gui/flattextarea.cpp b/Telegram/SourceFiles/gui/flattextarea.cpp index a5abeba89..f605af98c 100644 --- a/Telegram/SourceFiles/gui/flattextarea.cpp +++ b/Telegram/SourceFiles/gui/flattextarea.cpp @@ -186,6 +186,7 @@ void FlatTextarea::paintEvent(QPaintEvent *e) { p.setPen(a_phColor.current()); p.drawText(phRect, _ph, QTextOption(_st.phAlign)); p.restore(); + p.setOpacity(1); } QTextEdit::paintEvent(e); } diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index ea0c5af8c..ef292da30 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -22,6 +22,7 @@ Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org #include "style.h" #include "lang.h" +#include "application.h" #include "boxes/confirmbox.h" #include "historywidget.h" #include "gui/filedialog.h" @@ -3992,6 +3993,8 @@ HistoryItem *HistoryWidget::atTopImportantMsg(int32 &bottomUnderScrollTop) const } void HistoryWidget::animShow(const QPixmap &bgAnimCache, const QPixmap &bgAnimTopBarCache, bool back) { + MTP::pause(); + _bgAnimCache = bgAnimCache; _bgAnimTopBarCache = bgAnimTopBarCache; _animCache = myGrab(this, rect()); @@ -4042,6 +4045,8 @@ bool HistoryWidget::showStep(float64 ms) { App::main()->topBar()->stopAnim(); App::main()->topBar()->enableShadow(); doneShow(); + + if (App::app()) App::app()->mtpUnpause(); } else { a_bgCoord.update(dt1, st::introHideFunc); a_bgAlpha.update(dt1, st::introAlphaHideFunc); diff --git a/Telegram/SourceFiles/intro/intro.cpp b/Telegram/SourceFiles/intro/intro.cpp index 4b2472ca0..9d6e187ad 100644 --- a/Telegram/SourceFiles/intro/intro.cpp +++ b/Telegram/SourceFiles/intro/intro.cpp @@ -145,6 +145,8 @@ bool IntroWidget::createNext() { } void IntroWidget::prepareMove() { + MTP::pause(); + if (cacheForHide.isNull() || cacheForHideInd != current) makeHideCache(); stages[current + moving]->prepareShow(); @@ -198,6 +200,8 @@ void IntroWidget::makeShowCache(int stage) { } void IntroWidget::animShow(const QPixmap &bgAnimCache, bool back) { + MTP::pause(); + _bgAnimCache = bgAnimCache; anim::stop(this); @@ -245,6 +249,7 @@ bool IntroWidget::animStep(float64 ms) { _back.setOpacity(1); _back.show(); } + if (App::app()) App::app()->mtpUnpause(); } else { a_bgCoord.update(dt1, st::introHideFunc); a_bgAlpha.update(dt1, st::introAlphaHideFunc); @@ -265,6 +270,7 @@ bool IntroWidget::animStep(float64 ms) { if (!stages[current]->hasBack()) { _back.hide(); } + if (App::app()) App::app()->mtpUnpause(); } else { xCoordShow.update(dt2, st::introShowFunc); cAlphaShow.update(dt2, st::introAlphaShowFunc); diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index b0c002590..22536067b 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -2705,6 +2705,8 @@ void MainWidget::historyCleared(History *hist) { } void MainWidget::animShow(const QPixmap &bgAnimCache, bool back) { + MTP::pause(); + _bgAnimCache = bgAnimCache; anim::stop(this); @@ -2737,6 +2739,8 @@ bool MainWidget::animStep(float64 ms) { anim::stop(this); showAll(); activate(); + + if (App::app()) App::app()->mtpUnpause(); } else { a_bgCoord.update(dt1, st::introHideFunc); a_bgAlpha.update(dt1, st::introAlphaHideFunc); diff --git a/Telegram/SourceFiles/mtproto/mtp.cpp b/Telegram/SourceFiles/mtproto/mtp.cpp index 22246480b..ebc6b3853 100644 --- a/Telegram/SourceFiles/mtproto/mtp.cpp +++ b/Telegram/SourceFiles/mtproto/mtp.cpp @@ -352,6 +352,8 @@ namespace { return false; } + bool _paused = false; + } namespace _mtp_internal { @@ -371,6 +373,10 @@ namespace _mtp_internal { sessions.insert(dcWithShift, result); return result; } + + bool paused() { + return _paused; + } void registerRequest(mtpRequestId requestId, int32 dcWithShift) { { @@ -643,6 +649,7 @@ namespace MTP { (*i)->restart(); } } + void restart(int32 dcMask) { if (!_started) return; @@ -654,6 +661,19 @@ namespace MTP { } } + void pause() { + if (!_started) return; + _paused = true; + } + + void unpause() { + if (!_started) return; + _paused = false; + for (Sessions::const_iterator i = sessions.cbegin(), e = sessions.cend(); i != e; ++i) { + (*i)->unpaused(); + } + } + void configure(int32 dc, int32 user) { if (_started) return; mtpSetDC(dc); diff --git a/Telegram/SourceFiles/mtproto/mtp.h b/Telegram/SourceFiles/mtproto/mtp.h index 3cde3f393..acafe616c 100644 --- a/Telegram/SourceFiles/mtproto/mtp.h +++ b/Telegram/SourceFiles/mtproto/mtp.h @@ -26,6 +26,8 @@ Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org namespace _mtp_internal { MTProtoSessionPtr getSession(int32 dc = 0); // 0 - current set dc + bool paused(); + void registerRequest(mtpRequestId requestId, int32 dc); void unregisterRequest(mtpRequestId requestId); @@ -86,6 +88,9 @@ namespace MTP { void restart(); void restart(int32 dcMask); + void pause(); + void unpause(); + void configure(int32 dc, int32 user); void setdc(int32 dc, bool fromZeroOnly = false); diff --git a/Telegram/SourceFiles/mtproto/mtpSession.cpp b/Telegram/SourceFiles/mtproto/mtpSession.cpp index d6dd6c111..4c1495f2c 100644 --- a/Telegram/SourceFiles/mtproto/mtpSession.cpp +++ b/Telegram/SourceFiles/mtproto/mtpSession.cpp @@ -66,7 +66,15 @@ void MTPSessionData::clear() { } -MTProtoSession::MTProtoSession() : _killed(false), data(this), dcWithShift(0), dc(0), msSendCall(0), msWait(0), _ping(false) { +MTProtoSession::MTProtoSession() : QObject() +, _killed(false) +, _needToReceive(false) +, data(this) +, dcWithShift(0) +, dc(0) +, msSendCall(0) +, msWait(0) +, _ping(false) { } void MTProtoSession::start(int32 dcenter) { @@ -144,6 +152,13 @@ void MTProtoSession::kill() { DEBUG_LOG(("Session Info: marked session dcWithShift %1 as killed").arg(dcWithShift)); } +void MTProtoSession::unpaused() { + if (_needToReceive) { + _needToReceive = false; + tryToReceive(); + } +} + void MTProtoSession::sendAnything(quint64 msCanWait) { if (_killed) { DEBUG_LOG(("Session Error: can't send anything in a killed session")); @@ -492,6 +507,10 @@ int32 MTProtoSession::getDcWithShift() const { } void MTProtoSession::tryToReceive() { + if (_mtp_internal::paused()) { + _needToReceive = true; + return; + } int32 cnt = 0; while (true) { mtpRequestId requestId; diff --git a/Telegram/SourceFiles/mtproto/mtpSession.h b/Telegram/SourceFiles/mtproto/mtpSession.h index 95085fdce..d50914ece 100644 --- a/Telegram/SourceFiles/mtproto/mtpSession.h +++ b/Telegram/SourceFiles/mtproto/mtpSession.h @@ -229,6 +229,8 @@ public: void stop(); void kill(); + void unpaused(); + int32 getDcWithShift() const; ~MTProtoSession(); @@ -281,6 +283,7 @@ private: MTProtoConnections connections; bool _killed; + bool _needToReceive; MTPSessionData data; diff --git a/Telegram/SourceFiles/overviewwidget.cpp b/Telegram/SourceFiles/overviewwidget.cpp index d4b7aa18a..8b633ad8e 100644 --- a/Telegram/SourceFiles/overviewwidget.cpp +++ b/Telegram/SourceFiles/overviewwidget.cpp @@ -2776,9 +2776,13 @@ void OverviewWidget::fastShow(bool back, int32 lastScrollTop) { show(); _inner.activate(); doneShow(); + + if (App::app()) App::app()->mtpUnpause(); } void OverviewWidget::animShow(const QPixmap &bgAnimCache, const QPixmap &bgAnimTopBarCache, bool back, int32 lastScrollTop) { + MTP::pause(); + stopGif(); _bgAnimCache = bgAnimCache; _bgAnimTopBarCache = bgAnimTopBarCache; @@ -2814,6 +2818,8 @@ bool OverviewWidget::animStep(float64 ms) { _bgAnimCache = _animCache = _animTopBarCache = _bgAnimTopBarCache = QPixmap(); App::main()->topBar()->stopAnim(); doneShow(); + + if (App::app()) App::app()->mtpUnpause(); } else { a_bgCoord.update(dt1, st::introHideFunc); a_bgAlpha.update(dt1, st::introAlphaHideFunc); diff --git a/Telegram/SourceFiles/passcodewidget.cpp b/Telegram/SourceFiles/passcodewidget.cpp index b92ae82b1..4f75780ce 100644 --- a/Telegram/SourceFiles/passcodewidget.cpp +++ b/Telegram/SourceFiles/passcodewidget.cpp @@ -112,6 +112,8 @@ void PasscodeWidget::onChanged() { } void PasscodeWidget::animShow(const QPixmap &bgAnimCache, bool back) { + MTP::pause(); + _bgAnimCache = bgAnimCache; anim::stop(this); @@ -143,6 +145,8 @@ bool PasscodeWidget::animStep(float64 ms) { showAll(); if (App::wnd()) App::wnd()->setInnerFocus(); + + if (App::app()) App::app()->mtpUnpause(); } else { a_bgCoord.update(dt1, st::introHideFunc); a_bgAlpha.update(dt1, st::introAlphaHideFunc); diff --git a/Telegram/SourceFiles/profilewidget.cpp b/Telegram/SourceFiles/profilewidget.cpp index 16107c508..201df5e07 100644 --- a/Telegram/SourceFiles/profilewidget.cpp +++ b/Telegram/SourceFiles/profilewidget.cpp @@ -1616,6 +1616,8 @@ int32 ProfileWidget::lastScrollTop() const { } void ProfileWidget::animShow(const QPixmap &bgAnimCache, const QPixmap &bgAnimTopBarCache, bool back, int32 lastScrollTop) { + MTP::pause(); + stopGif(); _bgAnimCache = bgAnimCache; _bgAnimTopBarCache = bgAnimTopBarCache; @@ -1651,6 +1653,8 @@ bool ProfileWidget::animStep(float64 ms) { _scroll.show(); _inner.start(); activate(); + + if (App::app()) App::app()->mtpUnpause(); } else { a_bgCoord.update(dt1, st::introHideFunc); a_bgAlpha.update(dt1, st::introAlphaHideFunc); diff --git a/Telegram/SourceFiles/settingswidget.cpp b/Telegram/SourceFiles/settingswidget.cpp index bf93f1150..6cb2b3fa4 100644 --- a/Telegram/SourceFiles/settingswidget.cpp +++ b/Telegram/SourceFiles/settingswidget.cpp @@ -1768,6 +1768,8 @@ void SettingsWidget::onParentResize(const QSize &newSize) { } void SettingsWidget::animShow(const QPixmap &bgAnimCache, bool back) { + MTP::pause(); + _bgAnimCache = bgAnimCache; anim::stop(this); @@ -1799,6 +1801,8 @@ bool SettingsWidget::animStep(float64 ms) { showAll(); _inner.setFocus(); + + if (App::app()) App::app()->mtpUnpause(); } else { a_bgCoord.update(dt1, st::introHideFunc); a_bgAlpha.update(dt1, st::introAlphaHideFunc);