call after sms is optional now

This commit is contained in:
John Preston 2016-03-15 22:38:30 +03:00
parent c6437ce893
commit bc172cf70c
6 changed files with 82 additions and 33 deletions

View File

@ -736,6 +736,7 @@ private:
PinnedBar *_pinnedBar; PinnedBar *_pinnedBar;
void updatePinnedBar(bool force = false); void updatePinnedBar(bool force = false);
bool pinnedMsgVisibilityUpdated(); bool pinnedMsgVisibilityUpdated();
void destroyPinnedBar();
void unpinDone(const MTPUpdates &updates); void unpinDone(const MTPUpdates &updates);
class ReplyEditMessageDataCallback : public SharedCallback2<void, ChannelData*, MsgId> { class ReplyEditMessageDataCallback : public SharedCallback2<void, ChannelData*, MsgId> {

View File

@ -82,7 +82,7 @@ IntroCode::IntroCode(IntroWidget *parent) : IntroStep(parent)
, _noTelegramCodeRequestId(0) , _noTelegramCodeRequestId(0)
, code(this, st::inpIntroCode, lang(lng_code_ph)) , code(this, st::inpIntroCode, lang(lng_code_ph))
, sentRequest(0) , sentRequest(0)
, waitTillCall(intro()->getCallTimeout()) { , callStatus(intro()->getCallStatus()) {
setGeometry(parent->innerRect()); setGeometry(parent->innerRect());
connect(&next, SIGNAL(clicked()), this, SLOT(onSubmitCode())); connect(&next, SIGNAL(clicked()), this, SLOT(onSubmitCode()));
@ -93,9 +93,10 @@ IntroCode::IntroCode(IntroWidget *parent) : IntroStep(parent)
updateDescText(); updateDescText();
waitTillCall = intro()->getCallTimeout();
if (!intro()->codeByTelegram()) { if (!intro()->codeByTelegram()) {
callTimer.start(1000); if (callStatus.type == IntroWidget::CallWaiting) {
callTimer.start(1000);
}
} }
} }
@ -106,8 +107,8 @@ void IntroCode::updateDescText() {
callTimer.stop(); callTimer.stop();
} else { } else {
_noTelegramCode.hide(); _noTelegramCode.hide();
waitTillCall = intro()->getCallTimeout(); callStatus = intro()->getCallStatus();
if (!callTimer.isActive()) { if (callStatus.type == IntroWidget::CallWaiting && !callTimer.isActive()) {
callTimer.start(1000); callTimer.start(1000);
} }
} }
@ -130,15 +131,27 @@ void IntroCode::paintEvent(QPaintEvent *e) {
} }
if (codeByTelegram) { if (codeByTelegram) {
} else { } else {
QString callText = lang(lng_code_calling); QString callText;
if (waitTillCall >= 3600) { switch (callStatus.type) {
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'))); case IntroWidget::CallWaiting: {
} else if (waitTillCall > 0) { if (callStatus.timeout >= 3600) {
callText = lng_code_call(lt_minutes, QString::number(waitTillCall / 60), lt_seconds, qsl("%1").arg(waitTillCall % 60, 2, 10, QChar('0'))); 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 if (waitTillCall < 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); 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()) { if (_a_error.animating() || error.length()) {
p.setOpacity(a_errorAlpha.current()); p.setOpacity(a_errorAlpha.current());
@ -291,16 +304,22 @@ void IntroCode::onInputChange() {
} }
void IntroCode::onSendCall() { void IntroCode::onSendCall() {
if (!--waitTillCall) { if (callStatus.type == IntroWidget::CallWaiting) {
callTimer.stop(); if (--callStatus.timeout <= 0) {
MTP::send(MTPauth_ResendCode(MTP_string(intro()->getPhone()), MTP_string(intro()->getPhoneHash())), rpcDone(&IntroCode::callDone)); 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(); update();
} }
void IntroCode::callDone(const MTPBool &v) { void IntroCode::callDone(const MTPauth_SentCode &v) {
if (!waitTillCall) { if (callStatus.type == IntroWidget::CallCalling) {
waitTillCall = -1; callStatus.type = IntroWidget::CallCalled;
intro()->setCallStatus(callStatus);
update(); 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)); _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); intro()->setCodeByTelegram(false);
updateDescText(); updateDescText();
} }

View File

@ -78,7 +78,7 @@ public slots:
private: private:
void showError(const QString &err); void showError(const QString &err);
void callDone(const MTPBool &v); void callDone(const MTPauth_SentCode &v);
void gotPassword(const MTPaccount_Password &result); void gotPassword(const MTPaccount_Password &result);
void stopCheck(); void stopCheck();
@ -94,14 +94,14 @@ private:
mtpRequestId _noTelegramCodeRequestId; mtpRequestId _noTelegramCodeRequestId;
QRect textRect; QRect textRect;
void noTelegramCodeDone(const MTPBool &result); void noTelegramCodeDone(const MTPauth_SentCode &result);
bool noTelegramCodeFail(const RPCError &result); bool noTelegramCodeFail(const RPCError &result);
CodeInput code; CodeInput code;
QString sentCode; QString sentCode;
mtpRequestId sentRequest; mtpRequestId sentRequest;
QTimer callTimer; QTimer callTimer;
int32 waitTillCall; IntroWidget::CallStatus callStatus;
QTimer checkRequest; QTimer checkRequest;
}; };

View File

@ -252,13 +252,15 @@ void IntroPhone::phoneSubmitDone(const MTPauth_SentCode &result) {
const MTPDauth_sentCode &d(result.c_auth_sentCode()); const MTPDauth_sentCode &d(result.c_auth_sentCode());
switch (d.vtype.type()) { switch (d.vtype.type()) {
case mtpc_auth_sentCodeTypeApp: intro()->setCodeByTelegram(true); 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_sentCodeTypeCall: intro()->setCodeByTelegram(false);
case mtpc_auth_sentCodeTypeFlashCall: LOG(("Error: should not be flashcall!")); break; 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()); 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) { if (d.has_next_type() && d.vnext_type.type() == mtpc_auth_codeTypeCall) {
intro()->setCallTimeout(d.vtimeout.v); intro()->setCallStatus({ IntroWidget::CallWaiting, d.has_timeout() ? d.vtimeout.v : 60 });
} else {
intro()->setCallStatus({ IntroWidget::CallDisabled, 0 });
} }
intro()->nextStep(new IntroCode(intro())); intro()->nextStep(new IntroCode(intro()));
} }

View File

@ -58,7 +58,7 @@ IntroWidget::IntroWidget(QWidget *parent) : TWidget(parent)
, _cacheHideIndex(0) , _cacheHideIndex(0)
, _cacheShowIndex(0) , _cacheShowIndex(0)
, _a_show(animation(this, &IntroWidget::step_show)) , _a_show(animation(this, &IntroWidget::step_show))
, _callTimeout(60) , _callStatus({ CallDisabled, 0 })
, _registered(false) , _registered(false)
, _hasRecovery(false) , _hasRecovery(false)
, _codeByTelegram(false) , _codeByTelegram(false)
@ -326,8 +326,8 @@ void IntroWidget::setCodeByTelegram(bool byTelegram) {
_codeByTelegram = byTelegram; _codeByTelegram = byTelegram;
} }
void IntroWidget::setCallTimeout(int32 callTimeout) { void IntroWidget::setCallStatus(const CallStatus &status) {
_callTimeout = callTimeout; _callStatus = status;
} }
const QString &IntroWidget::getPhone() const { const QString &IntroWidget::getPhone() const {
@ -342,8 +342,8 @@ const QString &IntroWidget::getCode() const {
return _code; return _code;
} }
int32 IntroWidget::getCallTimeout() const { const IntroWidget::CallStatus &IntroWidget::getCallStatus() const {
return _callTimeout; return _callStatus;
} }
const QByteArray &IntroWidget::getPwdSalt() const { const QByteArray &IntroWidget::getPwdSalt() const {

View File

@ -43,9 +43,19 @@ public:
QRect innerRect() const; QRect innerRect() const;
QString currentCountry() 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 setPhone(const QString &phone, const QString &phone_hash, bool registered);
void setCode(const QString &code); void setCode(const QString &code);
void setCallTimeout(int32 callTimeout); void setCallStatus(const CallStatus &status);
void setPwdSalt(const QByteArray &salt); void setPwdSalt(const QByteArray &salt);
void setHasRecovery(bool hasRecovery); void setHasRecovery(bool hasRecovery);
void setPwdHint(const QString &hint); void setPwdHint(const QString &hint);
@ -54,7 +64,7 @@ public:
const QString &getPhone() const; const QString &getPhone() const;
const QString &getPhoneHash() const; const QString &getPhoneHash() const;
const QString &getCode() const; const QString &getCode() const;
int32 getCallTimeout() const; const CallStatus &getCallStatus() const;
const QByteArray &getPwdSalt() const; const QByteArray &getPwdSalt() const;
bool getHasRecovery() const; bool getHasRecovery() const;
const QString &getPwdHint() const; const QString &getPwdHint() const;
@ -116,7 +126,7 @@ private:
void pushStep(IntroStep *step, MoveType type); void pushStep(IntroStep *step, MoveType type);
QString _phone, _phone_hash; QString _phone, _phone_hash;
int32 _callTimeout; CallStatus _callStatus;
bool _registered; bool _registered;
QString _code; QString _code;