add_contact_box.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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 "ui/layers/box_content.h"
  9. #include "base/timer.h"
  10. #include "mtproto/sender.h"
  11. class PeerListBox;
  12. struct RequestPeerQuery;
  13. namespace Window {
  14. class SessionNavigation;
  15. } // namespace Window
  16. namespace Main {
  17. class Session;
  18. } // namespace Main
  19. namespace Ui {
  20. class FlatLabel;
  21. class InputField;
  22. class PhoneInput;
  23. class UsernameInput;
  24. class Checkbox;
  25. template <typename Enum>
  26. class RadioenumGroup;
  27. template <typename Enum>
  28. class Radioenum;
  29. class LinkButton;
  30. class UserpicButton;
  31. class Show;
  32. } // namespace Ui
  33. enum class PeerFloodType {
  34. Send,
  35. InviteGroup,
  36. InviteChannel,
  37. };
  38. struct ForbiddenInvites;
  39. [[nodiscard]] TextWithEntities PeerFloodErrorText(
  40. not_null<Main::Session*> session,
  41. PeerFloodType type);
  42. void ShowAddParticipantsError(
  43. std::shared_ptr<Ui::Show> show,
  44. const QString &error,
  45. not_null<PeerData*> chat,
  46. const ForbiddenInvites &forbidden);
  47. void ShowAddParticipantsError(
  48. std::shared_ptr<Ui::Show> show,
  49. const QString &error,
  50. not_null<PeerData*> chat,
  51. not_null<UserData*> user);
  52. class AddContactBox : public Ui::BoxContent {
  53. public:
  54. AddContactBox(QWidget*, not_null<Main::Session*> session);
  55. AddContactBox(
  56. QWidget*,
  57. not_null<Main::Session*> session,
  58. QString fname,
  59. QString lname,
  60. QString phone);
  61. protected:
  62. void prepare() override;
  63. void paintEvent(QPaintEvent *e) override;
  64. void resizeEvent(QResizeEvent *e) override;
  65. void setInnerFocus() override;
  66. private:
  67. void submit();
  68. void retry();
  69. void save();
  70. void updateButtons();
  71. const not_null<Main::Session*> _session;
  72. object_ptr<Ui::InputField> _first;
  73. object_ptr<Ui::InputField> _last;
  74. object_ptr<Ui::PhoneInput> _phone;
  75. bool _retrying = false;
  76. bool _invertOrder = false;
  77. uint64 _contactId = 0;
  78. mtpRequestId _addRequest = 0;
  79. QString _sentName;
  80. };
  81. class GroupInfoBox : public Ui::BoxContent {
  82. public:
  83. enum class Type {
  84. Group,
  85. Channel,
  86. Megagroup,
  87. Forum,
  88. };
  89. GroupInfoBox(
  90. QWidget*,
  91. not_null<Window::SessionNavigation*> navigation,
  92. Type type,
  93. const QString &title = QString(),
  94. Fn<void(not_null<ChannelData*>)> channelDone = nullptr);
  95. GroupInfoBox(
  96. QWidget*,
  97. not_null<Window::SessionNavigation*> navigation,
  98. not_null<UserData*> bot,
  99. RequestPeerQuery query,
  100. Fn<void(not_null<PeerData*>)> done);
  101. protected:
  102. void prepare() override;
  103. void setInnerFocus() override;
  104. void resizeEvent(QResizeEvent *e) override;
  105. private:
  106. void createChannel(const QString &title, const QString &description);
  107. void createGroup(
  108. QPointer<Ui::BoxContent> selectUsersBox,
  109. const QString &title,
  110. const std::vector<not_null<PeerData*>> &users);
  111. void submitName();
  112. void submit();
  113. void checkInviteLink();
  114. void channelReady();
  115. void descriptionResized();
  116. void updateMaxHeight();
  117. [[nodiscard]] TimeId ttlPeriod() const;
  118. const not_null<Window::SessionNavigation*> _navigation;
  119. MTP::Sender _api;
  120. Type _type = Type::Group;
  121. QString _initialTitle;
  122. bool _mustBePublic = false;
  123. UserData *_canAddBot = nullptr;
  124. Fn<void(not_null<PeerData*>)> _done;
  125. object_ptr<Ui::UserpicButton> _photo = { nullptr };
  126. object_ptr<Ui::InputField> _title = { nullptr };
  127. object_ptr<Ui::InputField> _description = { nullptr };
  128. // group / channel creation
  129. mtpRequestId _creationRequestId = 0;
  130. bool _creatingInviteLink = false;
  131. ChannelData *_createdChannel = nullptr;
  132. TimeId _ttlPeriod = 0;
  133. bool _ttlPeriodOverridden = false;
  134. };
  135. class SetupChannelBox final : public Ui::BoxContent {
  136. public:
  137. SetupChannelBox(
  138. QWidget*,
  139. not_null<Window::SessionNavigation*> navigation,
  140. not_null<ChannelData*> channel,
  141. bool mustBePublic,
  142. Fn<void(not_null<PeerData*>)> done);
  143. void setInnerFocus() override;
  144. protected:
  145. void prepare() override;
  146. void keyPressEvent(QKeyEvent *e) override;
  147. void paintEvent(QPaintEvent *e) override;
  148. void resizeEvent(QResizeEvent *e) override;
  149. void mouseMoveEvent(QMouseEvent *e) override;
  150. void mousePressEvent(QMouseEvent *e) override;
  151. void leaveEventHook(QEvent *e) override;
  152. private:
  153. enum class Privacy {
  154. Public,
  155. Private,
  156. };
  157. enum class UsernameResult {
  158. Ok,
  159. Invalid,
  160. Occupied,
  161. ChatsTooMuch,
  162. NA,
  163. Unknown,
  164. };
  165. [[nodiscard]] UsernameResult parseError(const QString &error);
  166. void privacyChanged(Privacy value);
  167. void updateSelected(const QPoint &cursorGlobalPosition);
  168. void handleChange();
  169. void check();
  170. void save();
  171. void updateFail(UsernameResult result);
  172. void mustBePublicFailed();
  173. void checkFail(UsernameResult result);
  174. void firstCheckFail(UsernameResult result);
  175. void updateMaxHeight();
  176. void showRevokePublicLinkBoxForEdit();
  177. const not_null<Window::SessionNavigation*> _navigation;
  178. const not_null<ChannelData*> _channel;
  179. MTP::Sender _api;
  180. bool _creatingInviteLink = false;
  181. bool _mustBePublic = false;
  182. Fn<void(not_null<PeerData*>)> _done;
  183. std::shared_ptr<Ui::RadioenumGroup<Privacy>> _privacyGroup;
  184. object_ptr<Ui::Radioenum<Privacy>> _public;
  185. object_ptr<Ui::Radioenum<Privacy>> _private;
  186. int32 _aboutPublicWidth, _aboutPublicHeight;
  187. Ui::Text::String _aboutPublic, _aboutPrivate;
  188. object_ptr<Ui::UsernameInput> _link;
  189. QRect _invitationLink;
  190. bool _linkOver = false;
  191. bool _tooMuchUsernames = false;
  192. mtpRequestId _saveRequestId = 0;
  193. mtpRequestId _checkRequestId = 0;
  194. QString _sentUsername, _checkUsername, _errorText, _goodText;
  195. base::Timer _checkTimer;
  196. };
  197. class EditNameBox : public Ui::BoxContent {
  198. public:
  199. EditNameBox(QWidget*, not_null<UserData*> user);
  200. protected:
  201. void setInnerFocus() override;
  202. void prepare() override;
  203. void resizeEvent(QResizeEvent *e) override;
  204. private:
  205. void submit();
  206. void save();
  207. void saveSelfFail(const QString &error);
  208. const not_null<UserData*> _user;
  209. MTP::Sender _api;
  210. object_ptr<Ui::InputField> _first;
  211. object_ptr<Ui::InputField> _last;
  212. bool _invertOrder = false;
  213. mtpRequestId _requestId = 0;
  214. QString _sentName;
  215. };