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

Commit c79bd79

Browse files
authored
Merge pull request #3786 from matrix-org/t3chguy/serialize_file_uploads
Serialize file uploads into room to match confirmation dialog order
2 parents 0591188 + 9f948b5 commit c79bd79

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/ContentMessages.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,9 @@ export default class ContentMessages {
422422

423423
const UploadConfirmDialog = sdk.getComponent("dialogs.UploadConfirmDialog");
424424
let uploadAll = false;
425+
// Promise to complete before sending next file into room, used for synchronisation of file-sending
426+
// to match the order the files were specified in
427+
let promBefore = Promise.resolve();
425428
for (let i = 0; i < okFiles.length; ++i) {
426429
const file = okFiles[i];
427430
if (!uploadAll) {
@@ -440,11 +443,11 @@ export default class ContentMessages {
440443
});
441444
if (!shouldContinue) break;
442445
}
443-
this._sendContentToRoom(file, roomId, matrixClient);
446+
promBefore = this._sendContentToRoom(file, roomId, matrixClient, promBefore);
444447
}
445448
}
446449

447-
_sendContentToRoom(file, roomId, matrixClient) {
450+
_sendContentToRoom(file, roomId, matrixClient, promBefore) {
448451
const content = {
449452
body: file.name || 'Attachment',
450453
info: {
@@ -517,7 +520,10 @@ export default class ContentMessages {
517520
content.file = result.file;
518521
content.url = result.url;
519522
});
520-
}).then(function(url) {
523+
}).then((url) => {
524+
// Await previous message being sent into the room
525+
return promBefore;
526+
}).then(function() {
521527
return matrixClient.sendMessage(roomId, content);
522528
}, function(err) {
523529
error = err;

0 commit comments

Comments
 (0)