From 4be14080e1d3a9621eee6fb3fbfe554e97b3269b Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 16 Dec 2016 17:11:28 +0000 Subject: [PATCH] Fix cancel button on uploads --- src/ContentMessages.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/ContentMessages.js b/src/ContentMessages.js index e2f9086f66..c169ce64b5 100644 --- a/src/ContentMessages.js +++ b/src/ContentMessages.js @@ -256,10 +256,14 @@ function uploadFile(matrixClient, roomId, file) { }); }); } else { - return matrixClient.uploadContent(file).then(function(url) { + const basePromise = matrixClient.uploadContent(file); + const promise1 = basePromise.then(function(url) { // If the attachment isn't encrypted then include the URL directly. return {"url": url}; }); + // XXX: copy over the abort method to the new promise + promise1.abort = basePromise.abort; + return promise1; } } @@ -322,13 +326,16 @@ class ContentMessages { var error; return def.promise.then(function() { + // XXX: upload.promise must be the promise that + // is returned by uploadFile as it has an abort() + // method hacked onto it. upload.promise = uploadFile( matrixClient, roomId, file - ).then(function(result) { + ); + return upload.promise.then(function(result) { content.file = result.file; content.url = result.url; }); - return upload.promise; }).progress(function(ev) { if (ev) { upload.total = ev.total;