From dcf8ec6a776fde032049a158547076e26cd93caa Mon Sep 17 00:00:00 2001 From: Akshaya Salvi Date: Sun, 5 Dec 2021 10:31:20 +0530 Subject: [PATCH 1/8] Added attachment size check for videos on native --- .../AttachmentPicker/index.native.js | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/components/AttachmentPicker/index.native.js b/src/components/AttachmentPicker/index.native.js index 494d33bf76f2..1f729e84386b 100644 --- a/src/components/AttachmentPicker/index.native.js +++ b/src/components/AttachmentPicker/index.native.js @@ -6,6 +6,7 @@ import React, {Component} from 'react'; import {Alert, Linking, View} from 'react-native'; import {launchImageLibrary} from 'react-native-image-picker'; import RNDocumentPicker from 'react-native-document-picker'; +import RNFetchBlob from 'rn-fetch-blob'; import {propTypes as basePropTypes, defaultProps} from './attachmentPickerPropTypes'; import styles from '../../styles/styles'; import Popover from '../Popover'; @@ -62,12 +63,22 @@ const documentPickerOptions = { * @return {Object} */ function getDataForUpload(fileData) { - return { - name: fileData.fileName || fileData.name || 'chat_attachment', - type: fileData.type, - uri: fileData.uri, - size: fileData.fileSize || fileData.size, - }; + return new Promise((resolve, reject) => { + const fileResult = { + name: fileData.fileName || fileData.name || 'chat_attachment', + type: fileData.type, + uri: fileData.uri, + size: fileData.fileSize || fileData.size, + }; + if (_.has(fileData, 'fileSize') || _.has(fileData, 'size')) { + return resolve(fileResult); + } + + RNFetchBlob.fs.stat(fileData.uri.replace('file://', '')).then((stats) => { + fileResult.size = stats.size; + return resolve(fileResult); + }).catch(reject); + }); } /** @@ -129,8 +140,11 @@ class AttachmentPicker extends Component { return; } - const result = getDataForUpload(attachment); - this.completeAttachmentSelection(result); + getDataForUpload(attachment).then((result) => { + this.completeAttachmentSelection(result); + }).catch(() => { + this.showGeneralAlert(); + }); } /** From a500f43ca41db8dadf75fda7d82b121a3f9e6483 Mon Sep 17 00:00:00 2001 From: Akshaya Salvi Date: Tue, 7 Dec 2021 19:17:23 +0530 Subject: [PATCH 2/8] thrown the received error for picker --- src/components/AttachmentPicker/index.native.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/AttachmentPicker/index.native.js b/src/components/AttachmentPicker/index.native.js index 1f729e84386b..81f0d88cd033 100644 --- a/src/components/AttachmentPicker/index.native.js +++ b/src/components/AttachmentPicker/index.native.js @@ -142,8 +142,9 @@ class AttachmentPicker extends Component { getDataForUpload(attachment).then((result) => { this.completeAttachmentSelection(result); - }).catch(() => { - this.showGeneralAlert(); + }).catch((error) => { + this.showGeneralAlert(error.message); + throw error; }); } From 75386dc23c524678e385a4ff7c69ce7e11bc6bbf Mon Sep 17 00:00:00 2001 From: Akshaya Salvi Date: Wed, 8 Dec 2021 21:28:35 +0530 Subject: [PATCH 3/8] Changed promise structure --- .../AttachmentPicker/index.native.js | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/components/AttachmentPicker/index.native.js b/src/components/AttachmentPicker/index.native.js index 81f0d88cd033..156fd0827f96 100644 --- a/src/components/AttachmentPicker/index.native.js +++ b/src/components/AttachmentPicker/index.native.js @@ -63,21 +63,20 @@ const documentPickerOptions = { * @return {Object} */ function getDataForUpload(fileData) { - return new Promise((resolve, reject) => { - const fileResult = { - name: fileData.fileName || fileData.name || 'chat_attachment', - type: fileData.type, - uri: fileData.uri, - size: fileData.fileSize || fileData.size, - }; - if (_.has(fileData, 'fileSize') || _.has(fileData, 'size')) { - return resolve(fileResult); - } + const fileResult = { + name: fileData.fileName || fileData.name || 'chat_attachment', + type: fileData.type, + uri: fileData.uri, + size: fileData.fileSize || fileData.size, + }; + + if (fileResult.size) { + return Promise.resolve(fileResult); + } - RNFetchBlob.fs.stat(fileData.uri.replace('file://', '')).then((stats) => { - fileResult.size = stats.size; - return resolve(fileResult); - }).catch(reject); + return RNFetchBlob.fs.stat(fileData.uri.replace('file://', '')).then((stats) => { + fileResult.size = stats.size; + return fileResult; }); } From c675c6f2a79d57468fe1b19d76caf069f66b95b8 Mon Sep 17 00:00:00 2001 From: Akshaya Salvi Date: Wed, 8 Dec 2021 21:59:05 +0530 Subject: [PATCH 4/8] Added noop for completeAttachmentSelection --- src/components/AttachmentPicker/index.native.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/AttachmentPicker/index.native.js b/src/components/AttachmentPicker/index.native.js index 156fd0827f96..c4eb7c79d241 100644 --- a/src/components/AttachmentPicker/index.native.js +++ b/src/components/AttachmentPicker/index.native.js @@ -121,6 +121,7 @@ class AttachmentPicker extends Component { this.close = this.close.bind(this); this.pickAttachment = this.pickAttachment.bind(this); + this.completeAttachmentSelection = () => {}; } /** From d1c2e4cd6439d84f93fe386eae7338c0c37f4ca4 Mon Sep 17 00:00:00 2001 From: Akshaya Salvi Date: Thu, 9 Dec 2021 08:51:23 +0530 Subject: [PATCH 5/8] Return Promise --- src/components/AttachmentPicker/index.native.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/components/AttachmentPicker/index.native.js b/src/components/AttachmentPicker/index.native.js index c4eb7c79d241..c3b6397005a6 100644 --- a/src/components/AttachmentPicker/index.native.js +++ b/src/components/AttachmentPicker/index.native.js @@ -129,6 +129,7 @@ class AttachmentPicker extends Component { * sends the selected attachment to the caller (parent component) * * @param {ImagePickerResponse|DocumentPickerResponse} attachment + * @returns {Promise} */ pickAttachment(attachment) { if (!attachment) { @@ -140,11 +141,8 @@ class AttachmentPicker extends Component { return; } - getDataForUpload(attachment).then((result) => { + return getDataForUpload(attachment).then((result) => { this.completeAttachmentSelection(result); - }).catch((error) => { - this.showGeneralAlert(error.message); - throw error; }); } From c26ae54183974c7f8710ba3a5b214999c92c614b Mon Sep 17 00:00:00 2001 From: akshayasalvi <57435789+akshayasalvi@users.noreply.github.com> Date: Thu, 9 Dec 2021 17:06:05 +0530 Subject: [PATCH 6/8] Update src/components/AttachmentPicker/index.native.js Added Promise for jsdoc Co-authored-by: Alex Beaman --- src/components/AttachmentPicker/index.native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/AttachmentPicker/index.native.js b/src/components/AttachmentPicker/index.native.js index c3b6397005a6..096ccad8b4c2 100644 --- a/src/components/AttachmentPicker/index.native.js +++ b/src/components/AttachmentPicker/index.native.js @@ -60,7 +60,7 @@ const documentPickerOptions = { * send to the xhr will be handled properly. * * @param {Object} fileData - * @return {Object} + * @return {Promise} */ function getDataForUpload(fileData) { const fileResult = { From 4ba96a8437ae9482ffab47312ee7278808137ee4 Mon Sep 17 00:00:00 2001 From: Akshaya Salvi Date: Thu, 9 Dec 2021 18:47:45 +0530 Subject: [PATCH 7/8] Added catch for error block --- src/components/AttachmentPicker/index.native.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/components/AttachmentPicker/index.native.js b/src/components/AttachmentPicker/index.native.js index c3b6397005a6..a6d47d19f62c 100644 --- a/src/components/AttachmentPicker/index.native.js +++ b/src/components/AttachmentPicker/index.native.js @@ -143,6 +143,9 @@ class AttachmentPicker extends Component { return getDataForUpload(attachment).then((result) => { this.completeAttachmentSelection(result); + }).catch((error) => { + this.showGeneralAlert(error.message); + throw error; }); } From a5d18d8f2a7a550cb535045da8734a8659254674 Mon Sep 17 00:00:00 2001 From: akshayasalvi <57435789+akshayasalvi@users.noreply.github.com> Date: Thu, 9 Dec 2021 20:44:05 +0530 Subject: [PATCH 8/8] Removed the function noop --- src/components/AttachmentPicker/index.native.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/AttachmentPicker/index.native.js b/src/components/AttachmentPicker/index.native.js index c3291b04c28c..883aa70a2ff3 100644 --- a/src/components/AttachmentPicker/index.native.js +++ b/src/components/AttachmentPicker/index.native.js @@ -121,7 +121,6 @@ class AttachmentPicker extends Component { this.close = this.close.bind(this); this.pickAttachment = this.pickAttachment.bind(this); - this.completeAttachmentSelection = () => {}; } /**