Always refresh claims/file info on downloaded/published pages

This commit is contained in:
6ea86b96 2017-06-15 11:26:26 +07:00
parent 84589f1ebb
commit 1063d2fc9d
6 changed files with 376 additions and 393 deletions

View file

@ -98,16 +98,9 @@ export function doDeleteFile(outpoint, deleteFromComputer) {
export function doFetchFileInfosAndPublishedClaims() { export function doFetchFileInfosAndPublishedClaims() {
return function(dispatch, getState) { return function(dispatch, getState) {
const state = getState(), const state = getState();
isClaimListMinePending = selectClaimListMineIsPending(state),
isFileInfoListPending = selectFileListIsPending(state);
if (isClaimListMinePending === undefined) {
dispatch(doFetchClaimListMine()); dispatch(doFetchClaimListMine());
}
if (isFileInfoListPending === undefined) {
dispatch(doFileList()); dispatch(doFileList());
}
}; };
} }

View file

@ -82,7 +82,7 @@ class FileList extends React.PureComponent {
}); });
return ( return (
<section className="file-list__header"> <section className="file-list__header">
{fetching && <span className="busy-indicator" />} {fetching && <BusyMessage />}
<span className="sort-section"> <span className="sort-section">
{__("Sort by")} {" "} {__("Sort by")} {" "}
<FormField type="select" onChange={this.handleSortChanged.bind(this)}> <FormField type="select" onChange={this.handleSortChanged.bind(this)}>

View file

@ -19,14 +19,14 @@ class FileTile extends React.PureComponent {
} }
componentDidMount() { componentDidMount() {
this.resolve(this.props); const { isResolvingUri, claim, uri, resolveUri } = this.props;
if (!isResolvingUri && !claim && uri) resolveUri(uri);
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
this.resolve(nextProps); const { isResolvingUri, claim, uri, resolveUri } = this.props;
}
resolve({ isResolvingUri, claim, uri, resolveUri }) {
if (!isResolvingUri && claim === undefined && uri) resolveUri(uri); if (!isResolvingUri && claim === undefined && uri) resolveUri(uri);
} }

View file

@ -1,15 +1,15 @@
import lbryio from './lbryio.js'; import lbryio from "./lbryio.js";
import lighthouse from './lighthouse.js'; import lighthouse from "./lighthouse.js";
import jsonrpc from './jsonrpc.js'; import jsonrpc from "./jsonrpc.js";
import lbryuri from './lbryuri.js'; import lbryuri from "./lbryuri.js";
import { getLocal, getSession, setSession, setLocal } from './utils.js'; import { getLocal, getSession, setSession, setLocal } from "./utils.js";
const { remote, ipcRenderer } = require('electron'); const { remote, ipcRenderer } = require("electron");
const menu = remote.require('./menu/main-menu'); const menu = remote.require("./menu/main-menu");
let lbry = { let lbry = {
isConnected: false, isConnected: false,
daemonConnectionString: 'http://localhost:5279/lbryapi', daemonConnectionString: "http://localhost:5279/lbryapi",
pendingPublishTimeout: 20 * 60 * 1000, pendingPublishTimeout: 20 * 60 * 1000,
defaultClientSettings: { defaultClientSettings: {
showNsfw: false, showNsfw: false,
@ -18,8 +18,8 @@ let lbry = {
useCustomLighthouseServers: false, useCustomLighthouseServers: false,
customLighthouseServers: [], customLighthouseServers: [],
showDeveloperMenu: false, showDeveloperMenu: false,
language: 'en' language: "en",
} },
}; };
/** /**
@ -33,17 +33,17 @@ function savePendingPublish({ name, channel_name }) {
} else { } else {
uri = lbryuri.build({ name: name }, false); uri = lbryuri.build({ name: name }, false);
} }
const pendingPublishes = getLocal('pendingPublishes') || []; const pendingPublishes = getLocal("pendingPublishes") || [];
const newPendingPublish = { const newPendingPublish = {
name, name,
channel_name, channel_name,
claim_id: 'pending_claim_' + uri, claim_id: "pending_claim_" + uri,
txid: 'pending_' + uri, txid: "pending_" + uri,
nout: 0, nout: 0,
outpoint: 'pending_' + uri + ':0', outpoint: "pending_" + uri + ":0",
time: Date.now() time: Date.now(),
}; };
setLocal('pendingPublishes', [...pendingPublishes, newPendingPublish]); setLocal("pendingPublishes", [...pendingPublishes, newPendingPublish]);
return newPendingPublish; return newPendingPublish;
} }
@ -61,7 +61,7 @@ function removePendingPublishIfNeeded({ name, channel_name, outpoint }) {
} }
setLocal( setLocal(
'pendingPublishes', "pendingPublishes",
lbry.getPendingPublishes().filter(pub => !pubMatches(pub)) lbry.getPendingPublishes().filter(pub => !pubMatches(pub))
); );
} }
@ -71,11 +71,11 @@ function removePendingPublishIfNeeded({ name, channel_name, outpoint }) {
* removes them from the list. * removes them from the list.
*/ */
lbry.getPendingPublishes = function() { lbry.getPendingPublishes = function() {
const pendingPublishes = getLocal('pendingPublishes') || []; const pendingPublishes = getLocal("pendingPublishes") || [];
const newPendingPublishes = pendingPublishes.filter( const newPendingPublishes = pendingPublishes.filter(
pub => Date.now() - pub.time <= lbry.pendingPublishTimeout pub => Date.now() - pub.time <= lbry.pendingPublishTimeout
); );
setLocal('pendingPublishes', newPendingPublishes); setLocal("pendingPublishes", newPendingPublishes);
return newPendingPublishes; return newPendingPublishes;
}; };
@ -101,7 +101,7 @@ function pendingPublishToDummyClaim({
outpoint, outpoint,
claim_id, claim_id,
txid, txid,
nout nout,
}) { }) {
return { name, outpoint, claim_id, txid, nout, channel_name }; return { name, outpoint, claim_id, txid, nout, channel_name };
} }
@ -142,14 +142,14 @@ lbry.connect = function() {
checkDaemonStarted(); checkDaemonStarted();
}, tryNum < 50 ? 400 : 1000); }, tryNum < 50 ? 400 : 1000);
} else { } else {
reject(new Error('Unable to connect to LBRY')); reject(new Error("Unable to connect to LBRY"));
} }
} }
// Check every half second to see if the daemon is accepting connections // Check every half second to see if the daemon is accepting connections
function checkDaemonStarted() { function checkDaemonStarted() {
lbry.call( lbry.call(
'status', "status",
{}, {},
resolve, resolve,
checkDaemonStartedFailed, checkDaemonStartedFailed,
@ -165,12 +165,12 @@ lbry.connect = function() {
}; };
lbry.checkAddressIsMine = function(address, callback) { lbry.checkAddressIsMine = function(address, callback) {
lbry.call('wallet_is_address_mine', { address: address }, callback); lbry.call("wallet_is_address_mine", { address: address }, callback);
}; };
lbry.sendToAddress = function(amount, address, callback, errorCallback) { lbry.sendToAddress = function(amount, address, callback, errorCallback) {
lbry.call( lbry.call(
'send_amount_to_address', "send_amount_to_address",
{ amount: amount, address: address }, { amount: amount, address: address },
callback, callback,
errorCallback errorCallback
@ -191,7 +191,7 @@ lbry.costPromiseCache = {};
lbry.getCostInfo = function(uri) { lbry.getCostInfo = function(uri) {
if (lbry.costPromiseCache[uri] === undefined) { if (lbry.costPromiseCache[uri] === undefined) {
lbry.costPromiseCache[uri] = new Promise((resolve, reject) => { lbry.costPromiseCache[uri] = new Promise((resolve, reject) => {
const COST_INFO_CACHE_KEY = 'cost_info_cache'; const COST_INFO_CACHE_KEY = "cost_info_cache";
let costInfoCache = getSession(COST_INFO_CACHE_KEY, {}); let costInfoCache = getSession(COST_INFO_CACHE_KEY, {});
function cacheAndResolve(cost, includesData) { function cacheAndResolve(cost, includesData) {
@ -245,7 +245,7 @@ lbry.publish = function(
errorCallback errorCallback
) { ) {
lbry.call( lbry.call(
'publish', "publish",
params, params,
result => { result => {
if (returnedPending) { if (returnedPending) {
@ -273,7 +273,7 @@ lbry.publish = function(
if (publishedCallback) { if (publishedCallback) {
savePendingPublish({ savePendingPublish({
name: params.name, name: params.name,
channel_name: params.channel_name channel_name: params.channel_name,
}); });
publishedCallback(true); publishedCallback(true);
} }
@ -282,7 +282,7 @@ lbry.publish = function(
const { name, channel_name } = params; const { name, channel_name } = params;
savePendingPublish({ savePendingPublish({
name: params.name, name: params.name,
channel_name: params.channel_name channel_name: params.channel_name,
}); });
fileListedCallback(true); fileListedCallback(true);
} }
@ -292,7 +292,7 @@ lbry.publish = function(
lbry.getClientSettings = function() { lbry.getClientSettings = function() {
var outSettings = {}; var outSettings = {};
for (let setting of Object.keys(lbry.defaultClientSettings)) { for (let setting of Object.keys(lbry.defaultClientSettings)) {
var localStorageVal = localStorage.getItem('setting_' + setting); var localStorageVal = localStorage.getItem("setting_" + setting);
outSettings[setting] = localStorageVal === null outSettings[setting] = localStorageVal === null
? lbry.defaultClientSettings[setting] ? lbry.defaultClientSettings[setting]
: JSON.parse(localStorageVal); : JSON.parse(localStorageVal);
@ -301,8 +301,8 @@ lbry.getClientSettings = function() {
}; };
lbry.getClientSetting = function(setting) { lbry.getClientSetting = function(setting) {
var localStorageVal = localStorage.getItem('setting_' + setting); var localStorageVal = localStorage.getItem("setting_" + setting);
if (setting == 'showDeveloperMenu') { if (setting == "showDeveloperMenu") {
return true; return true;
} }
return localStorageVal === null return localStorageVal === null
@ -317,18 +317,18 @@ lbry.setClientSettings = function(settings) {
}; };
lbry.setClientSetting = function(setting, value) { lbry.setClientSetting = function(setting, value) {
return localStorage.setItem('setting_' + setting, JSON.stringify(value)); return localStorage.setItem("setting_" + setting, JSON.stringify(value));
}; };
lbry.getSessionInfo = function(callback) { lbry.getSessionInfo = function(callback) {
lbry.call('status', { session_status: true }, callback); lbry.call("status", { session_status: true }, callback);
}; };
lbry.reportBug = function(message, callback) { lbry.reportBug = function(message, callback) {
lbry.call( lbry.call(
'report_bug', "report_bug",
{ {
message: message message: message,
}, },
callback callback
); );
@ -336,46 +336,46 @@ lbry.reportBug = function(message, callback) {
//utilities //utilities
lbry.formatCredits = function(amount, precision) { lbry.formatCredits = function(amount, precision) {
return amount.toFixed(precision || 1).replace(/\.?0+$/, ''); return amount.toFixed(precision || 1).replace(/\.?0+$/, "");
}; };
lbry.formatName = function(name) { lbry.formatName = function(name) {
// Converts LBRY name to standard format (all lower case, no special characters, spaces replaced by dashes) // Converts LBRY name to standard format (all lower case, no special characters, spaces replaced by dashes)
name = name.replace('/s+/g', '-'); name = name.replace("/s+/g", "-");
name = name.toLowerCase().replace(/[^a-z0-9\-]/g, ''); name = name.toLowerCase().replace(/[^a-z0-9\-]/g, "");
return name; return name;
}; };
lbry.imagePath = function(file) { lbry.imagePath = function(file) {
return 'img/' + file; return "img/" + file;
}; };
lbry.getMediaType = function(contentType, fileName) { lbry.getMediaType = function(contentType, fileName) {
if (contentType) { if (contentType) {
return /^[^/]+/.exec(contentType)[0]; return /^[^/]+/.exec(contentType)[0];
} else if (fileName) { } else if (fileName) {
var dotIndex = fileName.lastIndexOf('.'); var dotIndex = fileName.lastIndexOf(".");
if (dotIndex == -1) { if (dotIndex == -1) {
return 'unknown'; return "unknown";
} }
var ext = fileName.substr(dotIndex + 1); var ext = fileName.substr(dotIndex + 1);
if (/^mp4|mov|m4v|flv|f4v$/i.test(ext)) { if (/^mp4|mov|m4v|flv|f4v$/i.test(ext)) {
return 'video'; return "video";
} else if (/^mp3|m4a|aac|wav|flac|ogg$/i.test(ext)) { } else if (/^mp3|m4a|aac|wav|flac|ogg$/i.test(ext)) {
return 'audio'; return "audio";
} else if (/^html|htm|pdf|odf|doc|docx|md|markdown|txt$/i.test(ext)) { } else if (/^html|htm|pdf|odf|doc|docx|md|markdown|txt$/i.test(ext)) {
return 'document'; return "document";
} else { } else {
return 'unknown'; return "unknown";
} }
} else { } else {
return 'unknown'; return "unknown";
} }
}; };
lbry.stop = function(callback) { lbry.stop = function(callback) {
lbry.call('stop', {}, callback); lbry.call("stop", {}, callback);
}; };
lbry._subscribeIdCount = 0; lbry._subscribeIdCount = 0;
@ -418,22 +418,22 @@ lbry.balanceUnsubscribe = function(subscribeId) {
}; };
lbry.showMenuIfNeeded = function() { lbry.showMenuIfNeeded = function() {
const showingMenu = sessionStorage.getItem('menuShown') || null; const showingMenu = sessionStorage.getItem("menuShown") || null;
const chosenMenu = lbry.getClientSetting('showDeveloperMenu') const chosenMenu = lbry.getClientSetting("showDeveloperMenu")
? 'developer' ? "developer"
: 'normal'; : "normal";
if (chosenMenu != showingMenu) { if (chosenMenu != showingMenu) {
menu.showMenubar(chosenMenu == 'developer'); menu.showMenubar(chosenMenu == "developer");
} }
sessionStorage.setItem('menuShown', chosenMenu); sessionStorage.setItem("menuShown", chosenMenu);
}; };
lbry.getAppVersionInfo = function() { lbry.getAppVersionInfo = function() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
ipcRenderer.once('version-info-received', (event, versionInfo) => { ipcRenderer.once("version-info-received", (event, versionInfo) => {
resolve(versionInfo); resolve(versionInfo);
}); });
ipcRenderer.send('version-info-requested'); ipcRenderer.send("version-info-requested");
}); });
}; };
@ -464,7 +464,7 @@ lbry.file_list = function(params = {}) {
} }
lbry.call( lbry.call(
'file_list', "file_list",
params, params,
fileInfos => { fileInfos => {
removePendingPublishIfNeeded({ name, channel_name, outpoint }); removePendingPublishIfNeeded({ name, channel_name, outpoint });
@ -483,14 +483,14 @@ lbry.file_list = function(params = {}) {
lbry.claim_list_mine = function(params = {}) { lbry.claim_list_mine = function(params = {}) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
lbry.call( lbry.call(
'claim_list_mine', "claim_list_mine",
params, params,
claims => { claims => {
for (let { name, channel_name, txid, nout } of claims) { for (let { name, channel_name, txid, nout } of claims) {
removePendingPublishIfNeeded({ removePendingPublishIfNeeded({
name, name,
channel_name, channel_name,
outpoint: txid + ':' + nout outpoint: txid + ":" + nout,
}); });
} }
@ -505,30 +505,20 @@ lbry.claim_list_mine = function(params = {}) {
}); });
}; };
const claimCacheKey = 'resolve_claim_cache';
lbry._claimCache = getSession(claimCacheKey, {});
lbry._resolveXhrs = {}; lbry._resolveXhrs = {};
lbry.resolve = function(params = {}) { lbry.resolve = function(params = {}) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (!params.uri) { if (!params.uri) {
throw __('Resolve has hacked cache on top of it that requires a URI'); throw __("Resolve has hacked cache on top of it that requires a URI");
} }
if (params.uri && lbry._claimCache[params.uri] !== undefined) {
resolve(lbry._claimCache[params.uri]);
} else {
lbry._resolveXhrs[params.uri] = lbry.call( lbry._resolveXhrs[params.uri] = lbry.call(
'resolve', "resolve",
params, params,
function(data) { function(data) {
if (data !== undefined) {
lbry._claimCache[params.uri] = data;
}
setSession(claimCacheKey, lbry._claimCache);
resolve(data); resolve(data);
}, },
reject reject
); );
}
}); });
}; };
@ -557,7 +547,7 @@ lbry = new Proxy(lbry, {
); );
}); });
}; };
} },
}); });
export default lbry; export default lbry;

View file

@ -12,7 +12,7 @@ import SubHeader from "component/subHeader";
class FileListDownloaded extends React.PureComponent { class FileListDownloaded extends React.PureComponent {
componentWillMount() { componentWillMount() {
this.props.fetchFileInfosDownloaded(); if (!this.props.isPending) this.props.fetchFileInfosDownloaded();
} }
render() { render() {

View file

@ -12,7 +12,7 @@ import SubHeader from "component/subHeader";
class FileListPublished extends React.PureComponent { class FileListPublished extends React.PureComponent {
componentWillMount() { componentWillMount() {
this.props.fetchFileListPublished(); if (!this.props.isPending) this.props.fetchFileListPublished();
} }
componentDidUpdate() { componentDidUpdate() {