Skip to content

Commit 27c4152

Browse files
author
Dan Carbonell
committed
decouple text/loading image messages based on prop
1 parent 355e4fb commit 27c4152

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

src/components/MessageInput.js

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,17 @@ class MessageInput extends PureComponent {
228228
]),
229229
/** Disables the child MessageInput component */
230230
disabled: PropTypes.bool,
231+
/**
232+
* For images still in uploading state when user hits send, send text immediately and send image as follow-up message once uploaded
233+
*/
234+
sendImageAsync: PropTypes.bool,
231235
};
232236

233237
static defaultProps = {
234238
hasImagePicker: true,
235239
hasFilePicker: true,
236240
disabled: false,
241+
sendImageAsync: false,
237242
SendButton,
238243
AttachButton,
239244
};
@@ -472,9 +477,13 @@ class MessageInput extends PureComponent {
472477

473478
if (image.state === FileState.UPLOADING) {
474479
// TODO: show error to user that they should wait until image is uploaded
475-
this.setState((prevState) => ({
476-
asyncIds: [...prevState.asyncIds, id],
477-
}));
480+
if (this.props.sendImageAsync) {
481+
this.setState((prevState) => ({
482+
asyncIds: [...prevState.asyncIds, id],
483+
}));
484+
} else {
485+
return this.setState({ sending: false, text });
486+
}
478487
}
479488

480489
if (image.state === FileState.UPLOADED) {
@@ -733,6 +742,8 @@ class MessageInput extends PureComponent {
733742
return;
734743
}
735744

745+
let response;
746+
736747
const filename = (file.name || file.uri).replace(
737748
/^(file:\/\/|content:\/\/)/,
738749
'',
@@ -741,16 +752,11 @@ class MessageInput extends PureComponent {
741752

742753
try {
743754
if (this.props.doImageUploadRequest) {
744-
const response = await this.props.doImageUploadRequest(
755+
response = await this.props.doImageUploadRequest(
745756
file,
746757
this.props.channel,
747758
);
748-
this.setState((prevState) => ({
749-
imageUploads: prevState.imageUploads
750-
.setIn([id, 'state'], FileState.UPLOADED)
751-
.setIn([id, 'url'], response.file),
752-
}));
753-
} else {
759+
} else if (this.props.sendImageAsync) {
754760
this.props.channel
755761
.sendImage(file.uri, null, contentType)
756762
.then((res) => {
@@ -768,6 +774,20 @@ class MessageInput extends PureComponent {
768774
}));
769775
}
770776
});
777+
} else {
778+
response = await this.props.channel.sendImage(
779+
file.uri,
780+
null,
781+
contentType,
782+
);
783+
}
784+
785+
if (response) {
786+
this.setState((prevState) => ({
787+
imageUploads: prevState.imageUploads
788+
.setIn([id, 'state'], FileState.UPLOADED)
789+
.setIn([id, 'url'], response.file),
790+
}));
771791
}
772792
} catch (e) {
773793
console.warn(e);

0 commit comments

Comments
 (0)