mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 15:43:55 +02:00
Slightly improved code style in PromoSuggestions.
This commit is contained in:
parent
197f6b05ae
commit
24a3a41cd6
2 changed files with 65 additions and 67 deletions
|
@ -56,7 +56,7 @@ void PromoSuggestions::refreshTopPromotion() {
|
|||
? _topPromotionNextRequestTime
|
||||
: now;
|
||||
if (_topPromotionRequestId) {
|
||||
getTopPromotionDelayed(now, next);
|
||||
topPromotionDelayed(now, next);
|
||||
return;
|
||||
}
|
||||
const auto key = [&]() -> std::pair<QString, uint32> {
|
||||
|
@ -70,40 +70,22 @@ void PromoSuggestions::refreshTopPromotion() {
|
|||
return { proxy.host, proxy.port };
|
||||
}();
|
||||
if (_topPromotionKey == key && now < next) {
|
||||
getTopPromotionDelayed(now, next);
|
||||
topPromotionDelayed(now, next);
|
||||
return;
|
||||
}
|
||||
_topPromotionKey = key;
|
||||
_topPromotionRequestId = _session->api().request(MTPhelp_GetPromoData(
|
||||
)).done([=](const MTPhelp_PromoData &result) {
|
||||
_topPromotionRequestId = 0;
|
||||
topPromotionDone(result);
|
||||
}).fail([=] {
|
||||
_topPromotionRequestId = 0;
|
||||
const auto now = base::unixtime::now();
|
||||
const auto next = _topPromotionNextRequestTime = now
|
||||
+ kTopPromotionInterval;
|
||||
if (!_topPromotionTimer.isActive()) {
|
||||
getTopPromotionDelayed(now, next);
|
||||
}
|
||||
}).send();
|
||||
}
|
||||
|
||||
void PromoSuggestions::getTopPromotionDelayed(TimeId now, TimeId next) {
|
||||
_topPromotionTimer.callOnce(std::min(
|
||||
std::max(next - now, kTopPromotionMinDelay),
|
||||
kTopPromotionInterval) * crl::time(1000));
|
||||
};
|
||||
|
||||
void PromoSuggestions::topPromotionDone(const MTPhelp_PromoData &proxy) {
|
||||
_topPromotionNextRequestTime = proxy.match([&](const auto &data) {
|
||||
_topPromotionNextRequestTime = result.match([&](const auto &data) {
|
||||
return data.vexpires().v;
|
||||
});
|
||||
getTopPromotionDelayed(
|
||||
topPromotionDelayed(
|
||||
base::unixtime::now(),
|
||||
_topPromotionNextRequestTime);
|
||||
|
||||
proxy.match([&](const MTPDhelp_promoDataEmpty &data) {
|
||||
result.match([&](const MTPDhelp_promoDataEmpty &data) {
|
||||
setTopPromoted(nullptr, QString(), QString());
|
||||
}, [&](const MTPDhelp_promoData &data) {
|
||||
_session->data().processChats(data.vchats());
|
||||
|
@ -140,7 +122,9 @@ void PromoSuggestions::topPromotionDone(const MTPhelp_PromoData &proxy) {
|
|||
auto changedCustom = false;
|
||||
auto custom = data.vcustom_pending_suggestion()
|
||||
? std::make_optional(
|
||||
CustomFromTL(_session, *data.vcustom_pending_suggestion()))
|
||||
CustomFromTL(
|
||||
_session,
|
||||
*data.vcustom_pending_suggestion()))
|
||||
: std::nullopt;
|
||||
if (_custom != custom) {
|
||||
_custom = std::move(custom);
|
||||
|
@ -153,8 +137,23 @@ void PromoSuggestions::topPromotionDone(const MTPhelp_PromoData &proxy) {
|
|||
_refreshed.fire({});
|
||||
}
|
||||
});
|
||||
}).fail([=] {
|
||||
_topPromotionRequestId = 0;
|
||||
const auto now = base::unixtime::now();
|
||||
const auto next = _topPromotionNextRequestTime = now
|
||||
+ kTopPromotionInterval;
|
||||
if (!_topPromotionTimer.isActive()) {
|
||||
topPromotionDelayed(now, next);
|
||||
}
|
||||
}).send();
|
||||
}
|
||||
|
||||
void PromoSuggestions::topPromotionDelayed(TimeId now, TimeId next) {
|
||||
_topPromotionTimer.callOnce(std::min(
|
||||
std::max(next - now, kTopPromotionMinDelay),
|
||||
kTopPromotionInterval) * crl::time(1000));
|
||||
};
|
||||
|
||||
rpl::producer<> PromoSuggestions::value() const {
|
||||
return _refreshed.events_starting_with({});
|
||||
}
|
||||
|
|
|
@ -51,8 +51,7 @@ private:
|
|||
const QString &type,
|
||||
const QString &message);
|
||||
|
||||
void getTopPromotionDelayed(TimeId now, TimeId next);
|
||||
void topPromotionDone(const MTPhelp_PromoData &proxy);
|
||||
void topPromotionDelayed(TimeId now, TimeId next);
|
||||
|
||||
const not_null<Main::Session*> _session;
|
||||
base::flat_set<QString> _dismissedSuggestions;
|
||||
|
|
Loading…
Add table
Reference in a new issue