2018-03-29 19:49:31 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "passport/passport_form_view_controller.h"
|
|
|
|
#include "passport/passport_form_controller.h"
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "ui/layers/layer_widget.h"
|
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
class BoxContent;
|
|
|
|
} // namespace Ui
|
2018-03-29 19:49:31 +00:00
|
|
|
|
|
|
|
namespace Passport {
|
|
|
|
|
|
|
|
class FormController;
|
2018-03-31 01:45:40 +00:00
|
|
|
class Panel;
|
2018-03-29 19:49:31 +00:00
|
|
|
|
2021-10-13 21:36:48 +00:00
|
|
|
struct EditDocumentCountry;
|
2018-04-12 15:45:04 +00:00
|
|
|
struct EditDocumentScheme;
|
|
|
|
struct EditContactScheme;
|
|
|
|
|
2018-04-20 17:34:51 +00:00
|
|
|
enum class ReadScanError;
|
|
|
|
|
2021-10-13 21:36:48 +00:00
|
|
|
using preferredLangCallback =
|
|
|
|
Fn<rpl::producer<EditDocumentCountry>(const QString &)>;
|
2018-04-12 15:45:04 +00:00
|
|
|
EditDocumentScheme GetDocumentScheme(
|
|
|
|
Scope::Type type,
|
2018-09-21 16:28:46 +00:00
|
|
|
std::optional<Value::Type> scansType,
|
2021-10-13 21:36:48 +00:00
|
|
|
bool nativeNames,
|
|
|
|
preferredLangCallback &&preferredLanguage);
|
2018-04-12 15:45:04 +00:00
|
|
|
EditContactScheme GetContactScheme(Scope::Type type);
|
|
|
|
|
2018-08-14 11:37:03 +00:00
|
|
|
const std::map<QString, QString> &LatinToNativeMap();
|
|
|
|
const std::map<QString, QString> &NativeToLatinMap();
|
2018-08-14 12:51:12 +00:00
|
|
|
QString AdjustKeyName(not_null<const Value*> value, const QString &key);
|
2018-08-14 05:43:40 +00:00
|
|
|
bool SkipFieldCheck(not_null<const Value*> value, const QString &key);
|
|
|
|
|
2018-03-29 19:49:31 +00:00
|
|
|
struct ScanInfo {
|
2018-08-17 14:59:07 +00:00
|
|
|
explicit ScanInfo(FileType type);
|
|
|
|
ScanInfo(
|
|
|
|
FileType type,
|
|
|
|
const FileKey &key,
|
|
|
|
const QString &status,
|
|
|
|
const QImage &thumb,
|
|
|
|
bool deleted,
|
|
|
|
const QString &error);
|
|
|
|
|
|
|
|
FileType type;
|
2018-03-29 19:49:31 +00:00
|
|
|
FileKey key;
|
|
|
|
QString status;
|
|
|
|
QImage thumb;
|
2018-03-31 01:45:40 +00:00
|
|
|
bool deleted = false;
|
2018-04-15 15:06:53 +00:00
|
|
|
QString error;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ScopeError {
|
2018-08-14 05:43:40 +00:00
|
|
|
enum class General {
|
|
|
|
WholeValue,
|
|
|
|
ScanMissing,
|
|
|
|
TranslationMissing,
|
|
|
|
};
|
|
|
|
|
|
|
|
// FileKey - file_hash error (bad scan / selfie / translation)
|
|
|
|
// General - general value error (or scan / translation missing)
|
2018-04-15 15:06:53 +00:00
|
|
|
// QString - data_hash with such key error (bad value)
|
2020-08-31 08:14:53 +00:00
|
|
|
std::variant<FileKey, General, QString> key;
|
2018-04-15 15:06:53 +00:00
|
|
|
QString text;
|
2018-03-29 19:49:31 +00:00
|
|
|
};
|
|
|
|
|
2018-03-31 01:45:40 +00:00
|
|
|
class PanelController : public ViewController {
|
2018-03-29 19:49:31 +00:00
|
|
|
public:
|
2018-03-31 01:45:40 +00:00
|
|
|
PanelController(not_null<FormController*> form);
|
2018-03-29 19:49:31 +00:00
|
|
|
|
|
|
|
not_null<UserData*> bot() const;
|
2018-04-03 18:24:31 +00:00
|
|
|
QString privacyPolicyUrl() const;
|
2018-04-12 15:45:04 +00:00
|
|
|
void submitForm();
|
2018-07-10 16:41:11 +00:00
|
|
|
void submitPassword(const QByteArray &password);
|
2018-04-18 08:42:15 +00:00
|
|
|
void recoverPassword();
|
2018-03-29 19:49:31 +00:00
|
|
|
rpl::producer<QString> passwordError() const;
|
|
|
|
QString passwordHint() const;
|
2018-04-16 17:02:40 +00:00
|
|
|
QString unconfirmedEmailPattern() const;
|
|
|
|
|
|
|
|
void setupPassword();
|
|
|
|
void cancelPasswordSubmit();
|
2018-11-07 09:39:31 +00:00
|
|
|
void validateRecoveryEmail();
|
2018-03-29 19:49:31 +00:00
|
|
|
|
2018-08-14 15:27:47 +00:00
|
|
|
bool canAddScan(FileType type) const;
|
|
|
|
void uploadScan(FileType type, QByteArray &&content);
|
2018-09-21 16:28:46 +00:00
|
|
|
void deleteScan(FileType type, std::optional<int> fileIndex);
|
|
|
|
void restoreScan(FileType type, std::optional<int> fileIndex);
|
2018-03-29 19:49:31 +00:00
|
|
|
rpl::producer<ScanInfo> scanUpdated() const;
|
2018-04-15 15:06:53 +00:00
|
|
|
rpl::producer<ScopeError> saveErrors() const;
|
2018-04-20 17:34:51 +00:00
|
|
|
void readScanError(ReadScanError error);
|
2018-03-29 19:49:31 +00:00
|
|
|
|
2018-09-21 16:28:46 +00:00
|
|
|
std::optional<rpl::producer<QString>> deleteValueLabel() const;
|
2018-04-13 16:43:17 +00:00
|
|
|
void deleteValue();
|
|
|
|
|
2018-03-29 19:49:31 +00:00
|
|
|
QString defaultEmail() const;
|
|
|
|
QString defaultPhoneNumber() const;
|
|
|
|
|
2018-03-31 01:45:40 +00:00
|
|
|
void showAskPassword() override;
|
|
|
|
void showNoPassword() override;
|
2018-04-15 15:06:53 +00:00
|
|
|
void showCriticalError(const QString &error) override;
|
2018-07-10 20:15:54 +00:00
|
|
|
void showUpdateAppBox() override;
|
2018-03-31 01:45:40 +00:00
|
|
|
|
2018-03-29 19:49:31 +00:00
|
|
|
void fillRows(
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(
|
2018-03-29 19:49:31 +00:00
|
|
|
QString title,
|
|
|
|
QString description,
|
2018-04-13 17:42:28 +00:00
|
|
|
bool ready,
|
|
|
|
bool error)> callback);
|
|
|
|
rpl::producer<> refillRows() const;
|
2018-03-29 19:49:31 +00:00
|
|
|
|
2018-04-03 18:24:31 +00:00
|
|
|
void editScope(int index) override;
|
|
|
|
void saveScope(ValueMap &&data, ValueMap &&filesData);
|
2018-04-09 17:56:07 +00:00
|
|
|
bool editScopeChanged(
|
|
|
|
const ValueMap &data,
|
|
|
|
const ValueMap &filesData) const;
|
|
|
|
void cancelEditScope();
|
2018-03-31 01:45:40 +00:00
|
|
|
|
2018-04-16 17:02:40 +00:00
|
|
|
void showBox(
|
2019-09-18 11:19:05 +00:00
|
|
|
object_ptr<Ui::BoxContent> box,
|
|
|
|
Ui::LayerOptions options,
|
2018-04-16 17:02:40 +00:00
|
|
|
anim::type animated) override;
|
2018-04-13 10:54:17 +00:00
|
|
|
void showToast(const QString &text) override;
|
2018-06-04 15:35:11 +00:00
|
|
|
void suggestReset(Fn<void()> callback) override;
|
2018-04-06 16:23:09 +00:00
|
|
|
|
2018-04-13 18:14:14 +00:00
|
|
|
int closeGetDuration() override;
|
|
|
|
|
2018-03-31 01:45:40 +00:00
|
|
|
void cancelAuth();
|
2018-06-02 14:29:21 +00:00
|
|
|
void cancelAuthSure();
|
2018-03-31 01:45:40 +00:00
|
|
|
|
|
|
|
rpl::lifetime &lifetime();
|
2018-03-29 19:49:31 +00:00
|
|
|
|
2018-04-13 05:11:53 +00:00
|
|
|
~PanelController();
|
|
|
|
|
2018-03-29 19:49:31 +00:00
|
|
|
private:
|
2018-03-31 01:45:40 +00:00
|
|
|
void ensurePanelCreated();
|
|
|
|
|
2018-09-21 16:28:46 +00:00
|
|
|
void editScope(int index, std::optional<int> documentIndex);
|
2018-04-12 15:45:04 +00:00
|
|
|
void editWithUpload(int index, int documentIndex);
|
2018-08-17 14:59:07 +00:00
|
|
|
bool editRequiresScanUpload(
|
|
|
|
int index,
|
2018-09-21 16:28:46 +00:00
|
|
|
std::optional<int> documentIndex) const;
|
|
|
|
void startScopeEdit(int index, std::optional<int> documentIndex);
|
|
|
|
std::optional<int> findBestDocumentIndex(const Scope &scope) const;
|
2018-04-10 07:51:19 +00:00
|
|
|
void requestScopeFilesType(int index);
|
2018-04-06 18:47:29 +00:00
|
|
|
void cancelValueEdit();
|
2018-04-09 17:56:07 +00:00
|
|
|
void processValueSaveFinished(not_null<const Value*> value);
|
2018-04-06 18:47:29 +00:00
|
|
|
void processVerificationNeeded(not_null<const Value*> value);
|
2018-03-29 19:49:31 +00:00
|
|
|
|
2018-04-13 16:43:17 +00:00
|
|
|
bool savingScope() const;
|
2018-07-10 19:32:34 +00:00
|
|
|
bool uploadingScopeScan() const;
|
2018-04-13 16:43:17 +00:00
|
|
|
bool hasValueDocument() const;
|
|
|
|
bool hasValueFields() const;
|
2018-08-14 11:37:03 +00:00
|
|
|
std::vector<ScopeError> collectSaveErrors(
|
2018-04-15 15:06:53 +00:00
|
|
|
not_null<const Value*> value) const;
|
2018-04-06 11:54:01 +00:00
|
|
|
QString getDefaultContactValue(Scope::Type type) const;
|
2018-04-13 16:43:17 +00:00
|
|
|
void deleteValueSure(bool withDetails);
|
2018-03-29 19:49:31 +00:00
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
void resetPassport(Fn<void()> callback);
|
2018-04-15 16:22:13 +00:00
|
|
|
void cancelReset();
|
|
|
|
|
2018-03-29 19:49:31 +00:00
|
|
|
not_null<FormController*> _form;
|
2018-04-03 18:24:31 +00:00
|
|
|
std::vector<Scope> _scopes;
|
2018-04-13 17:42:28 +00:00
|
|
|
rpl::event_stream<> _submitFailed;
|
2018-04-15 15:06:53 +00:00
|
|
|
std::vector<not_null<const Value*>> _submitErrors;
|
|
|
|
rpl::event_stream<ScopeError> _saveErrors;
|
2018-03-29 19:49:31 +00:00
|
|
|
|
2018-03-31 01:45:40 +00:00
|
|
|
std::unique_ptr<Panel> _panel;
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<bool()> _panelHasUnsavedChanges;
|
2019-09-18 11:19:05 +00:00
|
|
|
QPointer<Ui::BoxContent> _confirmForgetChangesBox;
|
|
|
|
std::vector<Ui::BoxPointer> _editScopeBoxes;
|
2018-04-03 18:24:31 +00:00
|
|
|
Scope *_editScope = nullptr;
|
2018-04-13 16:43:17 +00:00
|
|
|
const Value *_editValue = nullptr;
|
|
|
|
const Value *_editDocument = nullptr;
|
2019-09-18 11:19:05 +00:00
|
|
|
Ui::BoxPointer _scopeDocumentTypeBox;
|
|
|
|
std::map<not_null<const Value*>, Ui::BoxPointer> _verificationBoxes;
|
2018-03-31 01:45:40 +00:00
|
|
|
|
2019-09-18 11:19:05 +00:00
|
|
|
Ui::BoxPointer _resetBox;
|
2018-04-15 16:22:13 +00:00
|
|
|
|
2018-03-31 01:45:40 +00:00
|
|
|
rpl::lifetime _lifetime;
|
2018-03-29 19:49:31 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Passport
|