From 425fbb84a5523a8ebbb17ee798c4ba1b9ece3649 Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Tue, 17 Jan 2017 04:04:29 -0500 Subject: [PATCH] Fix delay in files disappearing from My Files We now maintain a list of files that have been requested for removal in lbry.js and simulate the file being removed so all components can respond immediately. --- js/component/file-actions.js | 8 ++++---- js/lbry.js | 38 ++++++++++++++++++++++++------------ 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/js/component/file-actions.js b/js/component/file-actions.js index e793e8f1f..cdb4044b7 100644 --- a/js/component/file-actions.js +++ b/js/component/file-actions.js @@ -61,6 +61,7 @@ export let FileActions = React.createClass({ path: React.PropTypes.string, hidden: React.PropTypes.bool, deleteChecked: React.PropTypes.bool, + onRemove: React.PropTypes.function, }, getInitialState: function() { return { @@ -137,14 +138,13 @@ export let FileActions = React.createClass({ }, handleRemoveConfirmed: function() { if (this.props.streamName) { - lbry.deleteFile(this.props.streamName, this.state.deleteChecked); + lbry.removeFile(this.props.sdHash, this.props.streamName, this.state.deleteChecked); } else { alert('this file cannot be deleted because lbry is a retarded piece of shit'); } this.setState({ modal: null, fileInfo: false, - attemptingRemove: true, attemptingDownload: false }); }, @@ -169,10 +169,10 @@ export let FileActions = React.createClass({ return
; } const openInFolderMessage = window.navigator.platform.startsWith('Mac') ? 'Open in Finder' : 'Open in Folder', - showMenu = !this.state.attemptingRemove && this.state.fileInfo !== null; + showMenu = !!this.state.fileInfo; let linkBlock; - if (this.state.attemptingRemove || (this.state.fileInfo === false && !this.state.attemptingDownload)) { + if (this.state.fileInfo === false && !this.state.attemptingDownload) { linkBlock = ; } else if (this.state.attemptingDownload || !this.state.fileInfo.completed) { const diff --git a/js/lbry.js b/js/lbry.js index d264b1a31..38df0564e 100644 --- a/js/lbry.js +++ b/js/lbry.js @@ -265,7 +265,10 @@ lbry.stopFile = function(name, callback) { lbry.call('stop_lbry_file', { name: name }, callback); } -lbry.deleteFile = function(name, deleteTargetFile=true, callback) { +lbry.removeFile = function(sdHash, name, deleteTargetFile=true, callback) { // Name param is temporary until the API can delete by unique ID (SD hash, claim ID etc.) + this._removedFiles.push(sdHash); + this._updateSubscribedFileInfo(sdHash); + lbry.call('delete_lbry_file', { name: name, delete_target_file: deleteTargetFile, @@ -461,6 +464,7 @@ lbry.fileInfo = {}; lbry._fileInfoSubscribeIdCounter = 0; lbry._fileInfoSubscribeCallbacks = {}; lbry._fileInfoSubscribeInterval = 5000; +lbry._removedFiles = []; lbry._claimIdOwnershipCache = {}; // should be claimId!!! But not lbry._updateClaimOwnershipCache = function(claimId) { @@ -472,20 +476,30 @@ lbry._updateClaimOwnershipCache = function(claimId) { }; lbry._updateSubscribedFileInfo = function(sdHash) { - lbry.getFileInfoBySdHash(sdHash, (fileInfo) => { - if (fileInfo) { - if (this._claimIdOwnershipCache[fileInfo.claim_id] === undefined) { - lbry._updateClaimOwnershipCache(fileInfo.claim_id); - } - fileInfo.isMine = !!this._claimIdOwnershipCache[fileInfo.claim_id]; - } - Object.keys(this._fileInfoSubscribeCallbacks[sdHash]).forEach(function(subscribeId) { - lbry._fileInfoSubscribeCallbacks[sdHash][subscribeId](fileInfo); + const callSubscribedCallbacks = (sdHash, fileInfo) => { + Object.keys(this._fileInfoSubscribeCallbacks[sdHash]).forEach((subscribeId) => { + this._fileInfoSubscribeCallbacks[sdHash][subscribeId](fileInfo); }); - }); + } + + if (lbry._removedFiles.includes(sdHash)) { + callSubscribedCallbacks(sdHash, false); + } else { + lbry.getFileInfoBySdHash(sdHash, (fileInfo) => { + if (fileInfo) { + if (this._claimIdOwnershipCache[fileInfo.claim_id] === undefined) { + this._updateClaimOwnershipCache(fileInfo.claim_id); + } + fileInfo.isMine = !!this._claimIdOwnershipCache[fileInfo.claim_id]; + } + + callSubscribedCallbacks(sdHash, fileInfo); + }); + } + if (Object.keys(this._fileInfoSubscribeCallbacks[sdHash]).length) { setTimeout(() => { - this._updateSubscribedFileInfo(sdHash) + this._updateSubscribedFileInfo(sdHash); }, lbry._fileInfoSubscribeInterval); } }