mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Preload gifts for the gift to user layer.
This commit is contained in:
parent
0f74456f30
commit
940455f786
2 changed files with 66 additions and 1 deletions
|
@ -108,6 +108,7 @@ constexpr auto kSentToastDuration = 3 * crl::time(1000);
|
||||||
constexpr auto kSwitchUpgradeCoverInterval = 3 * crl::time(1000);
|
constexpr auto kSwitchUpgradeCoverInterval = 3 * crl::time(1000);
|
||||||
constexpr auto kCrossfadeDuration = crl::time(400);
|
constexpr auto kCrossfadeDuration = crl::time(400);
|
||||||
constexpr auto kUpgradeDoneToastDuration = 4 * crl::time(1000);
|
constexpr auto kUpgradeDoneToastDuration = 4 * crl::time(1000);
|
||||||
|
constexpr auto kGiftsPreloadTimeout = 3 * crl::time(1000);
|
||||||
|
|
||||||
using namespace HistoryView;
|
using namespace HistoryView;
|
||||||
using namespace Info::PeerGifts;
|
using namespace Info::PeerGifts;
|
||||||
|
@ -2193,7 +2194,66 @@ void ChooseStarGiftRecipient(
|
||||||
void ShowStarGiftBox(
|
void ShowStarGiftBox(
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
not_null<PeerData*> peer) {
|
not_null<PeerData*> peer) {
|
||||||
controller->show(Box(GiftBox, controller, peer));
|
struct Session {
|
||||||
|
PeerData *peer = nullptr;
|
||||||
|
bool premiumGiftsReady = false;
|
||||||
|
bool starsGiftsReady = false;
|
||||||
|
rpl::lifetime lifetime;
|
||||||
|
};
|
||||||
|
static auto Map = base::flat_map<not_null<Main::Session*>, Session>();
|
||||||
|
|
||||||
|
const auto session = &controller->session();
|
||||||
|
auto i = Map.find(session);
|
||||||
|
if (i == end(Map)) {
|
||||||
|
i = Map.emplace(session).first;
|
||||||
|
session->lifetime().add([=] { Map.remove(session); });
|
||||||
|
} else if (i->second.peer == peer) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
i->second = Session{ .peer = peer };
|
||||||
|
|
||||||
|
const auto weak = base::make_weak(controller);
|
||||||
|
const auto show = [=] {
|
||||||
|
Map[session] = Session();
|
||||||
|
if (const auto strong = weak.get()) {
|
||||||
|
strong->show(Box(GiftBox, strong, peer));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
base::timer_once(
|
||||||
|
kGiftsPreloadTimeout
|
||||||
|
) | rpl::start_with_next(show, i->second.lifetime);
|
||||||
|
|
||||||
|
const auto user = peer->asUser();
|
||||||
|
if (user && !user->isSelf()) {
|
||||||
|
GiftsPremium(
|
||||||
|
session,
|
||||||
|
peer
|
||||||
|
) | rpl::start_with_next([=](PremiumGiftsDescriptor &&gifts) {
|
||||||
|
if (!gifts.list.empty()) {
|
||||||
|
auto &entry = Map[session];
|
||||||
|
entry.premiumGiftsReady = true;
|
||||||
|
if (entry.starsGiftsReady) {
|
||||||
|
show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, i->second.lifetime);
|
||||||
|
} else {
|
||||||
|
i->second.premiumGiftsReady = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
GiftsStars(
|
||||||
|
session,
|
||||||
|
peer
|
||||||
|
) | rpl::start_with_next([=](std::vector<GiftTypeStars> &&gifts) {
|
||||||
|
if (!gifts.empty()) {
|
||||||
|
auto &entry = Map[session];
|
||||||
|
entry.starsGiftsReady = true;
|
||||||
|
if (entry.premiumGiftsReady) {
|
||||||
|
show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, i->second.lifetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddUniqueGiftCover(
|
void AddUniqueGiftCover(
|
||||||
|
|
|
@ -199,6 +199,8 @@ void InnerWidget::subscribeToUpdates() {
|
||||||
} else if (update.action == Action::Save
|
} else if (update.action == Action::Save
|
||||||
|| update.action == Action::Unsave) {
|
|| update.action == Action::Unsave) {
|
||||||
i->gift.hidden = (update.action == Action::Unsave);
|
i->gift.hidden = (update.action == Action::Unsave);
|
||||||
|
|
||||||
|
const auto unpin = i->gift.hidden && i->gift.pinned;
|
||||||
v::match(i->descriptor, [](GiftTypePremium &) {
|
v::match(i->descriptor, [](GiftTypePremium &) {
|
||||||
}, [&](GiftTypeStars &data) {
|
}, [&](GiftTypeStars &data) {
|
||||||
data.hidden = i->gift.hidden;
|
data.hidden = i->gift.hidden;
|
||||||
|
@ -209,6 +211,9 @@ void InnerWidget::subscribeToUpdates() {
|
||||||
view.manageId = {};
|
view.manageId = {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (unpin) {
|
||||||
|
markUnpinned(i);
|
||||||
|
}
|
||||||
} else if (update.action == Action::Pin
|
} else if (update.action == Action::Pin
|
||||||
|| update.action == Action::Unpin) {
|
|| update.action == Action::Unpin) {
|
||||||
if (update.action == Action::Pin) {
|
if (update.action == Action::Pin) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue