gift_credits_box.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. #include "boxes/gift_credits_box.h"
  8. #include "api/api_credits.h"
  9. #include "boxes/peer_list_controllers.h"
  10. #include "core/ui_integration.h" // TextContext.
  11. #include "data/data_peer.h"
  12. #include "data/data_session.h"
  13. #include "data/data_user.h"
  14. #include "data/stickers/data_custom_emoji.h"
  15. #include "lang/lang_keys.h"
  16. #include "main/session/session_show.h"
  17. #include "settings/settings_credits_graphics.h"
  18. #include "ui/controls/userpic_button.h"
  19. #include "ui/effects/premium_graphics.h"
  20. #include "ui/effects/premium_stars_colored.h"
  21. #include "ui/layers/generic_box.h"
  22. #include "ui/rect.h"
  23. #include "ui/text/text_utilities.h"
  24. #include "ui/vertical_list.h"
  25. #include "ui/widgets/label_with_custom_emoji.h"
  26. #include "window/window_session_controller.h"
  27. #include "styles/style_boxes.h"
  28. #include "styles/style_channel_earn.h"
  29. #include "styles/style_chat.h"
  30. #include "styles/style_credits.h"
  31. #include "styles/style_giveaway.h"
  32. #include "styles/style_layers.h"
  33. #include "styles/style_premium.h"
  34. namespace Ui {
  35. void GiftCreditsBox(
  36. not_null<Ui::GenericBox*> box,
  37. not_null<PeerData*> peer,
  38. Fn<void()> gifted) {
  39. box->setWidth(st::boxWideWidth);
  40. box->setStyle(st::creditsGiftBox);
  41. box->setNoContentMargin(true);
  42. box->addButton(tr::lng_create_group_back(), [=] { box->closeBox(); });
  43. const auto content = box->setPinnedToTopContent(
  44. object_ptr<Ui::VerticalLayout>(box));
  45. Ui::AddSkip(content);
  46. Ui::AddSkip(content);
  47. Ui::AddSkip(content);
  48. const auto &stUser = st::premiumGiftsUserpicButton;
  49. const auto userpicWrap = content->add(
  50. object_ptr<Ui::CenterWrap<>>(
  51. content,
  52. object_ptr<Ui::UserpicButton>(content, peer, stUser)));
  53. userpicWrap->setAttribute(Qt::WA_TransparentForMouseEvents);
  54. Ui::AddSkip(content);
  55. Ui::AddSkip(content);
  56. Settings::AddMiniStars(
  57. content,
  58. Ui::CreateChild<Ui::RpWidget>(content),
  59. stUser.photoSize,
  60. box->width(),
  61. 2.);
  62. {
  63. Ui::AddSkip(content);
  64. auto link = tr::lng_credits_box_history_entry_gift_about_link(
  65. lt_emoji,
  66. rpl::single(Ui::Text::IconEmoji(&st::textMoreIconEmoji)),
  67. Ui::Text::RichLangValue
  68. ) | rpl::map([](TextWithEntities text) {
  69. return Ui::Text::Link(
  70. std::move(text),
  71. u"internal:stars_examples"_q);
  72. });
  73. content->add(
  74. object_ptr<Ui::CenterWrap<>>(
  75. content,
  76. Ui::CreateLabelWithCustomEmoji(
  77. content,
  78. tr::lng_credits_box_history_entry_gift_out_about(
  79. lt_user,
  80. rpl::single(TextWithEntities{ peer->shortName() }),
  81. lt_link,
  82. std::move(link),
  83. Ui::Text::RichLangValue),
  84. Core::TextContext({ .session = &peer->session() }),
  85. st::creditsBoxAbout)),
  86. st::boxRowPadding);
  87. }
  88. Ui::AddSkip(content);
  89. Ui::AddSkip(box->verticalLayout());
  90. Settings::FillCreditOptions(
  91. Main::MakeSessionShow(box->uiShow(), &peer->session()),
  92. box->verticalLayout(),
  93. peer,
  94. StarsAmount(),
  95. [=] { gifted(); box->uiShow()->hideLayer(); },
  96. tr::lng_credits_summary_options_subtitle(),
  97. {});
  98. box->setPinnedToBottomContent(
  99. object_ptr<Ui::VerticalLayout>(box));
  100. }
  101. void ShowGiftCreditsBox(
  102. not_null<Window::SessionController*> controller,
  103. Fn<void()> gifted) {
  104. class Controller final : public ContactsBoxController {
  105. public:
  106. Controller(
  107. not_null<Main::Session*> session,
  108. Fn<void(not_null<PeerData*>)> choose)
  109. : ContactsBoxController(session)
  110. , _choose(std::move(choose)) {
  111. }
  112. protected:
  113. std::unique_ptr<PeerListRow> createRow(
  114. not_null<UserData*> user) override {
  115. if (user->isSelf()
  116. || user->isBot()
  117. || user->isServiceUser()
  118. || user->isInaccessible()) {
  119. return nullptr;
  120. }
  121. return ContactsBoxController::createRow(user);
  122. }
  123. void rowClicked(not_null<PeerListRow*> row) override {
  124. _choose(row->peer());
  125. }
  126. private:
  127. const Fn<void(not_null<PeerData*>)> _choose;
  128. };
  129. auto initBox = [=](not_null<PeerListBox*> peersBox) {
  130. peersBox->setTitle(tr::lng_credits_gift_title());
  131. peersBox->addButton(tr::lng_cancel(), [=] { peersBox->closeBox(); });
  132. };
  133. const auto show = controller->uiShow();
  134. auto listController = std::make_unique<Controller>(
  135. &controller->session(),
  136. [=](not_null<PeerData*> peer) {
  137. show->showBox(Box(GiftCreditsBox, peer, gifted));
  138. });
  139. show->showBox(
  140. Box<PeerListBox>(std::move(listController), std::move(initBox)),
  141. Ui::LayerOption::KeepOther);
  142. }
  143. } // namespace Ui