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