Added timeout to earn requests for channels and bots.

This commit is contained in:
23rd 2025-05-06 21:30:02 +03:00
parent a8afc62db7
commit 53cee177e8
2 changed files with 16 additions and 0 deletions

View file

@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "api/api_credits.h"
#include "api/api_global_privacy.h"
#include "api/api_statistics.h"
#include "base/timer_rpl.h"
#include "data/components/credits.h"
#include "data/data_changes.h"
#include "data/data_channel_admins.h"
@ -1360,6 +1361,7 @@ void ApplyChannelUpdate(
}
if (channel->flags() & Flag::CanViewRevenue) {
static constexpr auto kTimeout = crl::time(60000);
const auto id = channel->id;
const auto weak = base::make_weak(&channel->session());
const auto creditsLoadLifetime = std::make_shared<rpl::lifetime>();
@ -1371,6 +1373,9 @@ void ApplyChannelUpdate(
creditsLoadLifetime->destroy();
}
});
base::timer_once(kTimeout) | rpl::start_with_next([=] {
creditsLoadLifetime->destroy();
}, *creditsLoadLifetime);
const auto currencyLoadLifetime = std::make_shared<rpl::lifetime>();
const auto currencyLoad
= currencyLoadLifetime->make_state<Api::EarnStatistics>(channel);
@ -1385,6 +1390,9 @@ void ApplyChannelUpdate(
currencyLoadLifetime->destroy();
}
}, *currencyLoadLifetime);
base::timer_once(kTimeout) | rpl::start_with_next([=] {
currencyLoadLifetime->destroy();
}, *currencyLoadLifetime);
}
// For clearUpTill() call.

View file

@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "api/api_global_privacy.h"
#include "api/api_sensitive_content.h"
#include "api/api_statistics.h"
#include "base/timer_rpl.h"
#include "storage/localstorage.h"
#include "storage/storage_account.h"
#include "storage/storage_user_photos.h"
@ -767,6 +768,7 @@ void ApplyUserUpdate(not_null<UserData*> user, const MTPDuserFull &update) {
Data::PeerUpdate::Flag::Rights);
}
if (info->canEditInformation) {
static constexpr auto kTimeout = crl::time(60000);
const auto id = user->id;
const auto weak = base::make_weak(&user->session());
const auto creditsLoadLifetime
@ -779,6 +781,9 @@ void ApplyUserUpdate(not_null<UserData*> user, const MTPDuserFull &update) {
creditsLoadLifetime->destroy();
}
});
base::timer_once(kTimeout) | rpl::start_with_next([=] {
creditsLoadLifetime->destroy();
}, *creditsLoadLifetime);
const auto currencyLoadLifetime
= std::make_shared<rpl::lifetime>();
const auto currencyLoad
@ -794,6 +799,9 @@ void ApplyUserUpdate(not_null<UserData*> user, const MTPDuserFull &update) {
currencyLoadLifetime->destroy();
}
}, *currencyLoadLifetime);
base::timer_once(kTimeout) | rpl::start_with_next([=] {
currencyLoadLifetime->destroy();
}, *currencyLoadLifetime);
}
}