diff --git a/Telegram/SourceFiles/boxes/star_gift_box.cpp b/Telegram/SourceFiles/boxes/star_gift_box.cpp index 5bca3be602..69996e9628 100644 --- a/Telegram/SourceFiles/boxes/star_gift_box.cpp +++ b/Telegram/SourceFiles/boxes/star_gift_box.cpp @@ -1273,59 +1273,6 @@ void SendGift( }); } -[[nodiscard]] std::shared_ptr FindUniqueGift( - not_null session, - const MTPUpdates &updates) { - auto result = std::shared_ptr(); - const auto checkAction = [&](const MTPDmessageService &message) { - const auto &action = message.vaction(); - action.match([&](const MTPDmessageActionStarGiftUnique &data) { - if (const auto gift = Api::FromTL(session, data.vgift())) { - const auto to = data.vpeer() - ? peerFromMTP(*data.vpeer()) - : PeerId(); - const auto service = data.vfrom_id() - && session->data().peer( - peerFromMTP(*data.vfrom_id()))->isServiceUser(); - const auto channel = (service && peerIsChannel(to)) - ? session->data().channel(peerToChannel(to)).get() - : nullptr; - const auto channelSavedId = channel - ? data.vsaved_id().value_or_empty() - : uint64(); - const auto realGiftMsgId = (peerIsUser(to) && data.vsaved_id()) - ? MsgId(data.vsaved_id().value_or_empty()) - : MsgId(message.vid().v); - - result = std::make_shared( - Data::GiftUpgradeResult{ - .info = *gift, - .manageId = (channel && channelSavedId) - ? Data::SavedStarGiftId::Chat( - channel, - channelSavedId) - : Data::SavedStarGiftId::User(realGiftMsgId), - .date = message.vdate().v, - .starsForDetailsRemove = int( - data.vdrop_original_details_stars( - ).value_or_empty()), - .saved = data.is_saved(), - }); - } - }, [](const auto &) {}); - }; - updates.match([&](const MTPDupdates &data) { - for (const auto &update : data.vupdates().v) { - update.match([&](const MTPDupdateNewMessage &data) { - data.vmessage().match([&](const MTPDmessageService &data) { - checkAction(data); - }, [](const auto &) {}); - }, [](const auto &) {}); - } - }, [](const auto &) {}); - return result; -} - void ShowGiftUpgradedToast( not_null window, not_null session, @@ -5070,4 +5017,57 @@ void SendGiftBox( } } +std::shared_ptr FindUniqueGift( + not_null session, + const MTPUpdates &updates) { + auto result = std::shared_ptr(); + const auto checkAction = [&](const MTPDmessageService &message) { + const auto &action = message.vaction(); + action.match([&](const MTPDmessageActionStarGiftUnique &data) { + if (const auto gift = Api::FromTL(session, data.vgift())) { + const auto to = data.vpeer() + ? peerFromMTP(*data.vpeer()) + : PeerId(); + const auto service = data.vfrom_id() + && session->data().peer( + peerFromMTP(*data.vfrom_id()))->isServiceUser(); + const auto channel = (service && peerIsChannel(to)) + ? session->data().channel(peerToChannel(to)).get() + : nullptr; + const auto channelSavedId = channel + ? data.vsaved_id().value_or_empty() + : uint64(); + const auto realGiftMsgId = (peerIsUser(to) && data.vsaved_id()) + ? MsgId(data.vsaved_id().value_or_empty()) + : MsgId(message.vid().v); + + result = std::make_shared( + Data::GiftUpgradeResult{ + .info = *gift, + .manageId = (channel && channelSavedId) + ? Data::SavedStarGiftId::Chat( + channel, + channelSavedId) + : Data::SavedStarGiftId::User(realGiftMsgId), + .date = message.vdate().v, + .starsForDetailsRemove = int( + data.vdrop_original_details_stars( + ).value_or_empty()), + .saved = data.is_saved(), + }); + } + }, [](const auto &) {}); + }; + updates.match([&](const MTPDupdates &data) { + for (const auto &update : data.vupdates().v) { + update.match([&](const MTPDupdateNewMessage &data) { + data.vmessage().match([&](const MTPDmessageService &data) { + checkAction(data); + }, [](const auto &) {}); + }, [](const auto &) {}); + } + }, [](const auto &) {}); + return result; +} + } // namespace Ui diff --git a/Telegram/SourceFiles/boxes/star_gift_box.h b/Telegram/SourceFiles/boxes/star_gift_box.h index 2e5ce95b2e..dccfaee088 100644 --- a/Telegram/SourceFiles/boxes/star_gift_box.h +++ b/Telegram/SourceFiles/boxes/star_gift_box.h @@ -176,4 +176,8 @@ void SendGiftBox( uint64 nextToUpgradeStickerId = 0, Fn nextToUpgradeShow = nullptr); +[[nodiscard]] std::shared_ptr FindUniqueGift( + not_null session, + const MTPUpdates &updates); + } // namespace Ui diff --git a/Telegram/SourceFiles/boxes/star_gift_craft_box.cpp b/Telegram/SourceFiles/boxes/star_gift_craft_box.cpp index 7d2da2bbbb..60d6dd2ef2 100644 --- a/Telegram/SourceFiles/boxes/star_gift_craft_box.cpp +++ b/Telegram/SourceFiles/boxes/star_gift_craft_box.cpp @@ -103,6 +103,10 @@ struct GiftForCraft { std::shared_ptr unique; Data::SavedStarGiftId manageId; + [[nodiscard]] QString slugId() const { + return unique ? unique->slug : QString(); + } + explicit operator bool() const { return unique != nullptr; } @@ -624,8 +628,8 @@ void ShowSelectGiftBox( &state->delegate), }); const auto button = state->entries.back().button; - const auto proj = &GiftForCraft::manageId; - if (ranges::contains(selected, gift.manageId, proj)) { + const auto proj = &GiftForCraft::slugId; + if (ranges::contains(selected, gift.info.unique->slug, proj)) { button->toggleSelected( true, GiftSelectionMode::Inset, @@ -676,7 +680,8 @@ void ShowSelectGiftBox( box->verticalLayout(), state->resale, rpl::single(false), - bought); + bought, + true); } box->addButton(tr::lng_box_ok(), [=] { @@ -921,11 +926,12 @@ void ShowSelectGiftBox( void Craft( not_null box, not_null controller, - std::shared_ptr show, std::shared_ptr state, const std::vector &gifts, Fn closeParent) { + auto show = controller->uiShow(); auto startRequest = [=](CraftResultCallback done) { +#if 0 constexpr auto kDelays = std::array{ 100, 200, 300, 400, 500, 1000, 2000 }; @@ -953,6 +959,24 @@ void Craft( done(nullptr); } }); +#endif + + auto inputs = QVector(); + for (const auto &gift : gifts) { + inputs.push_back( + Api::InputSavedStarGiftId(gift.manageId, gift.unique)); + } + const auto weak = base::make_weak(controller); + const auto session = &controller->session(); + session->api().request(MTPpayments_CraftStarGift( + MTP_vector(inputs) + )).done([=](const MTPUpdates &result) { + session->api().applyUpdates(result); + session->data().nextForUpgradeGiftInvalidate(session->user()); + done(FindUniqueGift(session, result)); + }).fail([=](const MTP::Error &error) { + show->showToast(error.type()); + }).send(); }; const auto requested = std::make_shared(); const auto giftId = gifts.front().unique->initialGiftId; @@ -1319,7 +1343,6 @@ void MakeCraftContent( Craft( box, controller, - controller->uiShow(), state->craftState, state->chosen.current(), closeParent); diff --git a/Telegram/SourceFiles/boxes/star_gift_resale_box.cpp b/Telegram/SourceFiles/boxes/star_gift_resale_box.cpp index ea7774ff09..114f6b76f9 100644 --- a/Telegram/SourceFiles/boxes/star_gift_resale_box.cpp +++ b/Telegram/SourceFiles/boxes/star_gift_resale_box.cpp @@ -543,7 +543,8 @@ void AddResaleGiftsList( not_null container, Data::ResaleGiftsDescriptor descriptor, rpl::producer forceTon, - Fn)> bought) { + Fn)> bought, + bool forCraft) { struct State { rpl::event_stream<> updated; ResaleGiftsDescriptor data; @@ -553,6 +554,7 @@ void AddResaleGiftsList( int lastMinHeight = 0; }; const auto state = container->lifetime().make_state(); + state->filter = ResaleGiftsFilter{ .forCraft = forCraft }; state->data = std::move(descriptor); state->ton = std::move(forceTon); @@ -668,7 +670,7 @@ void ShowResaleGiftBoughtToast( not_null to, const Data::UniqueGift &gift) { show->showToast({ - .title = tr::lng_gift_sent_title(tr::now), + .title = to->isSelf() ? QString() : tr::lng_gift_sent_title(tr::now), .text = TextWithEntities{ (to->isSelf() ? tr::lng_gift_sent_resale_done_self( tr::now, diff --git a/Telegram/SourceFiles/boxes/star_gift_resale_box.h b/Telegram/SourceFiles/boxes/star_gift_resale_box.h index 205983f0d3..ef45be3f8d 100644 --- a/Telegram/SourceFiles/boxes/star_gift_resale_box.h +++ b/Telegram/SourceFiles/boxes/star_gift_resale_box.h @@ -47,6 +47,7 @@ void AddResaleGiftsList( not_null container, Data::ResaleGiftsDescriptor descriptor, rpl::producer forceTon, - Fn)> bought = nullptr); + Fn)> bought = nullptr, + bool forCraft = false); } // namespace Ui