From ae2d9b996ce6c948f8a968665f5a6f4fbaab91e2 Mon Sep 17 00:00:00 2001 From: Andrea Maria Piana Date: Thu, 19 Nov 2020 07:08:12 +0100 Subject: [PATCH] Limit max batch of images There's an issue reported on slow devices when sending a batch of images. All the requests are send concurrently, and the sending of messages is processed concurrently in the background. On slow devices or connection with slow upload speed this may result in expired envelopes, as the POW calculation or the upload takes too long, and either they never leave the device, or worse they reach the mailserver but won't be stored because already expired on arrival. This commit allows setting the max-images-batch config value, setting it to 1 for release and keeping it to 5 for other builds. Signed-off-by: Andrea Maria Piana --- .env | 1 + .env.e2e | 1 + .env.jenkins | 3 ++- .env.nightly | 3 ++- .env.release | 1 + src/status_im/chat/models/images.cljs | 8 ++++---- src/status_im/ui/screens/chat/image/views.cljs | 4 ++-- src/status_im/utils/config.cljs | 1 + 8 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.env b/.env index 20fdd53690..e0408dadb2 100644 --- a/.env +++ b/.env @@ -24,4 +24,5 @@ QR_READ_TEST_MENU=1 ENABLE_ROOT_ALERT=1 ENABLE_REFERRAL_INVITE=1 ENABLE_QUO_PREVIEW=1 +MAX_IMAGES_BATCH=5 APN_TOPIC=im.status.ethereum.pr diff --git a/.env.e2e b/.env.e2e index ea2482e0e0..7658cf856a 100644 --- a/.env.e2e +++ b/.env.e2e @@ -23,4 +23,5 @@ KEYCARD_TEST_MENU=1 QR_READ_TEST_MENU=1 ENABLE_ROOT_ALERT=0 ENABLE_REFERRAL_INVITE=1 +MAX_IMAGES_BATCH=5 APN_TOPIC=im.status.ethereum.pr diff --git a/.env.jenkins b/.env.jenkins index aece007766..d512e26490 100644 --- a/.env.jenkins +++ b/.env.jenkins @@ -24,4 +24,5 @@ ENABLE_REFERRAL_INVITE=1 DISABLE_WALLET_ON_MOBILE_NETWORK=1 APN_TOPIC=im.status.ethereum.pr BLANK_PREVIEW=0 -GOOGLE_FREE=0 \ No newline at end of file +MAX_IMAGES_BATCH=5 +GOOGLE_FREE=0 diff --git a/.env.nightly b/.env.nightly index 0a07b2c26b..62b08d1343 100644 --- a/.env.nightly +++ b/.env.nightly @@ -18,4 +18,5 @@ PARTITIONED_TOPIC=0 CONTRACT_NODES=1 ENABLE_ROOT_ALERT=1 ENABLE_REFERRAL_INVITE=0 -BLANK_PREVIEW=0 \ No newline at end of file +MAX_IMAGES_BATCH=5 +BLANK_PREVIEW=0 diff --git a/.env.release b/.env.release index 5570e201f5..be3001d2dd 100644 --- a/.env.release +++ b/.env.release @@ -16,4 +16,5 @@ SNOOPY=0 RPC_NETWORKS_ONLY=1 PARTITIONED_TOPIC=0 ENABLE_ROOT_ALERT=1 +MAX_IMAGES_BATCH=1 ENABLE_REFERRAL_INVITE=0 diff --git a/src/status_im/chat/models/images.cljs b/src/status_im/chat/models/images.cljs index f1d692baf5..c74b84c0c9 100644 --- a/src/status_im/chat/models/images.cljs +++ b/src/status_im/chat/models/images.cljs @@ -3,6 +3,7 @@ [status-im.utils.fx :as fx] ["@react-native-community/cameraroll" :as CameraRoll] [status-im.utils.types :as types] + [status-im.utils.config :as config] [status-im.ui.components.permissions :as permissions] [status-im.ui.components.react :as react] [status-im.utils.image-processing :as image-processing] @@ -11,7 +12,6 @@ [status-im.utils.platform :as platform])) (def maximum-image-size-px 2000) -(def max-images-batch 5) (defn- resize-and-call [uri cb] (react/image-get-size @@ -63,7 +63,7 @@ (when (and platform/ios? (pos? (count images))) (re-frame/dispatch [:chat.ui/clear-sending-images])) (doseq [^js result (if platform/ios? - (take max-images-batch images) + (take config/max-images-batch images) [images])] (resize-and-call (.-path result) #(re-frame/dispatch [:chat.ui/image-selected (result->id result) %])))) @@ -132,7 +132,7 @@ [{:keys [db]}] (let [current-chat-id (:current-chat-id db) images (get-in db [:chats current-chat-id :metadata :sending-image])] - (when (< (count images) max-images-batch) + (when (< (count images) config/max-images-batch) {::chat-open-image-picker nil}))) (fx/defn camera-roll-pick @@ -143,7 +143,7 @@ (if (get-in db [:chats current-chat-id :timeline?]) {:db (update-in db [:chats current-chat-id :metadata :sending-image] {uri {:uri uri}}) ::image-selected uri} - (when (and (< (count images) max-images-batch) + (when (and (< (count images) config/max-images-batch) (not (get images uri))) {:db (update-in db [:chats current-chat-id :metadata :sending-image] assoc uri {:uri uri}) ::image-selected uri})))) diff --git a/src/status_im/ui/screens/chat/image/views.cljs b/src/status_im/ui/screens/chat/image/views.cljs index 42a982e3f6..d5560c7989 100644 --- a/src/status_im/ui/screens/chat/image/views.cljs +++ b/src/status_im/ui/screens/chat/image/views.cljs @@ -3,11 +3,11 @@ (:require [status-im.ui.components.react :as react] [status-im.ui.components.icons.vector-icons :as icons] [status-im.ui.components.permissions :as permissions] + [status-im.utils.config :as config] [reagent.core :as reagent] [quo.components.animated.pressable :as pressable] [re-frame.core :as re-frame] [quo.design-system.colors :as colors] - [status-im.chat.models.images :as images] [quo.core :as quo] [status-im.utils.utils :as utils] [status-im.i18n :as i18n])) @@ -51,7 +51,7 @@ (defn image-preview [uri all-selected first? panel-height] (let [wh (/ (- panel-height 8) 2) selected (get all-selected uri) - max-selected (>= (count all-selected) images/max-images-batch)] + max-selected (>= (count all-selected) config/max-images-batch)] [react/touchable-highlight {:on-press #(if selected (re-frame/dispatch [:chat.ui/image-unselected uri]) (re-frame/dispatch [:chat.ui/camera-roll-pick uri])) diff --git a/src/status_im/utils/config.cljs b/src/status_im/utils/config.cljs index ef11bffbe5..33d20a1b12 100644 --- a/src/status_im/utils/config.cljs +++ b/src/status_im/utils/config.cljs @@ -29,6 +29,7 @@ (def erc20-contract-warnings-enabled? (enabled? (get-config :ERC20_CONTRACT_WARNINGS))) (def tr-to-talk-enabled? (enabled? (get-config :TRIBUTE_TO_TALK 0))) (def max-message-delivery-attempts (js/parseInt (get-config :MAX_MESSAGE_DELIVERY_ATTEMPTS "6"))) +(def max-images-batch (js/parseInt (get-config :MAX_IMAGES_BATCH "1"))) ;; NOTE: only disabled in releases (def local-notifications? (enabled? (get-config :LOCAL_NOTIFICATIONS "1"))) (def blank-preview? (enabled? (get-config :BLANK_PREVIEW "1")))