share_box.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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 "history/view/history_view_schedule_box.h"
  11. #include "ui/chat/forward_options_box.h"
  12. #include "ui/effects/animations.h"
  13. #include "ui/effects/round_checkbox.h"
  14. #include "mtproto/sender.h"
  15. class History;
  16. namespace style {
  17. struct MultiSelect;
  18. struct InputField;
  19. struct PeerList;
  20. } // namespace style
  21. namespace SendMenu {
  22. struct Details;
  23. } // namespace SendMenu
  24. namespace Window {
  25. class SessionController;
  26. } // namespace Window
  27. namespace Api {
  28. struct SendOptions;
  29. } // namespace Api
  30. namespace Main {
  31. class Session;
  32. class SessionShow;
  33. } // namespace Main
  34. namespace Dialogs {
  35. class Row;
  36. class IndexedList;
  37. } // namespace Dialogs
  38. namespace Data {
  39. enum class ForwardOptions;
  40. class Thread;
  41. } // namespace Data
  42. namespace Ui {
  43. class MultiSelect;
  44. class InputField;
  45. struct ScrollToRequest;
  46. template <typename Widget>
  47. class SlideWrap;
  48. class PopupMenu;
  49. } // namespace Ui
  50. class ShareBox;
  51. struct ShareBoxStyleOverrides {
  52. const style::MultiSelect *multiSelect = nullptr;
  53. const style::InputField *comment = nullptr;
  54. const style::PeerList *peerList = nullptr;
  55. const style::InputField *label = nullptr;
  56. const style::Checkbox *checkbox = nullptr;
  57. std::shared_ptr<HistoryView::ScheduleBoxStyleArgs> scheduleBox;
  58. };
  59. [[nodiscard]] ShareBoxStyleOverrides DarkShareBoxStyle();
  60. void FastShareMessage(
  61. std::shared_ptr<Main::SessionShow> show,
  62. not_null<HistoryItem*> item,
  63. ShareBoxStyleOverrides st = {});
  64. void FastShareMessage(
  65. not_null<Window::SessionController*> controller,
  66. not_null<HistoryItem*> item,
  67. ShareBoxStyleOverrides st = {});
  68. void FastShareLink(
  69. not_null<Window::SessionController*> controller,
  70. const QString &url,
  71. ShareBoxStyleOverrides st = {});
  72. void FastShareLink(
  73. std::shared_ptr<Main::SessionShow> show,
  74. const QString &url,
  75. ShareBoxStyleOverrides st = {});
  76. struct RecipientMoneyRestrictionError;
  77. [[nodiscard]] auto ShareMessageMoneyRestrictionError()
  78. -> Fn<RecipientMoneyRestrictionError(not_null<UserData*>)>;
  79. class ShareBox final : public Ui::BoxContent {
  80. public:
  81. using CopyCallback = Fn<void()>;
  82. using CountMessagesCallback = Fn<int(const TextWithTags&)>;
  83. using SubmitCallback = Fn<void(
  84. std::vector<not_null<Data::Thread*>>&&,
  85. Fn<bool()> checkPaid,
  86. TextWithTags&&,
  87. Api::SendOptions,
  88. Data::ForwardOptions)>;
  89. using FilterCallback = Fn<bool(not_null<Data::Thread*>)>;
  90. [[nodiscard]] static auto DefaultForwardCountMessages(
  91. not_null<History*> history,
  92. MessageIdsList msgIds) -> CountMessagesCallback;
  93. [[nodiscard]] static SubmitCallback DefaultForwardCallback(
  94. std::shared_ptr<Ui::Show> show,
  95. not_null<History*> history,
  96. MessageIdsList msgIds,
  97. std::optional<TimeId> videoTimestamp = {});
  98. struct Descriptor {
  99. not_null<Main::Session*> session;
  100. CopyCallback copyCallback;
  101. CountMessagesCallback countMessagesCallback;
  102. SubmitCallback submitCallback;
  103. FilterCallback filterCallback;
  104. object_ptr<Ui::RpWidget> bottomWidget = { nullptr };
  105. rpl::producer<QString> copyLinkText;
  106. rpl::producer<QString> titleOverride;
  107. ShareBoxStyleOverrides st;
  108. std::optional<TimeId> videoTimestamp;
  109. struct {
  110. int sendersCount = 0;
  111. int captionsCount = 0;
  112. bool show = false;
  113. } forwardOptions;
  114. using MoneyRestrictionError = RecipientMoneyRestrictionError;
  115. Fn<MoneyRestrictionError(
  116. not_null<UserData*>)> moneyRestrictionError;
  117. };
  118. ShareBox(QWidget*, Descriptor &&descriptor);
  119. protected:
  120. void prepare() override;
  121. void setInnerFocus() override;
  122. void resizeEvent(QResizeEvent *e) override;
  123. void keyPressEvent(QKeyEvent *e) override;
  124. private:
  125. void prepareCommentField();
  126. void scrollAnimationCallback();
  127. void submit(Api::SendOptions options);
  128. void copyLink() const;
  129. bool searchByUsername(bool useCache = false);
  130. [[nodiscard]] SendMenu::Details sendMenuDetails() const;
  131. void scrollTo(Ui::ScrollToRequest request);
  132. void needSearchByUsername();
  133. void applyFilterUpdate(const QString &query);
  134. void selectedChanged();
  135. void computeStarsCount();
  136. void createButtons();
  137. int getTopScrollSkip() const;
  138. int getBottomScrollSkip() const;
  139. int contentHeight() const;
  140. void updateScrollSkips();
  141. void addPeerToMultiSelect(not_null<Data::Thread*> thread);
  142. void innerSelectedChanged(not_null<Data::Thread*> thread, bool checked);
  143. void peopleDone(
  144. const MTPcontacts_Found &result,
  145. mtpRequestId requestId);
  146. void peopleFail(const MTP::Error &error, mtpRequestId requestId);
  147. void showMenu(not_null<Ui::RpWidget*> parent);
  148. Descriptor _descriptor;
  149. MTP::Sender _api;
  150. object_ptr<Ui::MultiSelect> _select;
  151. object_ptr<Ui::SlideWrap<Ui::InputField>> _comment;
  152. object_ptr<Ui::RpWidget> _bottomWidget;
  153. base::unique_qptr<Ui::PopupMenu> _menu;
  154. Ui::ForwardOptions _forwardOptions;
  155. class Inner;
  156. QPointer<Inner> _inner;
  157. bool _hasSelected = false;
  158. rpl::variable<QString> _copyLinkText;
  159. rpl::variable<int> _starsToSend;
  160. base::Timer _searchTimer;
  161. QString _peopleQuery;
  162. bool _peopleFull = false;
  163. mtpRequestId _peopleRequest = 0;
  164. RpWidget *_chatsFilters = nullptr;
  165. using PeopleCache = QMap<QString, MTPcontacts_Found>;
  166. PeopleCache _peopleCache;
  167. using PeopleQueries = QMap<mtpRequestId, QString>;
  168. PeopleQueries _peopleQueries;
  169. Ui::Animations::Simple _scrollAnimation;
  170. rpl::lifetime _submitLifetime;
  171. };