diff --git a/Telegram/SourceFiles/historywidget.h b/Telegram/SourceFiles/historywidget.h index 917eb73018..1ee9fc014b 100644 --- a/Telegram/SourceFiles/historywidget.h +++ b/Telegram/SourceFiles/historywidget.h @@ -736,6 +736,7 @@ private: PinnedBar *_pinnedBar; void updatePinnedBar(bool force = false); bool pinnedMsgVisibilityUpdated(); + void destroyPinnedBar(); void unpinDone(const MTPUpdates &updates); class ReplyEditMessageDataCallback : public SharedCallback2 { diff --git a/Telegram/SourceFiles/intro/introcode.cpp b/Telegram/SourceFiles/intro/introcode.cpp index 803c1d2649..71ed0bdf27 100644 --- a/Telegram/SourceFiles/intro/introcode.cpp +++ b/Telegram/SourceFiles/intro/introcode.cpp @@ -82,7 +82,7 @@ IntroCode::IntroCode(IntroWidget *parent) : IntroStep(parent) , _noTelegramCodeRequestId(0) , code(this, st::inpIntroCode, lang(lng_code_ph)) , sentRequest(0) -, waitTillCall(intro()->getCallTimeout()) { +, callStatus(intro()->getCallStatus()) { setGeometry(parent->innerRect()); connect(&next, SIGNAL(clicked()), this, SLOT(onSubmitCode())); @@ -93,9 +93,10 @@ IntroCode::IntroCode(IntroWidget *parent) : IntroStep(parent) updateDescText(); - waitTillCall = intro()->getCallTimeout(); if (!intro()->codeByTelegram()) { - callTimer.start(1000); + if (callStatus.type == IntroWidget::CallWaiting) { + callTimer.start(1000); + } } } @@ -106,8 +107,8 @@ void IntroCode::updateDescText() { callTimer.stop(); } else { _noTelegramCode.hide(); - waitTillCall = intro()->getCallTimeout(); - if (!callTimer.isActive()) { + callStatus = intro()->getCallStatus(); + if (callStatus.type == IntroWidget::CallWaiting && !callTimer.isActive()) { callTimer.start(1000); } } @@ -130,15 +131,27 @@ void IntroCode::paintEvent(QPaintEvent *e) { } if (codeByTelegram) { } else { - QString callText = lang(lng_code_calling); - if (waitTillCall >= 3600) { - callText = lng_code_call(lt_minutes, qsl("%1:%2").arg(waitTillCall / 3600).arg((waitTillCall / 60) % 60, 2, 10, QChar('0')), lt_seconds, qsl("%1").arg(waitTillCall % 60, 2, 10, QChar('0'))); - } else if (waitTillCall > 0) { - callText = lng_code_call(lt_minutes, QString::number(waitTillCall / 60), lt_seconds, qsl("%1").arg(waitTillCall % 60, 2, 10, QChar('0'))); - } else if (waitTillCall < 0) { + QString callText; + switch (callStatus.type) { + case IntroWidget::CallWaiting: { + if (callStatus.timeout >= 3600) { + callText = lng_code_call(lt_minutes, qsl("%1:%2").arg(callStatus.timeout / 3600).arg((callStatus.timeout / 60) % 60, 2, 10, QChar('0')), lt_seconds, qsl("%1").arg(callStatus.timeout % 60, 2, 10, QChar('0'))); + } else { + callText = lng_code_call(lt_minutes, QString::number(callStatus.timeout / 60), lt_seconds, qsl("%1").arg(callStatus.timeout % 60, 2, 10, QChar('0'))); + } + } break; + + case IntroWidget::CallCalling: { + callText = lang(lng_code_calling); + } break; + + case IntroWidget::CallCalled: { callText = lang(lng_code_called); + } break; + } + if (!callText.isEmpty()) { + p.drawText(QRect(textRect.left(), code.y() + code.height() + st::introCallSkip, st::introTextSize.width(), st::introErrHeight), callText, style::al_center); } - p.drawText(QRect(textRect.left(), code.y() + code.height() + st::introCallSkip, st::introTextSize.width(), st::introErrHeight), callText, style::al_center); } if (_a_error.animating() || error.length()) { p.setOpacity(a_errorAlpha.current()); @@ -291,16 +304,22 @@ void IntroCode::onInputChange() { } void IntroCode::onSendCall() { - if (!--waitTillCall) { - callTimer.stop(); - MTP::send(MTPauth_ResendCode(MTP_string(intro()->getPhone()), MTP_string(intro()->getPhoneHash())), rpcDone(&IntroCode::callDone)); + if (callStatus.type == IntroWidget::CallWaiting) { + if (--callStatus.timeout <= 0) { + callStatus.type = IntroWidget::CallCalling; + callTimer.stop(); + MTP::send(MTPauth_ResendCode(MTP_string(intro()->getPhone()), MTP_string(intro()->getPhoneHash())), rpcDone(&IntroCode::callDone)); + } else { + intro()->setCallStatus(callStatus); + } } update(); } -void IntroCode::callDone(const MTPBool &v) { - if (!waitTillCall) { - waitTillCall = -1; +void IntroCode::callDone(const MTPauth_SentCode &v) { + if (callStatus.type == IntroWidget::CallCalling) { + callStatus.type = IntroWidget::CallCalled; + intro()->setCallStatus(callStatus); update(); } } @@ -346,7 +365,24 @@ void IntroCode::onNoTelegramCode() { _noTelegramCodeRequestId = MTP::send(MTPauth_ResendCode(MTP_string(intro()->getPhone()), MTP_string(intro()->getPhoneHash())), rpcDone(&IntroCode::noTelegramCodeDone), rpcFail(&IntroCode::noTelegramCodeFail)); } -void IntroCode::noTelegramCodeDone(const MTPBool &result) { +void IntroCode::noTelegramCodeDone(const MTPauth_SentCode &result) { + if (result.type() != mtpc_auth_sentCode) { + showError(lang(lng_server_error)); + return; + } + + const MTPDauth_sentCode &d(result.c_auth_sentCode()); + switch (d.vtype.type()) { + case mtpc_auth_sentCodeTypeApp: intro()->setCodeByTelegram(true); + case mtpc_auth_sentCodeTypeSms: + case mtpc_auth_sentCodeTypeCall: intro()->setCodeByTelegram(false); + case mtpc_auth_sentCodeTypeFlashCall: LOG(("Error: should not be flashcall!")); break; + } + if (d.has_next_type() && d.vnext_type.type() == mtpc_auth_codeTypeCall) { + intro()->setCallStatus({ IntroWidget::CallWaiting, d.has_timeout() ? d.vtimeout.v : 60 }); + } else { + intro()->setCallStatus({ IntroWidget::CallDisabled, 0 }); + } intro()->setCodeByTelegram(false); updateDescText(); } diff --git a/Telegram/SourceFiles/intro/introcode.h b/Telegram/SourceFiles/intro/introcode.h index def8f28713..682f60105e 100644 --- a/Telegram/SourceFiles/intro/introcode.h +++ b/Telegram/SourceFiles/intro/introcode.h @@ -78,7 +78,7 @@ public slots: private: void showError(const QString &err); - void callDone(const MTPBool &v); + void callDone(const MTPauth_SentCode &v); void gotPassword(const MTPaccount_Password &result); void stopCheck(); @@ -94,14 +94,14 @@ private: mtpRequestId _noTelegramCodeRequestId; QRect textRect; - void noTelegramCodeDone(const MTPBool &result); + void noTelegramCodeDone(const MTPauth_SentCode &result); bool noTelegramCodeFail(const RPCError &result); CodeInput code; QString sentCode; mtpRequestId sentRequest; QTimer callTimer; - int32 waitTillCall; + IntroWidget::CallStatus callStatus; QTimer checkRequest; }; diff --git a/Telegram/SourceFiles/intro/introphone.cpp b/Telegram/SourceFiles/intro/introphone.cpp index 05cfc240c1..cf1e5f4d3e 100644 --- a/Telegram/SourceFiles/intro/introphone.cpp +++ b/Telegram/SourceFiles/intro/introphone.cpp @@ -252,13 +252,15 @@ void IntroPhone::phoneSubmitDone(const MTPauth_SentCode &result) { const MTPDauth_sentCode &d(result.c_auth_sentCode()); switch (d.vtype.type()) { case mtpc_auth_sentCodeTypeApp: intro()->setCodeByTelegram(true); - case mtpc_auth_sentCodeTypeSms: intro()->setCodeByTelegram(false); + case mtpc_auth_sentCodeTypeSms: case mtpc_auth_sentCodeTypeCall: intro()->setCodeByTelegram(false); case mtpc_auth_sentCodeTypeFlashCall: LOG(("Error: should not be flashcall!")); break; } intro()->setPhone(sentPhone, d.vphone_code_hash.c_string().v.c_str(), d.is_phone_registered()); - if (d.has_timeout() && d.has_next_type() && d.vnext_type.type() == mtpc_auth_codeTypeCall) { - intro()->setCallTimeout(d.vtimeout.v); + if (d.has_next_type() && d.vnext_type.type() == mtpc_auth_codeTypeCall) { + intro()->setCallStatus({ IntroWidget::CallWaiting, d.has_timeout() ? d.vtimeout.v : 60 }); + } else { + intro()->setCallStatus({ IntroWidget::CallDisabled, 0 }); } intro()->nextStep(new IntroCode(intro())); } diff --git a/Telegram/SourceFiles/intro/introwidget.cpp b/Telegram/SourceFiles/intro/introwidget.cpp index bb5a255550..8c7055b864 100644 --- a/Telegram/SourceFiles/intro/introwidget.cpp +++ b/Telegram/SourceFiles/intro/introwidget.cpp @@ -58,7 +58,7 @@ IntroWidget::IntroWidget(QWidget *parent) : TWidget(parent) , _cacheHideIndex(0) , _cacheShowIndex(0) , _a_show(animation(this, &IntroWidget::step_show)) -, _callTimeout(60) +, _callStatus({ CallDisabled, 0 }) , _registered(false) , _hasRecovery(false) , _codeByTelegram(false) @@ -326,8 +326,8 @@ void IntroWidget::setCodeByTelegram(bool byTelegram) { _codeByTelegram = byTelegram; } -void IntroWidget::setCallTimeout(int32 callTimeout) { - _callTimeout = callTimeout; +void IntroWidget::setCallStatus(const CallStatus &status) { + _callStatus = status; } const QString &IntroWidget::getPhone() const { @@ -342,8 +342,8 @@ const QString &IntroWidget::getCode() const { return _code; } -int32 IntroWidget::getCallTimeout() const { - return _callTimeout; +const IntroWidget::CallStatus &IntroWidget::getCallStatus() const { + return _callStatus; } const QByteArray &IntroWidget::getPwdSalt() const { diff --git a/Telegram/SourceFiles/intro/introwidget.h b/Telegram/SourceFiles/intro/introwidget.h index dc3868e154..66ac6f02c0 100644 --- a/Telegram/SourceFiles/intro/introwidget.h +++ b/Telegram/SourceFiles/intro/introwidget.h @@ -43,9 +43,19 @@ public: QRect innerRect() const; QString currentCountry() const; + enum CallStatusType { + CallWaiting, + CallCalling, + CallCalled, + CallDisabled, + }; + struct CallStatus { + CallStatusType type; + int timeout; + }; void setPhone(const QString &phone, const QString &phone_hash, bool registered); void setCode(const QString &code); - void setCallTimeout(int32 callTimeout); + void setCallStatus(const CallStatus &status); void setPwdSalt(const QByteArray &salt); void setHasRecovery(bool hasRecovery); void setPwdHint(const QString &hint); @@ -54,7 +64,7 @@ public: const QString &getPhone() const; const QString &getPhoneHash() const; const QString &getCode() const; - int32 getCallTimeout() const; + const CallStatus &getCallStatus() const; const QByteArray &getPwdSalt() const; bool getHasRecovery() const; const QString &getPwdHint() const; @@ -116,7 +126,7 @@ private: void pushStep(IntroStep *step, MoveType type); QString _phone, _phone_hash; - int32 _callTimeout; + CallStatus _callStatus; bool _registered; QString _code;