2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Improve config re-requesting.

This commit is contained in:
John Preston
2018-05-02 22:52:57 +03:00
parent 4bf66cb6e9
commit 62c812858e
4 changed files with 29 additions and 2 deletions

View File

@@ -528,6 +528,7 @@ struct Data {
int32 CallConnectTimeoutMs = 30000;
int32 CallPacketTimeoutMs = 10000;
bool PhoneCallsEnabled = true;
bool BlockedMode = false;
base::Observable<void> PhoneCallsEnabledChanged;
HiddenPinnedMessagesMap HiddenPinnedMessages;
@@ -651,6 +652,7 @@ DefineVar(Global, int32, CallRingTimeoutMs);
DefineVar(Global, int32, CallConnectTimeoutMs);
DefineVar(Global, int32, CallPacketTimeoutMs);
DefineVar(Global, bool, PhoneCallsEnabled);
DefineVar(Global, bool, BlockedMode);
DefineRefVar(Global, base::Observable<void>, PhoneCallsEnabledChanged);
DefineVar(Global, HiddenPinnedMessagesMap, HiddenPinnedMessages);

View File

@@ -345,6 +345,7 @@ DeclareVar(int32, CallRingTimeoutMs);
DeclareVar(int32, CallConnectTimeoutMs);
DeclareVar(int32, CallPacketTimeoutMs);
DeclareVar(bool, PhoneCallsEnabled);
DeclareVar(bool, BlockedMode);
DeclareRefVar(base::Observable<void>, PhoneCallsEnabledChanged);
typedef QMap<PeerId, MsgId> HiddenPinnedMessagesMap;

View File

@@ -26,6 +26,7 @@ namespace MTP {
namespace {
constexpr auto kConfigBecomesOldIn = 2 * 60 * TimeMs(1000);
constexpr auto kConfigBecomesOldForBlockedIn = 8 * TimeMs(1000);
} // namespace
@@ -126,6 +127,7 @@ private:
void logoutGuestDcs();
bool logoutGuestDone(mtpRequestId requestId);
void requestConfigIfExpired();
void configLoadDone(const MTPConfig &result);
bool configLoadFail(const RPCError &error);
@@ -160,6 +162,7 @@ private:
QString _userPhone;
mtpRequestId _cdnConfigLoadRequestId = 0;
TimeMs _lastConfigLoadedTime = 0;
TimeMs _configExpiresAt = 0;
std::map<DcId, AuthKeyPtr> _keysForWrite;
mutable QReadWriteLock _keysForWriteLock;
@@ -303,7 +306,22 @@ void Instance::Private::setUserPhone(const QString &phone) {
}
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();
}
}
@@ -639,10 +657,16 @@ void Instance::Private::configLoadDone(const MTPConfig &result) {
Global::SetPhoneCallsEnabled(data.is_phonecalls_enabled());
Global::RefPhoneCallsEnabledChanged().notify();
}
Global::SetBlockedMode(data.is_blocked_mode());
Lang::CurrentCloudManager().setSuggestedLanguage(data.has_suggested_lang_code() ? qs(data.vsuggested_lang_code) : QString());
Local::writeSettings();
_configExpiresAt = getms(true)
+ (data.vexpires.v - unixtime()) * TimeMs(1000);
requestConfigIfExpired();
emit _instance->configLoaded();
}