mirror of https://github.com/procxx/kepka.git
Improve config re-requesting.
This commit is contained in:
parent
4bf66cb6e9
commit
62c812858e
|
@ -467,7 +467,7 @@ upload.fileCdnRedirect#f18cda44 dc_id:int file_token:bytes encryption_key:bytes
|
||||||
|
|
||||||
dcOption#18b7a10d flags:# ipv6:flags.0?true media_only:flags.1?true tcpo_only:flags.2?true cdn:flags.3?true static:flags.4?true id:int ip_address:string port:int secret:flags.10?bytes = DcOption;
|
dcOption#18b7a10d flags:# ipv6:flags.0?true media_only:flags.1?true tcpo_only:flags.2?true cdn:flags.3?true static:flags.4?true id:int ip_address:string port:int secret:flags.10?bytes = DcOption;
|
||||||
|
|
||||||
config#86b5778e flags:# phonecalls_enabled:flags.1?true default_p2p_contacts:flags.3?true preload_featured_stickers:flags.4?true ignore_phone_entities:flags.5?true revoke_pm_inbox:flags.6?true date:int expires:int test_mode:Bool this_dc:int dc_options:Vector<DcOption> chat_size_max:int megagroup_size_max:int forwarded_count_max:int online_update_period_ms:int offline_blur_timeout_ms:int offline_idle_timeout_ms:int online_cloud_timeout_ms:int notify_cloud_delay_ms:int notify_default_delay_ms:int push_chat_period_ms:int push_chat_limit:int saved_gifs_limit:int edit_time_limit:int revoke_time_limit:int revoke_pm_time_limit:int rating_e_decay:int stickers_recent_limit:int stickers_faved_limit:int channels_read_media_period:int tmp_sessions:flags.0?int pinned_dialogs_count_max:int call_receive_timeout_ms:int call_ring_timeout_ms:int call_connect_timeout_ms:int call_packet_timeout_ms:int me_url_prefix:string suggested_lang_code:flags.2?string lang_pack_version:flags.2?int = Config;
|
config#eb7bb160 flags:# phonecalls_enabled:flags.1?true default_p2p_contacts:flags.3?true preload_featured_stickers:flags.4?true ignore_phone_entities:flags.5?true revoke_pm_inbox:flags.6?true blocked_mode:flags.8?true date:int expires:int test_mode:Bool this_dc:int dc_options:Vector<DcOption> chat_size_max:int megagroup_size_max:int forwarded_count_max:int online_update_period_ms:int offline_blur_timeout_ms:int offline_idle_timeout_ms:int online_cloud_timeout_ms:int notify_cloud_delay_ms:int notify_default_delay_ms:int push_chat_period_ms:int push_chat_limit:int saved_gifs_limit:int edit_time_limit:int revoke_time_limit:int revoke_pm_time_limit:int rating_e_decay:int stickers_recent_limit:int stickers_faved_limit:int channels_read_media_period:int tmp_sessions:flags.0?int pinned_dialogs_count_max:int call_receive_timeout_ms:int call_ring_timeout_ms:int call_connect_timeout_ms:int call_packet_timeout_ms:int me_url_prefix:string autoupdate_url_prefix:flags.7?string suggested_lang_code:flags.2?string lang_pack_version:flags.2?int = Config;
|
||||||
|
|
||||||
nearestDc#8e1a1775 country:string this_dc:int nearest_dc:int = NearestDc;
|
nearestDc#8e1a1775 country:string this_dc:int nearest_dc:int = NearestDc;
|
||||||
|
|
||||||
|
|
|
@ -528,6 +528,7 @@ struct Data {
|
||||||
int32 CallConnectTimeoutMs = 30000;
|
int32 CallConnectTimeoutMs = 30000;
|
||||||
int32 CallPacketTimeoutMs = 10000;
|
int32 CallPacketTimeoutMs = 10000;
|
||||||
bool PhoneCallsEnabled = true;
|
bool PhoneCallsEnabled = true;
|
||||||
|
bool BlockedMode = false;
|
||||||
base::Observable<void> PhoneCallsEnabledChanged;
|
base::Observable<void> PhoneCallsEnabledChanged;
|
||||||
|
|
||||||
HiddenPinnedMessagesMap HiddenPinnedMessages;
|
HiddenPinnedMessagesMap HiddenPinnedMessages;
|
||||||
|
@ -651,6 +652,7 @@ DefineVar(Global, int32, CallRingTimeoutMs);
|
||||||
DefineVar(Global, int32, CallConnectTimeoutMs);
|
DefineVar(Global, int32, CallConnectTimeoutMs);
|
||||||
DefineVar(Global, int32, CallPacketTimeoutMs);
|
DefineVar(Global, int32, CallPacketTimeoutMs);
|
||||||
DefineVar(Global, bool, PhoneCallsEnabled);
|
DefineVar(Global, bool, PhoneCallsEnabled);
|
||||||
|
DefineVar(Global, bool, BlockedMode);
|
||||||
DefineRefVar(Global, base::Observable<void>, PhoneCallsEnabledChanged);
|
DefineRefVar(Global, base::Observable<void>, PhoneCallsEnabledChanged);
|
||||||
|
|
||||||
DefineVar(Global, HiddenPinnedMessagesMap, HiddenPinnedMessages);
|
DefineVar(Global, HiddenPinnedMessagesMap, HiddenPinnedMessages);
|
||||||
|
|
|
@ -345,6 +345,7 @@ DeclareVar(int32, CallRingTimeoutMs);
|
||||||
DeclareVar(int32, CallConnectTimeoutMs);
|
DeclareVar(int32, CallConnectTimeoutMs);
|
||||||
DeclareVar(int32, CallPacketTimeoutMs);
|
DeclareVar(int32, CallPacketTimeoutMs);
|
||||||
DeclareVar(bool, PhoneCallsEnabled);
|
DeclareVar(bool, PhoneCallsEnabled);
|
||||||
|
DeclareVar(bool, BlockedMode);
|
||||||
DeclareRefVar(base::Observable<void>, PhoneCallsEnabledChanged);
|
DeclareRefVar(base::Observable<void>, PhoneCallsEnabledChanged);
|
||||||
|
|
||||||
typedef QMap<PeerId, MsgId> HiddenPinnedMessagesMap;
|
typedef QMap<PeerId, MsgId> HiddenPinnedMessagesMap;
|
||||||
|
|
|
@ -26,6 +26,7 @@ namespace MTP {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
constexpr auto kConfigBecomesOldIn = 2 * 60 * TimeMs(1000);
|
constexpr auto kConfigBecomesOldIn = 2 * 60 * TimeMs(1000);
|
||||||
|
constexpr auto kConfigBecomesOldForBlockedIn = 8 * TimeMs(1000);
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
@ -126,6 +127,7 @@ private:
|
||||||
void logoutGuestDcs();
|
void logoutGuestDcs();
|
||||||
bool logoutGuestDone(mtpRequestId requestId);
|
bool logoutGuestDone(mtpRequestId requestId);
|
||||||
|
|
||||||
|
void requestConfigIfExpired();
|
||||||
void configLoadDone(const MTPConfig &result);
|
void configLoadDone(const MTPConfig &result);
|
||||||
bool configLoadFail(const RPCError &error);
|
bool configLoadFail(const RPCError &error);
|
||||||
|
|
||||||
|
@ -160,6 +162,7 @@ private:
|
||||||
QString _userPhone;
|
QString _userPhone;
|
||||||
mtpRequestId _cdnConfigLoadRequestId = 0;
|
mtpRequestId _cdnConfigLoadRequestId = 0;
|
||||||
TimeMs _lastConfigLoadedTime = 0;
|
TimeMs _lastConfigLoadedTime = 0;
|
||||||
|
TimeMs _configExpiresAt = 0;
|
||||||
|
|
||||||
std::map<DcId, AuthKeyPtr> _keysForWrite;
|
std::map<DcId, AuthKeyPtr> _keysForWrite;
|
||||||
mutable QReadWriteLock _keysForWriteLock;
|
mutable QReadWriteLock _keysForWriteLock;
|
||||||
|
@ -303,7 +306,22 @@ void Instance::Private::setUserPhone(const QString &phone) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Instance::Private::requestConfigIfOld() {
|
void Instance::Private::requestConfigIfOld() {
|
||||||
if (getms(true) - _lastConfigLoadedTime >= kConfigBecomesOldIn) {
|
const auto timeout = Global::BlockedMode()
|
||||||
|
? kConfigBecomesOldForBlockedIn
|
||||||
|
: kConfigBecomesOldIn;
|
||||||
|
if (getms(true) - _lastConfigLoadedTime >= timeout) {
|
||||||
|
requestConfig();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Instance::Private::requestConfigIfExpired() {
|
||||||
|
const auto requestIn = (_configExpiresAt - getms(true));
|
||||||
|
if (requestIn > 0) {
|
||||||
|
App::CallDelayed(
|
||||||
|
std::min(requestIn, 3600 * TimeMs(1000)),
|
||||||
|
_instance,
|
||||||
|
[=] { requestConfigIfExpired(); });
|
||||||
|
} else {
|
||||||
requestConfig();
|
requestConfig();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -639,10 +657,16 @@ void Instance::Private::configLoadDone(const MTPConfig &result) {
|
||||||
Global::SetPhoneCallsEnabled(data.is_phonecalls_enabled());
|
Global::SetPhoneCallsEnabled(data.is_phonecalls_enabled());
|
||||||
Global::RefPhoneCallsEnabledChanged().notify();
|
Global::RefPhoneCallsEnabledChanged().notify();
|
||||||
}
|
}
|
||||||
|
Global::SetBlockedMode(data.is_blocked_mode());
|
||||||
|
|
||||||
Lang::CurrentCloudManager().setSuggestedLanguage(data.has_suggested_lang_code() ? qs(data.vsuggested_lang_code) : QString());
|
Lang::CurrentCloudManager().setSuggestedLanguage(data.has_suggested_lang_code() ? qs(data.vsuggested_lang_code) : QString());
|
||||||
|
|
||||||
Local::writeSettings();
|
Local::writeSettings();
|
||||||
|
|
||||||
|
_configExpiresAt = getms(true)
|
||||||
|
+ (data.vexpires.v - unixtime()) * TimeMs(1000);
|
||||||
|
requestConfigIfExpired();
|
||||||
|
|
||||||
emit _instance->configLoaded();
|
emit _instance->configLoaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue