From bab1cc0601fba3b9f5513dfb2eccc32c8f345f12 Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Thu, 10 Sep 2020 15:12:00 -0300 Subject: [PATCH] AppConfig setting to control the default request timeout (#4797) * AppConfig setting to control the default request timeout * Set default timeout to 10s --- android/app/src/main/res/values/strings.xml | 2 ++ android/app/src/main/res/xml/app_restrictions.xml | 6 ++++++ app/init/fetch.js | 13 ++++++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml index d3a95fa69..e14e36d44 100644 --- a/android/app/src/main/res/values/strings.xml +++ b/android/app/src/main/res/values/strings.xml @@ -14,6 +14,8 @@ Allow the user to change the above server URL. Default Username Set the username or email address to use to authenticate against the Mattermost Server. + Default Request Timeout + How long in milliseconds the mobile app should wait for the server to respond. EMM Vendor or Company Name Name of the EMM vendor or company deploying the app. Used in help text when prompting for passcodes so users are aware why the app is being protected. diff --git a/android/app/src/main/res/xml/app_restrictions.xml b/android/app/src/main/res/xml/app_restrictions.xml index fda826002..27a0e9e2e 100644 --- a/android/app/src/main/res/xml/app_restrictions.xml +++ b/android/app/src/main/res/xml/app_restrictions.xml @@ -43,6 +43,12 @@ android:description="@string/username_description" android:restrictionType="string" android:defaultValue="" /> + { + if (config.timeout !== managedConfig?.timeout) { + initFetchConfig(); + return; + } + managedConfig = config; }); @@ -150,11 +156,16 @@ Client4.doFetchWithResponse = async (url, options) => { const initFetchConfig = async () => { const fetchConfig = { auto: true, - timeout: 5000, // Set the base timeout for every request to 5s + timeout: DEFAULT_TIMEOUT, // Set the base timeout for every request to 5s }; try { managedConfig = await mattermostManaged.getConfig(); + + if (managedConfig?.timeout) { + const timeout = parseInt(managedConfig.timeout, 10); + fetchConfig.timeout = timeout || DEFAULT_TIMEOUT; + } } catch { // no managed config }