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.
This commit is contained in:
Alex Liebowitz 2017-01-17 04:04:29 -05:00
parent e9f00eec23
commit 425fbb84a5
2 changed files with 30 additions and 16 deletions

View file

@ -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 <section className="file-actions--stub"></section>;
}
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 = <Link button="text" label="Download" icon="icon-download" onClick={this.onDownloadClick} />;
} else if (this.state.attemptingDownload || !this.state.fileInfo.completed) {
const

View file

@ -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);
}
}