info_bot_starref_common.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 "base/object_ptr.h"
  9. #include "data/data_user.h"
  10. namespace Ui {
  11. class AbstractButton;
  12. class RoundButton;
  13. class VerticalLayout;
  14. class BoxContent;
  15. class RpWidget;
  16. class Show;
  17. } // namespace Ui
  18. namespace style {
  19. struct RoundButton;
  20. } // namespace style
  21. namespace Main {
  22. class Session;
  23. } // namespace Main
  24. namespace Info::BotStarRef {
  25. struct ConnectedBotState {
  26. StarRefProgram program;
  27. QString link;
  28. TimeId date = 0;
  29. int users = 0;
  30. bool unresolved = false;
  31. bool revoked = false;
  32. };
  33. struct ConnectedBot {
  34. not_null<UserData*> bot;
  35. ConnectedBotState state;
  36. };
  37. using ConnectedBots = std::vector<ConnectedBot>;
  38. [[nodiscard]] QString FormatCommission(ushort commission);
  39. [[nodiscard]] QString FormatProgramDuration(int durationMonths);
  40. [[nodiscard]] rpl::producer<TextWithEntities> FormatForProgramDuration(
  41. int durationMonths);
  42. [[nodiscard]] not_null<Ui::AbstractButton*> AddViewListButton(
  43. not_null<Ui::VerticalLayout*> parent,
  44. rpl::producer<QString> title,
  45. rpl::producer<QString> subtitle,
  46. bool newBadge = false);
  47. [[nodiscard]] not_null<Ui::RoundButton*> AddFullWidthButton(
  48. not_null<Ui::BoxContent*> box,
  49. rpl::producer<QString> text,
  50. Fn<void()> callback = nullptr,
  51. const style::RoundButton *stOverride = nullptr);
  52. void AddFullWidthButtonFooter(
  53. not_null<Ui::BoxContent*> box,
  54. not_null<Ui::RpWidget*> button,
  55. rpl::producer<TextWithEntities> text);
  56. [[nodiscard]] object_ptr<Ui::BoxContent> StarRefLinkBox(
  57. ConnectedBot row,
  58. not_null<PeerData*> peer);
  59. [[nodiscard]] object_ptr<Ui::BoxContent> JoinStarRefBox(
  60. ConnectedBot row,
  61. not_null<PeerData*> initialRecipient,
  62. std::vector<not_null<PeerData*>> recipients,
  63. Fn<void(ConnectedBotState)> done = nullptr);
  64. [[nodiscard]] object_ptr<Ui::BoxContent> ConfirmEndBox(Fn<void()> finish);
  65. void ResolveRecipients(
  66. not_null<Main::Session*> session,
  67. Fn<void(std::vector<not_null<PeerData*>>)> done);
  68. std::unique_ptr<Ui::AbstractButton> MakePeerBubbleButton(
  69. not_null<QWidget*> parent,
  70. not_null<PeerData*> peer,
  71. Ui::RpWidget *right = nullptr,
  72. const style::color *bgOverride = nullptr);
  73. void ConfirmUpdate(
  74. std::shared_ptr<Ui::Show> show,
  75. not_null<UserData*> bot,
  76. const StarRefProgram &program,
  77. bool exists,
  78. Fn<void(Fn<void(bool)> done)> update);
  79. void UpdateProgram(
  80. std::shared_ptr<Ui::Show> show,
  81. not_null<UserData*> bot,
  82. const StarRefProgram &program,
  83. Fn<void(bool)> done);
  84. void FinishProgram(
  85. std::shared_ptr<Ui::Show> show,
  86. not_null<UserData*> bot,
  87. Fn<void(bool)> done);
  88. [[nodiscard]] ConnectedBots Parse(
  89. not_null<Main::Session*> session,
  90. const MTPpayments_ConnectedStarRefBots &bots);
  91. } // namespace Info::BotStarRef