passport_panel_controller.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. #include "passport/passport_form_view_controller.h"
  9. #include "passport/passport_form_controller.h"
  10. #include "ui/layers/layer_widget.h"
  11. namespace Ui {
  12. class BoxContent;
  13. } // namespace Ui
  14. namespace Passport {
  15. class FormController;
  16. class Panel;
  17. struct EditDocumentCountry;
  18. struct EditDocumentScheme;
  19. struct EditContactScheme;
  20. enum class ReadScanError;
  21. using preferredLangCallback
  22. = Fn<rpl::producer<EditDocumentCountry>(const QString &)>;
  23. EditDocumentScheme GetDocumentScheme(
  24. Scope::Type type,
  25. std::optional<Value::Type> scansType,
  26. bool nativeNames,
  27. preferredLangCallback &&preferredLanguage);
  28. EditContactScheme GetContactScheme(Scope::Type type);
  29. const std::map<QString, QString> &LatinToNativeMap();
  30. const std::map<QString, QString> &NativeToLatinMap();
  31. QString AdjustKeyName(not_null<const Value*> value, const QString &key);
  32. bool SkipFieldCheck(not_null<const Value*> value, const QString &key);
  33. struct ScanInfo {
  34. explicit ScanInfo(FileType type);
  35. ScanInfo(
  36. FileType type,
  37. const FileKey &key,
  38. const QString &status,
  39. const QImage &thumb,
  40. bool deleted,
  41. const QString &error);
  42. FileType type;
  43. FileKey key;
  44. QString status;
  45. QImage thumb;
  46. bool deleted = false;
  47. QString error;
  48. };
  49. struct ScopeError {
  50. enum class General {
  51. WholeValue,
  52. ScanMissing,
  53. TranslationMissing,
  54. };
  55. // FileKey - file_hash error (bad scan / selfie / translation)
  56. // General - general value error (or scan / translation missing)
  57. // QString - data_hash with such key error (bad value)
  58. std::variant<FileKey, General, QString> key;
  59. QString text;
  60. };
  61. class PanelController : public ViewController {
  62. public:
  63. PanelController(not_null<FormController*> form);
  64. not_null<UserData*> bot() const;
  65. QString privacyPolicyUrl() const;
  66. void submitForm();
  67. void submitPassword(const QByteArray &password);
  68. void recoverPassword();
  69. rpl::producer<QString> passwordError() const;
  70. QString passwordHint() const;
  71. QString unconfirmedEmailPattern() const;
  72. void setupPassword();
  73. void cancelPasswordSubmit();
  74. void validateRecoveryEmail();
  75. bool canAddScan(FileType type) const;
  76. void uploadScan(FileType type, QByteArray &&content);
  77. void deleteScan(FileType type, std::optional<int> fileIndex);
  78. void restoreScan(FileType type, std::optional<int> fileIndex);
  79. rpl::producer<ScanInfo> scanUpdated() const;
  80. rpl::producer<ScopeError> saveErrors() const;
  81. void readScanError(ReadScanError error);
  82. std::optional<rpl::producer<QString>> deleteValueLabel() const;
  83. void deleteValue();
  84. QString defaultEmail() const;
  85. QString defaultPhoneNumber() const;
  86. void showAskPassword() override;
  87. void showNoPassword() override;
  88. void showCriticalError(const QString &error) override;
  89. void showUpdateAppBox() override;
  90. void fillRows(
  91. Fn<void(
  92. QString title,
  93. QString description,
  94. bool ready,
  95. bool error)> callback);
  96. rpl::producer<> refillRows() const;
  97. void editScope(int index) override;
  98. void saveScope(ValueMap &&data, ValueMap &&filesData);
  99. bool editScopeChanged(
  100. const ValueMap &data,
  101. const ValueMap &filesData) const;
  102. void cancelEditScope();
  103. void showBox(
  104. object_ptr<Ui::BoxContent> box,
  105. Ui::LayerOptions options,
  106. anim::type animated) override;
  107. void showToast(const QString &text) override;
  108. void suggestReset(Fn<void()> callback) override;
  109. int closeGetDuration() override;
  110. void cancelAuth();
  111. void cancelAuthSure();
  112. rpl::lifetime &lifetime();
  113. ~PanelController();
  114. private:
  115. void ensurePanelCreated();
  116. void editScope(int index, std::optional<int> documentIndex);
  117. void editWithUpload(int index, int documentIndex);
  118. bool editRequiresScanUpload(
  119. int index,
  120. std::optional<int> documentIndex) const;
  121. void startScopeEdit(int index, std::optional<int> documentIndex);
  122. std::optional<int> findBestDocumentIndex(const Scope &scope) const;
  123. void requestScopeFilesType(int index);
  124. void cancelValueEdit();
  125. void processValueSaveFinished(not_null<const Value*> value);
  126. void processVerificationNeeded(not_null<const Value*> value);
  127. bool savingScope() const;
  128. bool uploadingScopeScan() const;
  129. bool hasValueDocument() const;
  130. bool hasValueFields() const;
  131. std::vector<ScopeError> collectSaveErrors(
  132. not_null<const Value*> value) const;
  133. QString getDefaultContactValue(Scope::Type type) const;
  134. void deleteValueSure(bool withDetails);
  135. void resetPassport(Fn<void()> callback);
  136. void cancelReset();
  137. not_null<FormController*> _form;
  138. std::vector<Scope> _scopes;
  139. rpl::event_stream<> _submitFailed;
  140. std::vector<not_null<const Value*>> _submitErrors;
  141. rpl::event_stream<ScopeError> _saveErrors;
  142. std::unique_ptr<Panel> _panel;
  143. Fn<bool()> _panelHasUnsavedChanges;
  144. QPointer<Ui::BoxContent> _confirmForgetChangesBox;
  145. std::vector<Ui::BoxPointer> _editScopeBoxes;
  146. Scope *_editScope = nullptr;
  147. const Value *_editValue = nullptr;
  148. const Value *_editDocument = nullptr;
  149. Ui::BoxPointer _scopeDocumentTypeBox;
  150. std::map<not_null<const Value*>, Ui::BoxPointer> _verificationBoxes;
  151. Ui::BoxPointer _resetBox;
  152. rpl::lifetime _lifetime;
  153. };
  154. } // namespace Passport