diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 5aaacade7..716421792 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -276,8 +276,6 @@ PRIVATE boxes/edit_caption_box.h boxes/edit_privacy_box.cpp boxes/edit_privacy_box.h - boxes/gift_credits_box.cpp - boxes/gift_credits_box.h boxes/gift_premium_box.cpp boxes/gift_premium_box.h boxes/language_box.cpp @@ -322,6 +320,8 @@ PRIVATE boxes/sessions_box.h boxes/share_box.cpp boxes/share_box.h + boxes/star_gift_box.cpp + boxes/star_gift_box.h boxes/sticker_set_box.cpp boxes/sticker_set_box.h boxes/stickers_box.cpp diff --git a/Telegram/SourceFiles/boxes/gift_premium_box.cpp b/Telegram/SourceFiles/boxes/gift_premium_box.cpp index da4e9371d..fd640e496 100644 --- a/Telegram/SourceFiles/boxes/gift_premium_box.cpp +++ b/Telegram/SourceFiles/boxes/gift_premium_box.cpp @@ -64,11 +64,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace { -constexpr auto kUserpicsMax = size_t(3); - -using GiftOption = Data::PremiumSubscriptionOption; -using GiftOptions = Data::PremiumSubscriptionOptions; - [[nodiscard]] QString CreateMessageLink( not_null session, PeerId peerId, @@ -87,638 +82,6 @@ using GiftOptions = Data::PremiumSubscriptionOptions; return QString(); }; -GiftOptions GiftOptionFromTL(const MTPDuserFull &data) { - auto result = GiftOptions(); - const auto gifts = data.vpremium_gifts(); - if (!gifts) { - return result; - } - result = Api::PremiumSubscriptionOptionsFromTL(gifts->v); - for (auto &option : result) { - option.costPerMonth = tr::lng_premium_gift_per( - tr::now, - lt_cost, - option.costPerMonth); - } - return result; -} - -[[nodiscard]] Fn BoostsForGiftText( - const std::vector> users) { - Expects(!users.empty()); - - const auto session = &users.front()->session(); - const auto emoji = Ui::Text::SingleCustomEmoji( - session->data().customEmojiManager().registerInternalEmoji( - st::premiumGiftsBoostIcon, - QMargins(0, st::premiumGiftsUserpicBadgeInner, 0, 0), - false)); - - return [=, count = users.size()](TextWithEntities text) { - text.append('\n'); - text.append('\n'); - text.append(tr::lng_premium_gifts_about_reward( - tr::now, - lt_count, - count * BoostsForGift(session), - lt_emoji, - emoji, - Ui::Text::RichLangValue)); - return text; - }; -} - -using TagUser1 = lngtag_user; -using TagUser2 = lngtag_second_user; -using TagUser3 = lngtag_name; -[[nodiscard]] rpl::producer ComplexAboutLabel( - const std::vector> &users, - tr::phrase phrase1, - tr::phrase phrase2, - tr::phrase phrase3, - tr::phrase phraseMore) { - Expects(!users.empty()); - - const auto count = users.size(); - const auto nameValue = [&](not_null user) { - return user->session().changes().peerFlagsValue( - user, - Data::PeerUpdate::Flag::Name - ) | rpl::map([=] { return TextWithEntities{ user->firstName }; }); - }; - if (count == 1) { - return phrase1( - lt_user, - nameValue(users.front()), - Ui::Text::RichLangValue); - } else if (count == 2) { - return phrase2( - lt_user, - nameValue(users.front()), - lt_second_user, - nameValue(users[1]), - Ui::Text::RichLangValue); - } else if (count == 3) { - return phrase3( - lt_user, - nameValue(users.front()), - lt_second_user, - nameValue(users[1]), - lt_name, - nameValue(users[2]), - Ui::Text::RichLangValue); - } else { - return phraseMore( - lt_count, - rpl::single(count - kUserpicsMax) | tr::to_count(), - lt_user, - nameValue(users.front()), - lt_second_user, - nameValue(users[1]), - lt_name, - nameValue(users[2]), - Ui::Text::RichLangValue); - } -} - -[[nodiscard]] not_null CircleBadge( - not_null parent, - const QString &text) { - const auto widget = Ui::CreateChild(parent.get()); - - const auto full = Rect(st::premiumGiftsUserpicBadgeSize); - const auto inner = full - Margins(st::premiumGiftsUserpicBadgeInner); - auto gradient = QLinearGradient( - QPointF(0, full.height()), - QPointF(full.width(), 0)); - gradient.setStops(Ui::Premium::GiftGradientStops()); - - widget->paintRequest( - ) | rpl::start_with_next([=] { - auto p = QPainter(widget); - auto hq = PainterHighQualityEnabler(p); - p.setPen(Qt::NoPen); - p.setBrush(st::boxBg); - p.drawEllipse(full); - p.setPen(Qt::NoPen); - p.setBrush(gradient); - p.drawEllipse(inner); - p.setFont(st::premiumGiftsUserpicBadgeFont); - p.setPen(st::premiumButtonFg); - p.drawText(full, text, style::al_center); - }, widget->lifetime()); - widget->resize(full.size()); - return widget; -} - -[[nodiscard]] not_null UserpicsContainer( - not_null parent, - std::vector> users) { - Expects(!users.empty()); - - if (users.size() == 1) { - const auto userpic = Ui::CreateChild( - parent.get(), - users.front(), - st::defaultUserpicButton); - userpic->setAttribute(Qt::WA_TransparentForMouseEvents); - return userpic; - } - - const auto &singleSize = st::defaultUserpicButton.size; - - const auto container = Ui::CreateChild(parent.get()); - const auto single = singleSize.width(); - const auto shift = single - st::boostReplaceUserpicsShift; - const auto maxWidth = users.size() * (single - shift) + shift; - container->resize(maxWidth, singleSize.height()); - container->setAttribute(Qt::WA_TransparentForMouseEvents); - - const auto diff = (single - st::premiumGiftsUserpicButton.size.width()) - / 2; - for (auto i = 0; i < users.size(); i++) { - const auto bg = Ui::CreateChild(container); - bg->resize(singleSize); - bg->paintRequest( - ) | rpl::start_with_next([=] { - auto p = QPainter(bg); - auto hq = PainterHighQualityEnabler(p); - p.setPen(Qt::NoPen); - p.setBrush(st::boxBg); - p.drawEllipse(bg->rect()); - }, bg->lifetime()); - bg->moveToLeft(std::max(0, i * (single - shift)), 0); - - const auto userpic = Ui::CreateChild( - bg, - users[i], - st::premiumGiftsUserpicButton); - userpic->moveToLeft(diff, diff); - } - - return container; -} - -void GiftBox( - not_null box, - not_null controller, - not_null user, - GiftOptions options) { - const auto boxWidth = st::boxWideWidth; - box->setWidth(boxWidth); - box->setNoContentMargin(true); - const auto buttonsParent = box->verticalLayout().get(); - - struct State { - rpl::event_stream buttonText; - }; - const auto state = box->lifetime().make_state(); - - const auto userpicPadding = st::premiumGiftUserpicPadding; - const auto top = box->addRow(object_ptr( - buttonsParent, - userpicPadding.top() - + userpicPadding.bottom() - + st::defaultUserpicButton.size.height())); - - using ColoredMiniStars = Ui::Premium::ColoredMiniStars; - const auto stars = box->lifetime().make_state( - top, - true); - - const auto userpic = UserpicsContainer(top, { user }); - userpic->setAttribute(Qt::WA_TransparentForMouseEvents); - top->widthValue( - ) | rpl::start_with_next([=](int width) { - userpic->moveToLeft( - (width - userpic->width()) / 2, - userpicPadding.top()); - - const auto center = top->rect().center(); - const auto size = QSize( - userpic->width() * Ui::Premium::MiniStars::kSizeFactor, - userpic->height()); - const auto ministarsRect = QRect( - QPoint(center.x() - size.width(), center.y() - size.height()), - QPoint(center.x() + size.width(), center.y() + size.height())); - stars->setPosition(ministarsRect.topLeft()); - stars->setSize(ministarsRect.size()); - }, userpic->lifetime()); - - top->paintRequest( - ) | rpl::start_with_next([=](const QRect &r) { - auto p = QPainter(top); - - p.fillRect(r, Qt::transparent); - stars->paint(p); - }, top->lifetime()); - - const auto close = Ui::CreateChild( - buttonsParent, - st::infoTopBarClose); - close->setClickedCallback([=] { box->closeBox(); }); - - buttonsParent->widthValue( - ) | rpl::start_with_next([=](int width) { - close->moveToRight(0, 0, width); - }, close->lifetime()); - - // Header. - const auto &padding = st::premiumGiftAboutPadding; - const auto available = boxWidth - padding.left() - padding.right(); - const auto &stTitle = st::premiumPreviewAboutTitle; - auto titleLabel = object_ptr( - box, - tr::lng_premium_gift_title(), - stTitle); - titleLabel->resizeToWidth(available); - box->addRow( - object_ptr>( - box, - std::move(titleLabel)), - st::premiumGiftTitlePadding); - - auto textLabel = Ui::CreateLabelWithCustomEmoji( - box, - tr::lng_premium_gift_about( - lt_user, - user->session().changes().peerFlagsValue( - user, - Data::PeerUpdate::Flag::Name - ) | rpl::map([=] { return TextWithEntities{ user->firstName }; }), - Ui::Text::RichLangValue - ) | rpl::map( - BoostsForGiftText({ user }) - ), - { .session = &user->session() }, - st::premiumPreviewAbout); - textLabel->setTextColorOverride(stTitle.textFg->c); - textLabel->resizeToWidth(available); - box->addRow( - object_ptr>(box, std::move(textLabel)), - padding); - - // List. - const auto group = std::make_shared(); - const auto groupValueChangedCallback = [=](int value) { - Expects(value < options.size() && value >= 0); - auto text = tr::lng_premium_gift_button( - tr::now, - lt_cost, - options[value].costTotal); - state->buttonText.fire(std::move(text)); - }; - group->setChangedCallback(groupValueChangedCallback); - Ui::Premium::AddGiftOptions( - buttonsParent, - group, - options, - st::premiumGiftOption); - - // Footer. - auto terms = object_ptr( - box, - tr::lng_premium_gift_terms( - lt_link, - tr::lng_premium_gift_terms_link( - ) | rpl::map([=](const QString &t) { - return Ui::Text::Link(t, 1); - }), - Ui::Text::WithEntities), - st::premiumGiftTerms); - terms->setLink(1, std::make_shared([=] { - box->closeBox(); - Settings::ShowPremium(&user->session(), QString()); - })); - terms->resizeToWidth(available); - box->addRow( - object_ptr>(box, std::move(terms)), - st::premiumGiftTermsPadding); - - // Button. - const auto &stButton = st::premiumGiftBox; - box->setStyle(stButton); - auto raw = Settings::CreateSubscribeButton({ - controller, - box, - [] { return u"gift"_q; }, - state->buttonText.events(), - Ui::Premium::GiftGradientStops(), - [=] { - const auto value = group->current(); - return (value < options.size() && value >= 0) - ? options[value].botUrl - : QString(); - }, - }); - auto button = object_ptr::fromRaw(raw); - button->resizeToWidth(boxWidth - rect::m::sum::h(stButton.buttonPadding)); - box->setShowFinishedCallback([raw = button.data()] { - raw->startGlareAnimation(); - }); - box->addButton(std::move(button)); - - groupValueChangedCallback(0); - - Data::PeerPremiumValue( - user - ) | rpl::skip(1) | rpl::start_with_next([=] { - box->closeBox(); - }, box->lifetime()); -} - -void GiftsBox( - not_null box, - not_null controller, - std::vector> users, - not_null api, - const QString &ref) { - Expects(!users.empty()); - - const auto boxWidth = st::boxWideWidth; - box->setWidth(boxWidth); - box->setNoContentMargin(true); - const auto buttonsParent = box->verticalLayout().get(); - const auto session = &users.front()->session(); - - struct State { - rpl::event_stream buttonText; - rpl::variable confirmButtonBusy = false; - rpl::variable isPaymentComplete = false; - }; - const auto state = box->lifetime().make_state(); - - const auto userpicPadding = st::premiumGiftUserpicPadding; - const auto top = box->addRow(object_ptr( - buttonsParent, - userpicPadding.top() - + userpicPadding.bottom() - + st::defaultUserpicButton.size.height())); - - using ColoredMiniStars = Ui::Premium::ColoredMiniStars; - const auto stars = box->lifetime().make_state( - top, - true); - - const auto maxWithUserpic = std::min(users.size(), kUserpicsMax); - const auto userpics = UserpicsContainer( - top, - { users.begin(), users.begin() + maxWithUserpic }); - top->widthValue( - ) | rpl::start_with_next([=](int width) { - userpics->moveToLeft( - (width - userpics->width()) / 2, - userpicPadding.top()); - - const auto center = top->rect().center(); - const auto size = QSize( - userpics->width() * Ui::Premium::MiniStars::kSizeFactor, - userpics->height()); - const auto ministarsRect = QRect( - QPoint(center.x() - size.width(), center.y() - size.height()), - QPoint(center.x() + size.width(), center.y() + size.height())); - stars->setPosition(ministarsRect.topLeft()); - stars->setSize(ministarsRect.size()); - }, userpics->lifetime()); - if (const auto rest = users.size() - maxWithUserpic; rest > 0) { - const auto badge = CircleBadge( - userpics, - QChar('+') + QString::number(rest)); - badge->moveToRight(0, userpics->height() - badge->height()); - } - - top->paintRequest( - ) | rpl::start_with_next([=](const QRect &r) { - auto p = QPainter(top); - - p.fillRect(r, Qt::transparent); - stars->paint(p); - }, top->lifetime()); - - const auto close = Ui::CreateChild( - buttonsParent, - st::infoTopBarClose); - close->setClickedCallback([=] { box->closeBox(); }); - - buttonsParent->widthValue( - ) | rpl::start_with_next([=](int width) { - close->moveToRight(0, 0, width); - }, close->lifetime()); - - // Header. - const auto &padding = st::premiumGiftAboutPadding; - const auto available = boxWidth - padding.left() - padding.right(); - const auto &stTitle = st::premiumPreviewAboutTitle; - auto titleLabel = object_ptr( - box, - rpl::conditional( - state->isPaymentComplete.value(), - tr::lng_premium_gifts_about_paid_title(), - tr::lng_premium_gift_title()), - stTitle); - titleLabel->resizeToWidth(available); - box->addRow( - object_ptr>( - box, - std::move(titleLabel)), - st::premiumGiftTitlePadding); - - // About. - { - auto text = rpl::conditional( - state->isPaymentComplete.value(), - ComplexAboutLabel( - users, - tr::lng_premium_gifts_about_paid1, - tr::lng_premium_gifts_about_paid2, - tr::lng_premium_gifts_about_paid3, - tr::lng_premium_gifts_about_paid_more - ) | rpl::map([count = users.size()](TextWithEntities text) { - text.append('\n'); - text.append('\n'); - text.append(tr::lng_premium_gifts_about_paid_below( - tr::now, - lt_count, - float64(count), - Ui::Text::RichLangValue)); - return text; - }), - ComplexAboutLabel( - users, - tr::lng_premium_gifts_about_user1, - tr::lng_premium_gifts_about_user2, - tr::lng_premium_gifts_about_user3, - tr::lng_premium_gifts_about_user_more - ) | rpl::map(BoostsForGiftText(users)) - ); - const auto label = box->addRow( - object_ptr>( - box, - Ui::CreateLabelWithCustomEmoji( - box, - std::move(text), - { .session = session }, - st::premiumPreviewAbout)), - padding)->entity(); - label->setTextColorOverride(stTitle.textFg->c); - label->resizeToWidth(available); - } - - // List. - const auto optionsContainer = buttonsParent->add( - object_ptr>( - buttonsParent, - object_ptr(buttonsParent))); - const auto options = api->options(users.size()); - const auto group = std::make_shared(); - const auto groupValueChangedCallback = [=](int value) { - Expects(value < options.size() && value >= 0); - auto text = tr::lng_premium_gift_button( - tr::now, - lt_cost, - options[value].costTotal); - state->buttonText.fire(std::move(text)); - }; - group->setChangedCallback(groupValueChangedCallback); - Ui::Premium::AddGiftOptions( - optionsContainer->entity(), - group, - options, - st::premiumGiftOption); - optionsContainer->toggleOn( - state->isPaymentComplete.value() | rpl::map(!rpl::mappers::_1), - anim::type::instant); - - // Summary. - { - { - // Will be hidden after payment. - const auto content = optionsContainer->entity(); - Ui::AddSkip(content); - Ui::AddDivider(content); - Ui::AddSkip(content); - Ui::AddSubsectionTitle( - content, - tr::lng_premium_gifts_summary_subtitle()); - } - const auto content = box->addRow( - object_ptr(box), - {}); - auto buttonCallback = [=](PremiumFeature section) { - stars->setPaused(true); - const auto previewBoxShown = [=]( - not_null previewBox) { - previewBox->boxClosing( - ) | rpl::start_with_next(crl::guard(box, [=] { - stars->setPaused(false); - }), previewBox->lifetime()); - }; - - ShowPremiumPreviewBox( - controller->uiShow(), - section, - previewBoxShown, - true); - }; - Settings::AddSummaryPremium( - content, - controller, - ref, - std::move(buttonCallback)); - } - - // Footer. - { - box->addRow( - object_ptr( - box, - object_ptr( - box, - tr::lng_premium_gifts_terms( - lt_link, - tr::lng_payments_terms_link( - ) | rpl::map([](const QString &t) { - using namespace Ui::Text; - return Link(t, u"https://telegram.org/tos"_q); - }), - lt_policy, - tr::lng_premium_gifts_terms_policy( - ) | rpl::map([](const QString &t) { - using namespace Ui::Text; - return Link(t, u"https://telegram.org/privacy"_q); - }), - Ui::Text::RichLangValue), - st::premiumGiftTerms), - st::defaultBoxDividerLabelPadding), - {}); - } - - // Button. - const auto &stButton = st::premiumGiftBox; - box->setStyle(stButton); - auto raw = Settings::CreateSubscribeButton({ - controller, - box, - [=] { return ref; }, - rpl::combine( - state->buttonText.events(), - state->confirmButtonBusy.value(), - state->isPaymentComplete.value() - ) | rpl::map([](const QString &text, bool busy, bool paid) { - return busy - ? QString() - : paid - ? tr::lng_close(tr::now) - : text; - }), - Ui::Premium::GiftGradientStops(), - }); - raw->setClickedCallback([=] { - if (state->confirmButtonBusy.current()) { - return; - } - if (state->isPaymentComplete.current()) { - return box->closeBox(); - } - auto invoice = api->invoice( - users.size(), - api->monthsFromPreset(group->current())); - invoice.purpose = Payments::InvoicePremiumGiftCodeUsers{ users }; - - state->confirmButtonBusy = true; - const auto show = box->uiShow(); - const auto weak = Ui::MakeWeak(box.get()); - const auto done = [=](Payments::CheckoutResult result) { - if (const auto strong = weak.data()) { - strong->window()->setFocus(); - state->confirmButtonBusy = false; - if (result == Payments::CheckoutResult::Paid) { - state->isPaymentComplete = true; - Ui::StartFireworks(box->parentWidget()); - } - } - }; - - Payments::CheckoutProcess::Start(std::move(invoice), done); - }); - { - using namespace Info::Statistics; - const auto loadingAnimation = InfiniteRadialAnimationWidget( - raw, - raw->height() / 2); - AddChildToWidgetCenter(raw, loadingAnimation); - loadingAnimation->showOn(state->confirmButtonBusy.value()); - } - auto button = object_ptr::fromRaw(raw); - button->resizeToWidth(boxWidth - rect::m::sum::h(stButton.buttonPadding)); - box->setShowFinishedCallback([raw = button.data()] { - raw->startGlareAnimation(); - }); - box->addButton(std::move(button)); - - groupValueChangedCallback(0); -} - [[nodiscard]] Data::GiftCodeLink MakeGiftCodeLink( not_null session, const QString &slug) { @@ -996,180 +359,6 @@ void ShowAlreadyPremiumToast( } // namespace -GiftPremiumValidator::GiftPremiumValidator( - not_null controller) -: _controller(controller) -, _api(&_controller->session().mtp()) { -} - -void GiftPremiumValidator::cancel() { - _requestId = 0; -} - -void GiftPremiumValidator::showChoosePeerBox(const QString &ref) { - if (_manyGiftsLifetime) { - return; - } - using namespace Api; - const auto api = _manyGiftsLifetime.make_state( - _controller->session().user()); - const auto show = _controller->uiShow(); - api->request( - ) | rpl::start_with_error_done([=](const QString &error) { - show->showToast(error); - }, [=] { - const auto maxAmount = *ranges::max_element(api->availablePresets()); - - class Controller final : public ContactsBoxController { - public: - Controller( - not_null session, - Fn checkErrorCallback) - : ContactsBoxController(session) - , _checkErrorCallback(std::move(checkErrorCallback)) { - } - - protected: - std::unique_ptr createRow( - not_null user) override { - if (user->isSelf() - || user->isBot() - || user->isServiceUser() - || user->isInaccessible()) { - return nullptr; - } - return ContactsBoxController::createRow(user); - } - - void rowClicked(not_null row) override { - const auto checked = !row->checked(); - if (checked - && _checkErrorCallback - && _checkErrorCallback( - delegate()->peerListSelectedRowsCount())) { - return; - } - delegate()->peerListSetRowChecked(row, checked); - } - - private: - const Fn _checkErrorCallback; - - }; - auto initBox = [=](not_null peersBox) { - const auto ignoreClose = peersBox->lifetime().make_state(0); - - auto process = [=] { - const auto selected = peersBox->collectSelectedRows(); - const auto users = ranges::views::all( - selected - ) | ranges::views::transform([](not_null p) { - return p->asUser(); - }) | ranges::views::filter([](UserData *u) -> bool { - return u; - }) | ranges::to>>(); - if (users.empty()) { - show->showToast( - tr::lng_settings_gift_premium_choose(tr::now)); - return; - } - const auto giftBox = show->show( - Box(GiftsBox, _controller, users, api, ref)); - giftBox->boxClosing( - ) | rpl::start_with_next([=] { - _manyGiftsLifetime.destroy(); - }, giftBox->lifetime()); - (*ignoreClose) = true; - peersBox->closeBox(); - }; - - peersBox->setTitle(tr::lng_premium_gift_title()); - peersBox->addButton( - tr::lng_settings_gift_premium_users_confirm(), - std::move(process)); - peersBox->addButton(tr::lng_cancel(), [=] { - peersBox->closeBox(); - }); - peersBox->boxClosing( - ) | rpl::start_with_next([=] { - if (!(*ignoreClose)) { - _manyGiftsLifetime.destroy(); - } - }, peersBox->lifetime()); - }; - - auto listController = std::make_unique( - &_controller->session(), - [=](int count) { - if (count <= maxAmount) { - return false; - } - show->showToast(tr::lng_settings_gift_premium_users_error( - tr::now, - lt_count, - maxAmount)); - return true; - }); - show->showBox( - Box( - std::move(listController), - std::move(initBox)), - Ui::LayerOption::KeepOther); - - }, _manyGiftsLifetime); -} - -void GiftPremiumValidator::showChosenPeerBox( - not_null user, - const QString &ref) { - if (_manyGiftsLifetime) { - return; - } - using namespace Api; - const auto api = _manyGiftsLifetime.make_state( - _controller->session().user()); - const auto show = _controller->uiShow(); - api->request( - ) | rpl::start_with_error_done([=](const QString &error) { - show->showToast(error); - }, [=] { - const auto users = std::vector>{ user }; - const auto giftBox = show->show( - Box(GiftsBox, _controller, users, api, ref)); - giftBox->boxClosing( - ) | rpl::start_with_next([=] { - _manyGiftsLifetime.destroy(); - }, giftBox->lifetime()); - }, _manyGiftsLifetime); -} - -void GiftPremiumValidator::showBox(not_null user) { - if (_requestId) { - return; - } - _requestId = _api.request(MTPusers_GetFullUser( - user->inputUser - )).done([=](const MTPusers_UserFull &result) { - if (!_requestId) { - // Canceled. - return; - } - _requestId = 0; -// _controller->api().processFullPeer(peer, result); - _controller->session().data().processUsers(result.data().vusers()); - _controller->session().data().processChats(result.data().vchats()); - - const auto &fullUser = result.data().vfull_user().data(); - auto options = GiftOptionFromTL(fullUser); - if (!options.empty()) { - _controller->show( - Box(GiftBox, _controller, user, std::move(options))); - } - }).fail([=] { - _requestId = 0; - }).send(); -} - rpl::producer GiftDurationValue(int months) { return GiftDurationPhrase(months)( lt_count, diff --git a/Telegram/SourceFiles/boxes/gift_premium_box.h b/Telegram/SourceFiles/boxes/gift_premium_box.h index 5d81cc063..31ca5fcf2 100644 --- a/Telegram/SourceFiles/boxes/gift_premium_box.h +++ b/Telegram/SourceFiles/boxes/gift_premium_box.h @@ -9,8 +9,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mtproto/sender.h" -class UserData; - namespace Api { struct GiftCode; } // namespace Api @@ -29,29 +27,9 @@ class VerticalLayout; } // namespace Ui namespace Window { -class SessionController; class SessionNavigation; } // namespace Window -class GiftPremiumValidator final { -public: - GiftPremiumValidator(not_null controller); - - void showBox(not_null user); - void showChoosePeerBox(const QString &ref); - void showChosenPeerBox(not_null user, const QString &ref); - void cancel(); - -private: - const not_null _controller; - MTP::Sender _api; - - mtpRequestId _requestId = 0; - - rpl::lifetime _manyGiftsLifetime; - -}; - [[nodiscard]] rpl::producer GiftDurationValue(int months); [[nodiscard]] QString GiftDuration(int months); diff --git a/Telegram/SourceFiles/boxes/gift_credits_box.cpp b/Telegram/SourceFiles/boxes/star_gift_box.cpp similarity index 99% rename from Telegram/SourceFiles/boxes/gift_credits_box.cpp rename to Telegram/SourceFiles/boxes/star_gift_box.cpp index af05b604c..93f651cca 100644 --- a/Telegram/SourceFiles/boxes/gift_credits_box.cpp +++ b/Telegram/SourceFiles/boxes/star_gift_box.cpp @@ -5,7 +5,7 @@ the official desktop application for the Telegram messaging service. For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ -#include "boxes/gift_credits_box.h" +#include "boxes/star_gift_box.h" #include "base/event_filter.h" #include "base/random.h" @@ -1254,7 +1254,7 @@ void GiftBox( } // namespace -void ShowGiftCreditsBox( +void ChooseStarGiftRecipient( not_null controller, Fn gifted) { @@ -1292,15 +1292,21 @@ void ShowGiftCreditsBox( peersBox->addButton(tr::lng_cancel(), [=] { peersBox->closeBox(); }); }; - const auto show = controller->uiShow(); auto listController = std::make_unique( &controller->session(), [=](not_null peer) { - show->showBox(Box(GiftBox, controller, peer, gifted)); + ShowStarGiftBox(controller, peer, gifted); }); - show->showBox( + controller->show( Box(std::move(listController), std::move(initBox)), LayerOption::KeepOther); } +void ShowStarGiftBox( + not_null controller, + not_null peer, + Fn gifted) { + controller->show(Box(GiftBox, controller, peer, gifted)); +} + } // namespace Ui diff --git a/Telegram/SourceFiles/boxes/gift_credits_box.h b/Telegram/SourceFiles/boxes/star_gift_box.h similarity index 73% rename from Telegram/SourceFiles/boxes/gift_credits_box.h rename to Telegram/SourceFiles/boxes/star_gift_box.h index 43b8556f3..eadd64b93 100644 --- a/Telegram/SourceFiles/boxes/gift_credits_box.h +++ b/Telegram/SourceFiles/boxes/star_gift_box.h @@ -13,8 +13,13 @@ class SessionController; namespace Ui { -void ShowGiftCreditsBox( +void ChooseStarGiftRecipient( not_null controller, Fn gifted); +void ShowStarGiftBox( + not_null controller, + not_null peer, + Fn gifted); + } // namespace Ui diff --git a/Telegram/SourceFiles/core/local_url_handlers.cpp b/Telegram/SourceFiles/core/local_url_handlers.cpp index 566df8c94..1ef7cf083 100644 --- a/Telegram/SourceFiles/core/local_url_handlers.cpp +++ b/Telegram/SourceFiles/core/local_url_handlers.cpp @@ -27,10 +27,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "payments/payments_non_panel_process.h" #include "boxes/share_box.h" #include "boxes/connection_box.h" +#include "boxes/gift_premium_box.h" #include "boxes/edit_privacy_box.h" #include "boxes/premium_preview_box.h" #include "boxes/sticker_set_box.h" #include "boxes/sessions_box.h" +#include "boxes/star_gift_box.h" #include "boxes/language_box.h" #include "passport/passport_form_controller.h" #include "ui/text/text_utilities.h" @@ -1131,10 +1133,7 @@ bool ResolvePremiumMultigift( if (!controller) { return false; } - const auto params = url_parse_params( - match->captured(1).mid(1), - qthelp::UrlParamNameTransform::ToLower); - controller->showGiftPremiumsBox(params.value(u"ref"_q, u"gift_url"_q)); + Ui::ChooseStarGiftRecipient(controller, [] {}); controller->window().activate(); return true; } diff --git a/Telegram/SourceFiles/history/view/history_view_view_button.cpp b/Telegram/SourceFiles/history/view/history_view_view_button.cpp index aa12fe1c2..5f981bd18 100644 --- a/Telegram/SourceFiles/history/view/history_view_view_button.cpp +++ b/Telegram/SourceFiles/history/view/history_view_view_button.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "history/view/history_view_view_button.h" +#include "boxes/gift_premium_box.h" #include "core/click_handler_types.h" #include "history/history.h" #include "history/history_item_components.h" diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index 45c7280cb..091b2a7bf 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/peers/edit_contact_box.h" #include "boxes/report_messages_box.h" #include "boxes/share_box.h" +#include "boxes/star_gift_box.h" #include "boxes/translate_box.h" #include "core/application.h" #include "core/click_handler_types.h" @@ -705,7 +706,7 @@ base::options::toggle ShowPeerIdBelowAbout({ button->setClickedCallback([=] { if (!button->isDisabled()) { - controller->showGiftPremiumsBox(user, u"birthday"_q); + Ui::ShowStarGiftBox(controller, user, [] {}); } }); diff --git a/Telegram/SourceFiles/settings/settings_credits.cpp b/Telegram/SourceFiles/settings/settings_credits.cpp index 5051c70ba..a3d58c39a 100644 --- a/Telegram/SourceFiles/settings/settings_credits.cpp +++ b/Telegram/SourceFiles/settings/settings_credits.cpp @@ -8,7 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "settings/settings_credits.h" #include "api/api_credits.h" -#include "boxes/gift_credits_box.h" +#include "boxes/star_gift_box.h" #include "boxes/gift_premium_box.h" #include "core/click_handler_types.h" #include "data/components/credits.h" @@ -69,7 +69,6 @@ public: private: void setupContent(); - void setupOptions(not_null container); void setupHistory(not_null container); void setupSubscriptions(not_null container); @@ -361,7 +360,7 @@ void Credits::setupContent() { Ui::AddSkip(content); Ui::AddDivider(content); giftButton->setClickedCallback([=] { - Ui::ShowGiftCreditsBox(_controller, paid); + Ui::ChooseStarGiftRecipient(_controller, paid); }); } diff --git a/Telegram/SourceFiles/settings/settings_main.cpp b/Telegram/SourceFiles/settings/settings_main.cpp index c6c652fe7..f05fe7b97 100644 --- a/Telegram/SourceFiles/settings/settings_main.cpp +++ b/Telegram/SourceFiles/settings/settings_main.cpp @@ -26,7 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/language_box.h" #include "boxes/username_box.h" #include "boxes/about_box.h" -#include "boxes/gift_credits_box.h" +#include "boxes/star_gift_box.h" #include "ui/basic_click_handlers.h" #include "ui/boxes/confirm_box.h" #include "ui/controls/userpic_button.h" @@ -528,8 +528,7 @@ void SetupPremium( { .icon = &st::menuIconGiftPremium } ); button->addClickHandler([=] { - Ui::ShowGiftCreditsBox(controller, [=] { - }); + Ui::ChooseStarGiftRecipient(controller, [] {}); }); } Ui::AddSkip(container); diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index ad9c7f476..f334fb09b 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_report.h" #include "menu/menu_check_item.h" #include "boxes/share_box.h" +#include "boxes/star_gift_box.h" #include "chat_helpers/compose/compose_show.h" #include "chat_helpers/message_field.h" #include "chat_helpers/share_message_phrase_factory.h" @@ -1239,7 +1240,7 @@ void Filler::addGiftPremium() { const auto navigation = _controller; _addAction(tr::lng_profile_gift_premium(tr::now), [=] { - navigation->showGiftPremiumBox(user); + Ui::ChooseStarGiftRecipient(navigation, [] {}); }, &st::menuIconGiftPremium); } diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index 56dcfe72e..1442bb90f 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -1245,8 +1245,7 @@ SessionController::SessionController( , _activeChatsFilter(session->data().chatsFilters().defaultId()) , _openedFolder(window->id().folder()) , _defaultChatTheme(std::make_shared()) -, _chatStyle(std::make_unique(session->colorIndicesValue())) -, _giftPremiumValidator(this) { +, _chatStyle(std::make_unique(session->colorIndicesValue())) { init(); _chatStyleTheme = _defaultChatTheme; @@ -1470,24 +1469,6 @@ void SessionController::showEditPeerBox(PeerData *peer) { session().api().requestFullPeer(peer); } -void SessionController::showGiftPremiumBox(UserData *user) { - if (user) { - _giftPremiumValidator.showBox(user); - } else { - _giftPremiumValidator.cancel(); - } -} - -void SessionController::showGiftPremiumsBox(const QString &ref) { - _giftPremiumValidator.showChoosePeerBox(ref); -} - -void SessionController::showGiftPremiumsBox( - not_null user, - const QString &ref) { - _giftPremiumValidator.showChosenPeerBox(user, ref); -} - void SessionController::init() { if (session().supportMode()) { session().supportHelper().registerWindow(this); diff --git a/Telegram/SourceFiles/window/window_session_controller.h b/Telegram/SourceFiles/window/window_session_controller.h index 02f82198d..3da9eb291 100644 --- a/Telegram/SourceFiles/window/window_session_controller.h +++ b/Telegram/SourceFiles/window/window_session_controller.h @@ -8,11 +8,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "base/timer.h" -#include "boxes/gift_premium_box.h" // GiftPremiumValidator. #include "chat_helpers/compose/compose_show.h" #include "data/data_chat_participant_status.h" #include "data/data_report.h" #include "dialogs/dialogs_key.h" +#include "mtproto/sender.h" #include "settings/settings_type.h" #include "window/window_adaptive.h" @@ -407,11 +407,6 @@ public: Dialogs::RowDescriptor from = {}) const; void showEditPeerBox(PeerData *peer); - void showGiftPremiumBox(UserData *user); - void showGiftPremiumsBox(const QString &ref); - - // Single user gift as if was selected in multiple recipients chooser. - void showGiftPremiumsBox(not_null user, const QString &ref); void enableGifPauseReason(GifPauseReason reason); void disableGifPauseReason(GifPauseReason reason); @@ -735,8 +730,6 @@ private: base::has_weak_ptr _storyOpenGuard; - GiftPremiumValidator _giftPremiumValidator; - QString _premiumRef; rpl::lifetime _lifetime;