Add td_api::updateSpeedLimitNotification.
This commit is contained in:
parent
8b440b6761
commit
33073a5022
@ -7151,6 +7151,11 @@ updateAnimationSearchParameters provider:string emojis:vector<string> = Update;
|
||||
//@description The list of suggested to the user actions has changed @added_actions Added suggested actions @removed_actions Removed suggested actions
|
||||
updateSuggestedActions added_actions:vector<SuggestedAction> removed_actions:vector<SuggestedAction> = Update;
|
||||
|
||||
//@description Download or upload file speed for the user was limited, but it can be restored by subscription to Telegram Premium.
|
||||
//-Use getOption("premium_download_speedup") or getOption("premium_upload_speedup") to get expected speedup after subscription to Telegram Premium
|
||||
//@is_upload True, if upload speed was limited; false, if download speed was limited
|
||||
updateSpeedLimitNotification is_upload:Bool = Update;
|
||||
|
||||
//@description The list of contacts that had birthdays recently or will have birthday soon has changed @close_birthday_users List of contact users with close birthday
|
||||
updateContactCloseBirthdays close_birthday_users:vector<closeBirthdayUser> = Update;
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "td/telegram/OptionManager.h"
|
||||
#include "td/telegram/StateManager.h"
|
||||
#include "td/telegram/TdDb.h"
|
||||
#include "td/telegram/UpdatesManager.h"
|
||||
|
||||
#include "td/utils/format.h"
|
||||
#include "td/utils/logging.h"
|
||||
@ -343,6 +344,10 @@ void Global::add_location_access_hash(double latitude, double longitude, int64 a
|
||||
location_access_hashes_[get_location_key(latitude, longitude)] = access_hash;
|
||||
}
|
||||
|
||||
void Global::notify_speed_limited(bool is_upload) {
|
||||
send_closure(updates_manager_, &UpdatesManager::notify_speed_limited, is_upload);
|
||||
}
|
||||
|
||||
double get_global_server_time() {
|
||||
return G()->server_time();
|
||||
}
|
||||
|
@ -626,6 +626,8 @@ class Global final : public ActorContext {
|
||||
store_all_files_in_files_directory_ = flag;
|
||||
}
|
||||
|
||||
void notify_speed_limited(bool is_upload);
|
||||
|
||||
private:
|
||||
std::shared_ptr<DhConfig> dh_config_;
|
||||
|
||||
|
@ -4054,6 +4054,7 @@ void Td::send_update(tl_object_ptr<td_api::Update> &&object) {
|
||||
VLOG(td_requests) << "Sending update: " << to_string(object);
|
||||
}
|
||||
break;
|
||||
case td_api::updateSpeedLimitNotification::ID:
|
||||
case td_api::updateDefaultReactionType::ID / 2:
|
||||
LOG(ERROR) << "Sending update: " << oneline(to_string(object));
|
||||
break;
|
||||
|
@ -1784,6 +1784,15 @@ void UpdatesManager::on_server_pong(tl_object_ptr<telegram_api::updates_state> &
|
||||
}
|
||||
}
|
||||
|
||||
void UpdatesManager::notify_speed_limited(bool is_upload) {
|
||||
if (Time::now() < next_notify_speed_limited_[is_upload]) {
|
||||
return;
|
||||
}
|
||||
next_notify_speed_limited_[is_upload] =
|
||||
Time::now() + td_->option_manager_->get_option_integer("upload_premium_speedup_notify_period");
|
||||
send_closure(G()->td(), &Td::send_update, td_api::make_object<td_api::updateSpeedLimitNotification>(is_upload));
|
||||
}
|
||||
|
||||
void UpdatesManager::process_get_difference_updates(
|
||||
vector<tl_object_ptr<telegram_api::Message>> &&new_messages,
|
||||
vector<tl_object_ptr<telegram_api::EncryptedMessage>> &&new_encrypted_messages,
|
||||
|
@ -131,6 +131,8 @@ class UpdatesManager final : public Actor {
|
||||
|
||||
void ping_server();
|
||||
|
||||
void notify_speed_limited(bool is_upload);
|
||||
|
||||
bool running_get_difference() const {
|
||||
return running_get_difference_;
|
||||
}
|
||||
@ -280,6 +282,8 @@ class UpdatesManager final : public Actor {
|
||||
};
|
||||
FlatHashMap<uint64, SessionInfo> session_infos_;
|
||||
|
||||
double next_notify_speed_limited_[2] = {0.0, 0.0};
|
||||
|
||||
void start_up() final;
|
||||
|
||||
void tear_down() final;
|
||||
|
@ -34,10 +34,26 @@ void NetQueryDelayer::delay(NetQueryPtr query) {
|
||||
}
|
||||
} else if (code == 420) {
|
||||
auto error_message = query->error().message();
|
||||
for (auto prefix :
|
||||
{Slice("FLOOD_WAIT_"), Slice("SLOWMODE_WAIT_"), Slice("2FA_CONFIRM_WAIT_"), Slice("TAKEOUT_INIT_DELAY_")}) {
|
||||
for (auto prefix : {Slice("FLOOD_WAIT_"), Slice("SLOWMODE_WAIT_"), Slice("2FA_CONFIRM_WAIT_"),
|
||||
Slice("TAKEOUT_INIT_DELAY_"), Slice("FLOOD_PREMIUM_WAIT_")}) {
|
||||
if (begins_with(error_message, prefix)) {
|
||||
timeout = clamp(to_integer<int>(error_message.substr(prefix.size())), 1, 14 * 24 * 60 * 60);
|
||||
if (prefix == "FLOOD_PREMIUM_WAIT_") {
|
||||
switch (query->type()) {
|
||||
case NetQuery::Type::Common:
|
||||
LOG(ERROR) << "Receive " << error_message << " for " << query;
|
||||
break;
|
||||
case NetQuery::Type::Upload:
|
||||
G()->notify_speed_limited(true);
|
||||
break;
|
||||
case NetQuery::Type::Download:
|
||||
case NetQuery::Type::DownloadSmall:
|
||||
G()->notify_speed_limited(false);
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -121,6 +121,8 @@ void NetQueryDispatcher::dispatch(NetQueryPtr net_query) {
|
||||
net_query->debug(PSTRING() << "sent to download small session multi proxy " << dest_dc_id);
|
||||
send_closure_later(dcs_[dc_pos].download_small_session_, &SessionMultiProxy::send, std::move(net_query));
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user