diff --git a/Telegram/SourceFiles/boxes/star_gift_auction_box.cpp b/Telegram/SourceFiles/boxes/star_gift_auction_box.cpp index ba85e05772..f2318a8e4b 100644 --- a/Telegram/SourceFiles/boxes/star_gift_auction_box.cpp +++ b/Telegram/SourceFiles/boxes/star_gift_auction_box.cpp @@ -1020,7 +1020,7 @@ void AuctionInfoBox( }, close->lifetime()); } -void ChooseAndShowAuctionBox( +base::weak_qptr ChooseAndShowAuctionBox( std::shared_ptr show, not_null peer, std::shared_ptr> state, @@ -1062,38 +1062,59 @@ void ChooseAndShowAuctionBox( } else { boxClosed(); } + return box; } } // namespace rpl::lifetime ShowStarGiftAuction( not_null controller, - not_null peer, + PeerData *peer, QString slug, Fn finishRequesting, Fn boxClosed) { const auto weak = base::make_weak(controller); const auto session = &controller->session(); - const auto value = std::make_shared< - rpl::variable - >(); - return session->giftAuctions().state( + struct State { + rpl::variable value; + base::weak_qptr box; + }; + const auto state = std::make_shared(); + auto result = session->giftAuctions().state( slug - ) | rpl::start_with_next([=](Data::GiftAuctionState &&state) { + ) | rpl::start_with_next([=](Data::GiftAuctionState &&value) { if (const auto onstack = finishRequesting) { onstack(); } - const auto initial = !value->current().gift.has_value(); - (*value) = std::move(state); + const auto initial = !state->value.current().gift.has_value(); + const auto already = value.my.to; + state->value = std::move(value); if (initial) { if (const auto strong = weak.get()) { const auto show = strong->uiShow(); - ChooseAndShowAuctionBox(show, peer, value, boxClosed); + const auto to = peer + ? peer + : already + ? already + : show->session().user(); + state->box = ChooseAndShowAuctionBox( + show, + to, + std::shared_ptr>( + state, + &state->value), + boxClosed); } else { boxClosed(); } } }); + result.add([=] { + if (const auto strong = state->box.get()) { + strong->closeBox(); + } + }); + return result; } } // namespace Ui diff --git a/Telegram/SourceFiles/boxes/star_gift_auction_box.h b/Telegram/SourceFiles/boxes/star_gift_auction_box.h index ffa3147ab0..254c59a18b 100644 --- a/Telegram/SourceFiles/boxes/star_gift_auction_box.h +++ b/Telegram/SourceFiles/boxes/star_gift_auction_box.h @@ -15,7 +15,7 @@ namespace Ui { [[nodiscard]] rpl::lifetime ShowStarGiftAuction( not_null controller, - not_null peer, + PeerData *peer, QString slug, Fn finishRequesting, Fn boxClosed); diff --git a/Telegram/SourceFiles/core/local_url_handlers.cpp b/Telegram/SourceFiles/core/local_url_handlers.cpp index 49350e6893..939bf86837 100644 --- a/Telegram/SourceFiles/core/local_url_handlers.cpp +++ b/Telegram/SourceFiles/core/local_url_handlers.cpp @@ -1633,6 +1633,21 @@ bool ResolveUniqueGift( return true; } +bool ResolveGiftAuction( + Window::SessionController *controller, + const Match &match, + const QVariant &context) { + if (!controller) { + return false; + } + const auto slug = match->captured(1); + if (slug.isEmpty()) { + return false; + } + controller->showStarGiftAuction(slug); + return true; +} + bool ResolveConferenceCall( Window::SessionController *controller, const Match &match, @@ -1770,6 +1785,10 @@ const std::vector &LocalUrlHandlers() { u"^nft/?\\?slug=([a-zA-Z0-9\\.\\_\\-]+)(&|$)"_q, ResolveUniqueGift }, + { + u"^stargift_auction/?\\?slug=([a-zA-Z0-9\\.\\_\\-]+)(&|$)"_q, + ResolveGiftAuction + }, { u"^call/?\\?slug=([a-zA-Z0-9\\.\\_\\-]+)(&|$)"_q, ResolveConferenceCall @@ -1942,6 +1961,9 @@ QString TryConvertUrlToLocal(QString url) { } else if (const auto nftMatch = regex_match(u"^nft/([a-zA-Z0-9\\.\\_\\-]+)(\\?|$)"_q, query, matchOptions)) { const auto slug = nftMatch->captured(1); return u"tg://nft?slug="_q + slug; + } else if (const auto auctionMatch = regex_match(u"^auction/([a-zA-Z0-9\\.\\_\\-]+)(\\?|$)"_q, query, matchOptions)) { + const auto slug = auctionMatch->captured(1); + return u"tg://stargift_auction?slug="_q + slug; } else if (const auto callMatch = regex_match(u"^call/([a-zA-Z0-9\\.\\_\\-]+)(\\?|$)"_q, query, matchOptions)) { const auto slug = callMatch->captured(1); return u"tg://call?slug="_q + slug; diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index ecf53a0514..7c1bf7cf56 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -8,11 +8,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/window_session_controller.h" #include "api/api_text_entities.h" -#include "boxes/add_contact_box.h" #include "boxes/peers/add_bot_to_chat_box.h" #include "boxes/peers/edit_peer_info_box.h" #include "boxes/peers/replace_boost_box.h" +#include "boxes/add_contact_box.h" #include "boxes/delete_messages_box.h" +#include "boxes/star_gift_auction_box.h" #include "window/window_chat_preview.h" #include "window/window_chat_switch_process.h" #include "window/window_controller.h" @@ -3639,6 +3640,16 @@ void SessionController::dropSubsectionTabs() { base::take(_savedSubsectionTabs); } +void SessionController::showStarGiftAuction(const QString &slug) { + _starGiftAuctionLifetime.destroy(); + _starGiftAuctionLifetime = Ui::ShowStarGiftAuction( + this, + nullptr, + slug, + [] {}, + [=] { _starGiftAuctionLifetime.destroy(); }); +} + SessionController::~SessionController() { resetFakeUnreadWhileOpened(); dropSubsectionTabs(); diff --git a/Telegram/SourceFiles/window/window_session_controller.h b/Telegram/SourceFiles/window/window_session_controller.h index d0f74aa1ab..ab1ef01e5c 100644 --- a/Telegram/SourceFiles/window/window_session_controller.h +++ b/Telegram/SourceFiles/window/window_session_controller.h @@ -696,6 +696,8 @@ public: -> std::unique_ptr; void dropSubsectionTabs(); + void showStarGiftAuction(const QString &slug); + [[nodiscard]] rpl::lifetime &lifetime() { return _lifetime; } @@ -815,6 +817,8 @@ private: std::unique_ptr _savedSubsectionTabs; rpl::lifetime _savedSubsectionTabsLifetime; + rpl::lifetime _starGiftAuctionLifetime; + rpl::lifetime _lifetime; };