From a6fe1b188f7e502f5412bee61fa8c0d437e7bcf6 Mon Sep 17 00:00:00 2001 From: Ray Nicholus Date: Fri, 31 Mar 2017 23:59:43 -0500 Subject: [PATCH] fix(uploader.basic.api.js): early initial files onStatusChange onStatusChange is called for initial/canned files before internal state for the file is completely updated. This change introduces an update that makes it easy for internal users of the upload-data service to defer the status change broadcast until all processing and state updates are complete. fixes #1802 --- client/js/upload-data.js | 2 ++ client/js/uploader.basic.api.js | 27 ++++++++++++++------------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/client/js/upload-data.js b/client/js/upload-data.js index 3385c5496..d075fd0ef 100644 --- a/client/js/upload-data.js +++ b/client/js/upload-data.js @@ -65,6 +65,7 @@ qq.UploadData = function(uploaderProxy) { * - status: Initial `qq.status` for this file. Omit for `qq.status.SUBMITTING`. * - batchId: ID of the batch this file belongs to * - proxyGroupId: ID of the proxy group associated with this file + * - onBeforeStatusChange(fileId): callback that is executed before the status change is broadcast * * @returns {number} Internal ID for this file. */ @@ -104,6 +105,7 @@ qq.UploadData = function(uploaderProxy) { } byStatus[status].push(id); + spec.onBeforeStatusChange && spec.onBeforeStatusChange(id); uploaderProxy.onStatusChange(id, null, status); return id; diff --git a/client/js/uploader.basic.api.js b/client/js/uploader.basic.api.js index cf507059e..b02f03894 100644 --- a/client/js/uploader.basic.api.js +++ b/client/js/uploader.basic.api.js @@ -442,24 +442,25 @@ qq.basePrivateApi = { // Updates internal state with a file record (not backed by a live file). Returns the assigned ID. _addCannedFile: function(sessionData) { - var id = this._uploadData.addFile({ + var self = this; + + return this._uploadData.addFile({ uuid: sessionData.uuid, name: sessionData.name, size: sessionData.size, - status: qq.status.UPLOAD_SUCCESSFUL - }); - - sessionData.deleteFileEndpoint && this.setDeleteFileEndpoint(sessionData.deleteFileEndpoint, id); - sessionData.deleteFileParams && this.setDeleteFileParams(sessionData.deleteFileParams, id); - - if (sessionData.thumbnailUrl) { - this._thumbnailUrls[id] = sessionData.thumbnailUrl; - } + status: qq.status.UPLOAD_SUCCESSFUL, + onBeforeStatusChange: function(id) { + sessionData.deleteFileEndpoint && self.setDeleteFileEndpoint(sessionData.deleteFileEndpoint, id); + sessionData.deleteFileParams && self.setDeleteFileParams(sessionData.deleteFileParams, id); - this._netUploaded++; - this._netUploadedOrQueued++; + if (sessionData.thumbnailUrl) { + self._thumbnailUrls[id] = sessionData.thumbnailUrl; + } - return id; + self._netUploaded++; + self._netUploadedOrQueued++; + } + }); }, _annotateWithButtonId: function(file, associatedInput) {