Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3786 from matrix-org/t3chguy/serialize_file_uploads
Browse files Browse the repository at this point in the history
Serialize file uploads into room to match confirmation dialog order
  • Loading branch information
t3chguy committed Dec 27, 2019
2 parents 0591188 + 9f948b5 commit c79bd79
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/ContentMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,9 @@ export default class ContentMessages {

const UploadConfirmDialog = sdk.getComponent("dialogs.UploadConfirmDialog");
let uploadAll = false;
// Promise to complete before sending next file into room, used for synchronisation of file-sending
// to match the order the files were specified in
let promBefore = Promise.resolve();
for (let i = 0; i < okFiles.length; ++i) {
const file = okFiles[i];
if (!uploadAll) {
Expand All @@ -440,11 +443,11 @@ export default class ContentMessages {
});
if (!shouldContinue) break;
}
this._sendContentToRoom(file, roomId, matrixClient);
promBefore = this._sendContentToRoom(file, roomId, matrixClient, promBefore);
}
}

_sendContentToRoom(file, roomId, matrixClient) {
_sendContentToRoom(file, roomId, matrixClient, promBefore) {
const content = {
body: file.name || 'Attachment',
info: {
Expand Down Expand Up @@ -517,7 +520,10 @@ export default class ContentMessages {
content.file = result.file;
content.url = result.url;
});
}).then(function(url) {
}).then((url) => {
// Await previous message being sent into the room
return promBefore;
}).then(function() {
return matrixClient.sendMessage(roomId, content);
}, function(err) {
error = err;
Expand Down

0 comments on commit c79bd79

Please sign in to comment.