Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't immediately send & send multiple images. #5125

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ SPEC CHECKSUMS:
EXScreenOrientation: 09fe6b6b87899ae0c9320255bda7b7513cdfc8ec
EXWebBrowser: 76783ba5dcb8699237746ecf41a9643d428a4cc5
FBLazyVector: e686045572151edef46010a6f819ade377dfeb4b
FBReactNativeSpec: b96f20d2bcabd43e9acdeff6210208026a13633a
FBReactNativeSpec: 84bf0ee621e47a89282c2b1960e92dcb9d991b0c
Flipper: d3da1aa199aad94455ae725e9f3aa43f3ec17021
Flipper-DoubleConversion: 38631e41ef4f9b12861c67d17cb5518d06badc41
Flipper-Folly: 755929a4f851b2fb2c347d533a23f191b008554c
Expand Down
4 changes: 2 additions & 2 deletions ios/ZulipMobile.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "arm64 ";
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
Expand Down Expand Up @@ -524,7 +524,7 @@
COPY_PHASE_STRIP = YES;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "arm64 ";
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
Expand Down
37 changes: 22 additions & 15 deletions src/compose/ComposeMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { PureComponent } from 'react';
import type { ComponentType } from 'react';
import { Platform, View, Alert, Linking } from 'react-native';
import type { DocumentPickerResponse } from 'react-native-document-picker';
import type { Asset } from 'react-native-image-picker';
import { launchCamera, launchImageLibrary } from 'react-native-image-picker';

import * as logging from '../utils/logging';
Expand All @@ -20,7 +21,6 @@ import {
IconVideo,
} from '../common/Icons';
import AnimatedComponent from '../animation/AnimatedComponent';
import { uploadFile } from '../actions';
import { androidEnsureStoragePermission } from '../lightbox/download';

type OuterProps = $ReadOnly<{|
Expand Down Expand Up @@ -88,8 +88,23 @@ class ComposeMenuInner extends PureComponent<Props> {
static contextType = TranslationContext;
context: GetText;

toAttachmentResponse = (assets: Array<Asset>): Array<DocumentPickerResponse> => {
const images = [];
for (let i = 0; i < assets.length; i++) {
const asset = assets[i];
if (asset.type !== undefined && asset.uri !== undefined) {
images.push({
name: asset.fileName,
size: asset.fileSize,
type: asset.type,
uri: asset.uri,
});
}
}
return images;
};

handleImagePickerResponse = response => {
const { dispatch, destinationNarrow } = this.props;
const _ = this.context;

if (response.didCancel === true) {
Expand Down Expand Up @@ -130,24 +145,15 @@ class ComposeMenuInner extends PureComponent<Props> {
return;
}

// TODO: support sending multiple files; see library's docs for how to
// let `assets` have more than one item in `response`.
const firstAsset = response.assets && response.assets[0];

const { uri, fileName } = firstAsset ?? {};

if (!firstAsset || uri == null || fileName == null) {
if (!response.assets) {
// TODO: See if we these unexpected situations actually happen.
showErrorAlert(_('Error'), _('Something went wrong, and your message was not sent.'));
logging.error('Unexpected response from image picker', {
'!firstAsset': !firstAsset,
'uri == null': uri == null,
'fileName == null': fileName == null,
});
logging.error('Unexpected response from image picker');
return;
}

dispatch(uploadFile(destinationNarrow, uri, chooseUploadImageFilename(uri, fileName)));
// dispatch(uploadFile(destinationNarrow, uri, chooseUploadImageFilename(uri, fileName)));
this.props.insertAttachment(this.toAttachmentResponse(response.assets));
};

handleImagePicker = () => {
Expand All @@ -158,6 +164,7 @@ class ComposeMenuInner extends PureComponent<Props> {

quality: 1.0,
includeBase64: false,
selectionLimit: 0,
},
this.handleImagePickerResponse,
);
Expand Down