2016-07-28 17:01:08 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-07-28 17:01:08 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-07-28 17:01:08 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/abstract_box.h"
|
2018-04-09 17:56:07 +00:00
|
|
|
#include "base/timer.h"
|
2017-03-21 11:42:04 +00:00
|
|
|
#include "ui/widgets/input_fields.h"
|
2020-06-11 16:09:46 +00:00
|
|
|
#include "mtproto/sender.h"
|
2016-07-28 17:01:08 +00:00
|
|
|
|
2016-11-11 13:46:04 +00:00
|
|
|
namespace Ui {
|
2016-11-15 11:56:49 +00:00
|
|
|
class InputField;
|
2016-11-16 10:44:06 +00:00
|
|
|
class FlatLabel;
|
2016-11-11 13:46:04 +00:00
|
|
|
} // namespace Ui
|
|
|
|
|
2020-06-11 16:09:46 +00:00
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
|
|
|
|
2019-06-05 17:43:21 +00:00
|
|
|
void ShowPhoneBannedError(const QString &phone);
|
2019-08-06 16:40:08 +00:00
|
|
|
[[nodiscard]] QString ExtractPhonePrefix(const QString &phone);
|
2019-06-05 17:43:21 +00:00
|
|
|
|
2017-03-21 11:42:04 +00:00
|
|
|
class SentCodeField : public Ui::InputField {
|
|
|
|
public:
|
2018-11-19 12:15:59 +00:00
|
|
|
SentCodeField(
|
|
|
|
QWidget *parent,
|
|
|
|
const style::InputField &st,
|
2019-06-18 14:07:45 +00:00
|
|
|
rpl::producer<QString> placeholder = nullptr,
|
2018-11-19 12:15:59 +00:00
|
|
|
const QString &val = QString());
|
|
|
|
|
|
|
|
void setAutoSubmit(int length, Fn<void()> submitCallback);
|
|
|
|
void setChangedCallback(Fn<void()> changedCallback);
|
|
|
|
QString getDigitsOnly() const;
|
2017-03-21 11:42:04 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void fix();
|
|
|
|
|
|
|
|
// Flag for not calling onTextChanged() recursively.
|
|
|
|
bool _fixing = false;
|
|
|
|
|
|
|
|
int _autoSubmitLength = 0;
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void()> _submitCallback;
|
|
|
|
Fn<void()> _changedCallback;
|
2017-03-21 11:42:04 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class SentCodeCall {
|
|
|
|
public:
|
2018-04-09 17:56:07 +00:00
|
|
|
SentCodeCall(
|
2018-06-04 15:35:11 +00:00
|
|
|
FnMut<void()> callCallback,
|
|
|
|
Fn<void()> updateCallback);
|
2017-03-21 11:42:04 +00:00
|
|
|
|
|
|
|
enum class State {
|
|
|
|
Waiting,
|
|
|
|
Calling,
|
|
|
|
Called,
|
|
|
|
Disabled,
|
|
|
|
};
|
|
|
|
struct Status {
|
|
|
|
Status() {
|
|
|
|
}
|
|
|
|
Status(State state, int timeout) : state(state), timeout(timeout) {
|
|
|
|
}
|
|
|
|
|
|
|
|
State state = State::Disabled;
|
|
|
|
int timeout = 0;
|
|
|
|
};
|
|
|
|
void setStatus(const Status &status);
|
|
|
|
|
|
|
|
void callDone() {
|
|
|
|
if (_status.state == State::Calling) {
|
|
|
|
_status.state = State::Called;
|
|
|
|
if (_update) {
|
|
|
|
_update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString getText() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Status _status;
|
2018-04-09 17:56:07 +00:00
|
|
|
base::Timer _timer;
|
2018-06-04 15:35:11 +00:00
|
|
|
FnMut<void()> _call;
|
|
|
|
Fn<void()> _update;
|
2017-03-21 11:42:04 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2020-06-11 16:09:46 +00:00
|
|
|
class ConfirmPhoneBox final : public Ui::BoxContent {
|
2016-07-28 17:01:08 +00:00
|
|
|
public:
|
2020-06-11 16:09:46 +00:00
|
|
|
static void Start(
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
const QString &phone,
|
|
|
|
const QString &hash);
|
2016-07-28 17:01:08 +00:00
|
|
|
|
2020-06-11 16:09:46 +00:00
|
|
|
[[nodiscard]] Main::Session &session() const {
|
|
|
|
return *_session;
|
|
|
|
}
|
2016-07-28 17:01:08 +00:00
|
|
|
|
|
|
|
protected:
|
2016-12-13 17:07:56 +00:00
|
|
|
void prepare() override;
|
|
|
|
void setInnerFocus() override;
|
|
|
|
|
2016-07-28 17:01:08 +00:00
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
2020-06-11 16:09:46 +00:00
|
|
|
ConfirmPhoneBox(
|
|
|
|
QWidget*,
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
const QString &phone,
|
|
|
|
const QString &hash);
|
2016-12-13 17:07:56 +00:00
|
|
|
friend class object_ptr<ConfirmPhoneBox>;
|
|
|
|
|
2018-05-31 12:20:28 +00:00
|
|
|
void sendCode();
|
2017-03-21 11:42:04 +00:00
|
|
|
void sendCall();
|
2016-12-13 17:07:56 +00:00
|
|
|
void checkPhoneAndHash();
|
|
|
|
|
2016-07-28 17:01:08 +00:00
|
|
|
void sendCodeDone(const MTPauth_SentCode &result);
|
2020-06-11 16:09:46 +00:00
|
|
|
void sendCodeFail(const RPCError &error);
|
2016-07-28 17:01:08 +00:00
|
|
|
|
|
|
|
void callDone(const MTPauth_SentCode &result);
|
|
|
|
|
|
|
|
void confirmDone(const MTPBool &result);
|
2020-06-11 16:09:46 +00:00
|
|
|
void confirmFail(const RPCError &error);
|
2016-07-28 17:01:08 +00:00
|
|
|
|
|
|
|
QString getPhone() const {
|
|
|
|
return _phone;
|
|
|
|
}
|
|
|
|
void launch();
|
|
|
|
|
|
|
|
void showError(const QString &error);
|
|
|
|
|
2020-06-11 16:09:46 +00:00
|
|
|
const not_null<Main::Session*> _session;
|
|
|
|
MTP::Sender _api;
|
2016-07-28 17:01:08 +00:00
|
|
|
mtpRequestId _sendCodeRequestId = 0;
|
|
|
|
|
2016-07-29 10:05:00 +00:00
|
|
|
// _hash from the link for account.sendConfirmPhoneCode call.
|
|
|
|
// _phoneHash from auth.sentCode for account.confirmPhone call.
|
|
|
|
QString _phone, _hash;
|
|
|
|
QString _phoneHash;
|
2016-07-28 17:01:08 +00:00
|
|
|
|
|
|
|
// If we receive the code length, we autosubmit _code field when enough symbols is typed.
|
|
|
|
int _sentCodeLength = 0;
|
|
|
|
|
|
|
|
mtpRequestId _checkCodeRequestId = 0;
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<Ui::FlatLabel> _about = { nullptr };
|
2017-03-21 11:42:04 +00:00
|
|
|
object_ptr<SentCodeField> _code = { nullptr };
|
2016-07-28 17:01:08 +00:00
|
|
|
|
|
|
|
QString _error;
|
2017-03-21 11:42:04 +00:00
|
|
|
SentCodeCall _call;
|
2016-07-28 17:01:08 +00:00
|
|
|
|
|
|
|
};
|