Skip to content

Commit d74f46a

Browse files
compose: Don't immediately send selected image
For why this closes #2366, see Greg's explanation: #5474 (review) Fixes: #4540 Fixes: #2366 Co-authored-by: Akash Dhiman <[email protected]>
1 parent 2a7177f commit d74f46a

File tree

3 files changed

+5
-19
lines changed

3 files changed

+5
-19
lines changed

src/compose/ComposeMenu.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ import DocumentPicker from 'react-native-document-picker';
88
import type { DocumentPickerResponse } from 'react-native-document-picker';
99
import { launchCamera, launchImageLibrary } from 'react-native-image-picker';
1010

11-
import { useDispatch } from '../react-redux';
1211
import * as logging from '../utils/logging';
1312
import { TranslationContext } from '../boot/TranslationProvider';
1413
import type { Narrow } from '../types';
1514
import { showErrorAlert } from '../utils/info';
1615
import { createStyleSheet } from '../styles';
1716
import { IconImage, IconCamera, IconAttach, IconVideo } from '../common/Icons';
18-
import { uploadFile } from '../actions';
1917
import { androidEnsureStoragePermission } from '../lightbox/download';
2018
import { ThemeContext } from '../styles/theme';
2119
import type { SpecificIconType } from '../common/Icons';
@@ -100,9 +98,8 @@ function MenuButton(props: MenuButtonProps) {
10098
}
10199

102100
export default function ComposeMenu(props: Props): Node {
103-
const { destinationNarrow, insertAttachments, insertVideoCallLink } = props;
101+
const { insertAttachments, insertVideoCallLink } = props;
104102

105-
const dispatch = useDispatch();
106103
const _ = useContext(TranslationContext);
107104

108105
const handleImagePickerResponse = useCallback(
@@ -155,7 +152,7 @@ export default function ComposeMenu(props: Props): Node {
155152
// TODO: See if we these unexpected situations actually happen. …Ah,
156153
// yep, reportedly (and we've seen in Sentry):
157154
// https://github.com/react-native-image-picker/react-native-image-picker/issues/1945
158-
showErrorAlert(_('Error'), _('Something went wrong, and your message was not sent.'));
155+
showErrorAlert(_('Error'), _('Failed to attach your file.'));
159156
logging.error('Unexpected response from image picker', {
160157
'!firstAsset': !firstAsset,
161158
'uri == null': uri == null,
@@ -164,9 +161,9 @@ export default function ComposeMenu(props: Props): Node {
164161
return;
165162
}
166163

167-
dispatch(uploadFile(destinationNarrow, uri, chooseUploadImageFilename(uri, fileName)));
164+
insertAttachments([{ name: chooseUploadImageFilename(uri, fileName), url: uri }]);
168165
},
169-
[_, destinationNarrow, dispatch],
166+
[_, insertAttachments],
170167
);
171168

172169
const handleImagePicker = useCallback(() => {

src/message/fetchActions.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import {
3333
import { FIRST_UNREAD_ANCHOR, LAST_MESSAGE_ANCHOR } from '../anchor';
3434
import { ALL_PRIVATE_NARROW, apiNarrowOfNarrow, caseNarrow, topicNarrow } from '../utils/narrow';
3535
import { BackoffMachine, promiseTimeout, TimeoutError } from '../utils/async';
36-
import { addToOutbox } from '../outbox/outboxActions';
3736
import { getAllUsersById, getOwnUserId } from '../users/userSelectors';
3837
import type { ServerSettings } from '../api/settings/getServerSettings';
3938

@@ -390,16 +389,6 @@ export async function tryFetch<T>(
390389
}
391390
}
392391

393-
export const uploadFile =
394-
(destinationNarrow: Narrow, uri: string, name: string): ThunkAction<Promise<void>> =>
395-
async (dispatch, getState) => {
396-
const auth = getAuth(getState());
397-
const response = await api.uploadFile(auth, uri, name);
398-
const messageToSend = `[${name}](${response.uri})`;
399-
400-
dispatch(addToOutbox(destinationNarrow, messageToSend));
401-
};
402-
403392
export async function fetchServerSettings(realm: URL): Promise<
404393
| {| +type: 'success', +value: ServerSettings |}
405394
| {|

static/translations/messages_en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"Updates may be delayed.": "Updates may be delayed.",
2424
"No one has read this message yet.": "No one has read this message yet.",
2525
"Confirm": "Confirm",
26+
"Failed to attach your file.": "Failed to attach your file.",
2627
"Configure permissions": "Configure permissions",
2728
"You": "You",
2829
"Discard changes": "Discard changes",
@@ -72,7 +73,6 @@
7273
"The server sent a malformed response.": "The server sent a malformed response.",
7374
"Storage permission needed": "Storage permission needed",
7475
"Zulip will save a copy of your photo on your device. To do so, Zulip will need permission to store files on your device.": "Zulip will save a copy of your photo on your device. To do so, Zulip will need permission to store files on your device.",
75-
"Something went wrong, and your message was not sent.": "Something went wrong, and your message was not sent.",
7676
"Message not sent": "Message not sent",
7777
"Please specify a topic.": "Please specify a topic.",
7878
"Please specify a stream.": "Please specify a stream.",

0 commit comments

Comments
 (0)