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:
parent
e9f00eec23
commit
425fbb84a5
2 changed files with 30 additions and 16 deletions
|
@ -61,6 +61,7 @@ export let FileActions = React.createClass({
|
||||||
path: React.PropTypes.string,
|
path: React.PropTypes.string,
|
||||||
hidden: React.PropTypes.bool,
|
hidden: React.PropTypes.bool,
|
||||||
deleteChecked: React.PropTypes.bool,
|
deleteChecked: React.PropTypes.bool,
|
||||||
|
onRemove: React.PropTypes.function,
|
||||||
},
|
},
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
return {
|
return {
|
||||||
|
@ -137,14 +138,13 @@ export let FileActions = React.createClass({
|
||||||
},
|
},
|
||||||
handleRemoveConfirmed: function() {
|
handleRemoveConfirmed: function() {
|
||||||
if (this.props.streamName) {
|
if (this.props.streamName) {
|
||||||
lbry.deleteFile(this.props.streamName, this.state.deleteChecked);
|
lbry.removeFile(this.props.sdHash, this.props.streamName, this.state.deleteChecked);
|
||||||
} else {
|
} else {
|
||||||
alert('this file cannot be deleted because lbry is a retarded piece of shit');
|
alert('this file cannot be deleted because lbry is a retarded piece of shit');
|
||||||
}
|
}
|
||||||
this.setState({
|
this.setState({
|
||||||
modal: null,
|
modal: null,
|
||||||
fileInfo: false,
|
fileInfo: false,
|
||||||
attemptingRemove: true,
|
|
||||||
attemptingDownload: false
|
attemptingDownload: false
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -169,10 +169,10 @@ export let FileActions = React.createClass({
|
||||||
return <section className="file-actions--stub"></section>;
|
return <section className="file-actions--stub"></section>;
|
||||||
}
|
}
|
||||||
const openInFolderMessage = window.navigator.platform.startsWith('Mac') ? 'Open in Finder' : 'Open in Folder',
|
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;
|
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} />;
|
linkBlock = <Link button="text" label="Download" icon="icon-download" onClick={this.onDownloadClick} />;
|
||||||
} else if (this.state.attemptingDownload || !this.state.fileInfo.completed) {
|
} else if (this.state.attemptingDownload || !this.state.fileInfo.completed) {
|
||||||
const
|
const
|
||||||
|
|
38
js/lbry.js
38
js/lbry.js
|
@ -265,7 +265,10 @@ lbry.stopFile = function(name, callback) {
|
||||||
lbry.call('stop_lbry_file', { name: 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', {
|
lbry.call('delete_lbry_file', {
|
||||||
name: name,
|
name: name,
|
||||||
delete_target_file: deleteTargetFile,
|
delete_target_file: deleteTargetFile,
|
||||||
|
@ -461,6 +464,7 @@ lbry.fileInfo = {};
|
||||||
lbry._fileInfoSubscribeIdCounter = 0;
|
lbry._fileInfoSubscribeIdCounter = 0;
|
||||||
lbry._fileInfoSubscribeCallbacks = {};
|
lbry._fileInfoSubscribeCallbacks = {};
|
||||||
lbry._fileInfoSubscribeInterval = 5000;
|
lbry._fileInfoSubscribeInterval = 5000;
|
||||||
|
lbry._removedFiles = [];
|
||||||
lbry._claimIdOwnershipCache = {}; // should be claimId!!! But not
|
lbry._claimIdOwnershipCache = {}; // should be claimId!!! But not
|
||||||
|
|
||||||
lbry._updateClaimOwnershipCache = function(claimId) {
|
lbry._updateClaimOwnershipCache = function(claimId) {
|
||||||
|
@ -472,20 +476,30 @@ lbry._updateClaimOwnershipCache = function(claimId) {
|
||||||
};
|
};
|
||||||
|
|
||||||
lbry._updateSubscribedFileInfo = function(sdHash) {
|
lbry._updateSubscribedFileInfo = function(sdHash) {
|
||||||
lbry.getFileInfoBySdHash(sdHash, (fileInfo) => {
|
const callSubscribedCallbacks = (sdHash, fileInfo) => {
|
||||||
if (fileInfo) {
|
Object.keys(this._fileInfoSubscribeCallbacks[sdHash]).forEach((subscribeId) => {
|
||||||
if (this._claimIdOwnershipCache[fileInfo.claim_id] === undefined) {
|
this._fileInfoSubscribeCallbacks[sdHash][subscribeId](fileInfo);
|
||||||
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);
|
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
|
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) {
|
if (Object.keys(this._fileInfoSubscribeCallbacks[sdHash]).length) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this._updateSubscribedFileInfo(sdHash)
|
this._updateSubscribedFileInfo(sdHash);
|
||||||
}, lbry._fileInfoSubscribeInterval);
|
}, lbry._fileInfoSubscribeInterval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue