Merge pull request #310 from lbryio/feat-trackReflectingFiles
track reflecting files
This commit is contained in:
commit
7bb6bb7ea2
10 changed files with 289 additions and 9 deletions
133
dist/bundle.es.js
vendored
133
dist/bundle.es.js
vendored
|
@ -145,6 +145,10 @@ const CHECK_PUBLISH_NAME_STARTED = 'CHECK_PUBLISH_NAME_STARTED';
|
||||||
const CHECK_PUBLISH_NAME_COMPLETED = 'CHECK_PUBLISH_NAME_COMPLETED';
|
const CHECK_PUBLISH_NAME_COMPLETED = 'CHECK_PUBLISH_NAME_COMPLETED';
|
||||||
const UPDATE_PENDING_CLAIMS = 'UPDATE_PENDING_CLAIMS';
|
const UPDATE_PENDING_CLAIMS = 'UPDATE_PENDING_CLAIMS';
|
||||||
const UPDATE_CONFIRMED_CLAIMS = 'UPDATE_CONFIRMED_CLAIMS';
|
const UPDATE_CONFIRMED_CLAIMS = 'UPDATE_CONFIRMED_CLAIMS';
|
||||||
|
const ADD_FILES_REFLECTING = 'ADD_FILES_REFLECTING';
|
||||||
|
const UPDATE_FILES_REFLECTING = 'UPDATE_FILES_REFLECTING';
|
||||||
|
const TOGGLE_CHECKING_REFLECTING = 'TOGGLE_CHECKING_REFLECTING';
|
||||||
|
const TOGGLE_CHECKING_PENDING = 'TOGGLE_CHECKING_PENDING';
|
||||||
|
|
||||||
// Comments
|
// Comments
|
||||||
const COMMENT_LIST_STARTED = 'COMMENT_LIST_STARTED';
|
const COMMENT_LIST_STARTED = 'COMMENT_LIST_STARTED';
|
||||||
|
@ -421,6 +425,10 @@ var action_types = /*#__PURE__*/Object.freeze({
|
||||||
CHECK_PUBLISH_NAME_COMPLETED: CHECK_PUBLISH_NAME_COMPLETED,
|
CHECK_PUBLISH_NAME_COMPLETED: CHECK_PUBLISH_NAME_COMPLETED,
|
||||||
UPDATE_PENDING_CLAIMS: UPDATE_PENDING_CLAIMS,
|
UPDATE_PENDING_CLAIMS: UPDATE_PENDING_CLAIMS,
|
||||||
UPDATE_CONFIRMED_CLAIMS: UPDATE_CONFIRMED_CLAIMS,
|
UPDATE_CONFIRMED_CLAIMS: UPDATE_CONFIRMED_CLAIMS,
|
||||||
|
ADD_FILES_REFLECTING: ADD_FILES_REFLECTING,
|
||||||
|
UPDATE_FILES_REFLECTING: UPDATE_FILES_REFLECTING,
|
||||||
|
TOGGLE_CHECKING_REFLECTING: TOGGLE_CHECKING_REFLECTING,
|
||||||
|
TOGGLE_CHECKING_PENDING: TOGGLE_CHECKING_PENDING,
|
||||||
COMMENT_LIST_STARTED: COMMENT_LIST_STARTED,
|
COMMENT_LIST_STARTED: COMMENT_LIST_STARTED,
|
||||||
COMMENT_LIST_COMPLETED: COMMENT_LIST_COMPLETED,
|
COMMENT_LIST_COMPLETED: COMMENT_LIST_COMPLETED,
|
||||||
COMMENT_LIST_FAILED: COMMENT_LIST_FAILED,
|
COMMENT_LIST_FAILED: COMMENT_LIST_FAILED,
|
||||||
|
@ -2184,6 +2192,7 @@ const makeSelectPendingByUri = uri => reselect.createSelector(selectPendingById,
|
||||||
const claimId = isChannel ? channelClaimId : streamClaimId;
|
const claimId = isChannel ? channelClaimId : streamClaimId;
|
||||||
return pendingById[claimId];
|
return pendingById[claimId];
|
||||||
});
|
});
|
||||||
|
const selectReflectingById = reselect.createSelector(selectState$2, state => state.reflectingById);
|
||||||
|
|
||||||
const makeSelectClaimForUri = (uri, returnRepost = true) => reselect.createSelector(selectClaimsByUri, selectPendingById, (byUri, pendingById) => {
|
const makeSelectClaimForUri = (uri, returnRepost = true) => reselect.createSelector(selectClaimsByUri, selectPendingById, (byUri, pendingById) => {
|
||||||
// Check if a claim is pending first
|
// Check if a claim is pending first
|
||||||
|
@ -2546,6 +2555,11 @@ const selectUpdatingChannel = reselect.createSelector(selectState$2, state => st
|
||||||
|
|
||||||
const selectUpdateChannelError = reselect.createSelector(selectState$2, state => state.updateChannelError);
|
const selectUpdateChannelError = reselect.createSelector(selectState$2, state => state.updateChannelError);
|
||||||
|
|
||||||
|
const makeSelectReflectingClaimForUri = uri => reselect.createSelector(makeSelectClaimForUri(uri), selectReflectingById, (claim, reflectingById) => {
|
||||||
|
const claimId = claim && claim.claimId;
|
||||||
|
return reflectingById[claimId];
|
||||||
|
});
|
||||||
|
|
||||||
const makeSelectMyStreamUrlsForPage = (page = 1) => reselect.createSelector(selectMyClaimUrisWithoutChannels, urls => {
|
const makeSelectMyStreamUrlsForPage = (page = 1) => reselect.createSelector(selectMyClaimUrisWithoutChannels, urls => {
|
||||||
const start = (Number(page) - 1) * Number(PAGE_SIZE);
|
const start = (Number(page) - 1) * Number(PAGE_SIZE);
|
||||||
const end = Number(page) * Number(PAGE_SIZE);
|
const end = Number(page) * Number(PAGE_SIZE);
|
||||||
|
@ -4114,6 +4128,8 @@ const selectTakeOverAmount = reselect.createSelector(selectState$5, selectMyClai
|
||||||
|
|
||||||
var _extends$7 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
var _extends$7 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
||||||
|
|
||||||
|
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
|
||||||
|
|
||||||
const doResetThumbnailStatus = () => dispatch => {
|
const doResetThumbnailStatus = () => dispatch => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: UPDATE_PUBLISH_FORM,
|
type: UPDATE_PUBLISH_FORM,
|
||||||
|
@ -4400,7 +4416,82 @@ const doPublish = (success, fail) => (dispatch, getState) => {
|
||||||
return lbryProxy.publish(publishPayload).then(success, fail);
|
return lbryProxy.publish(publishPayload).then(success, fail);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Calls claim_list_mine until any pending publishes are confirmed
|
// Calls file_list until any reflecting files are done
|
||||||
|
const doCheckReflectingFiles = () => (dispatch, getState) => {
|
||||||
|
const state = getState();
|
||||||
|
const { checkingReflector } = state.claims;
|
||||||
|
let reflectorCheckInterval;
|
||||||
|
|
||||||
|
const checkFileList = (() => {
|
||||||
|
var _ref = _asyncToGenerator(function* () {
|
||||||
|
const state = getState();
|
||||||
|
const reflectingById = selectReflectingById(state);
|
||||||
|
const ids = Object.keys(reflectingById);
|
||||||
|
|
||||||
|
const newReflectingById = {};
|
||||||
|
const promises = [];
|
||||||
|
// TODO: just use file_list({claim_id: Array<claimId>})
|
||||||
|
if (Object.keys(reflectingById).length) {
|
||||||
|
ids.forEach(function (claimId) {
|
||||||
|
promises.push(lbryProxy.file_list({ claim_id: claimId }));
|
||||||
|
});
|
||||||
|
|
||||||
|
Promise.all(promises).then(function (results) {
|
||||||
|
results.forEach(function (res) {
|
||||||
|
const fileListItem = res.items[0];
|
||||||
|
const fileClaimId = fileListItem.claim_id;
|
||||||
|
const {
|
||||||
|
is_fully_reflected: done,
|
||||||
|
uploading_to_reflector: uploading,
|
||||||
|
reflector_progress: progress
|
||||||
|
} = fileListItem;
|
||||||
|
if (uploading) {
|
||||||
|
newReflectingById[fileClaimId] = {
|
||||||
|
fileListItem: fileListItem,
|
||||||
|
progress,
|
||||||
|
stalled: !done && !uploading
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}).then(function () {
|
||||||
|
dispatch({
|
||||||
|
type: UPDATE_FILES_REFLECTING,
|
||||||
|
data: newReflectingById
|
||||||
|
});
|
||||||
|
if (!Object.keys(newReflectingById).length) {
|
||||||
|
dispatch({
|
||||||
|
type: TOGGLE_CHECKING_REFLECTING,
|
||||||
|
data: false
|
||||||
|
});
|
||||||
|
clearInterval(reflectorCheckInterval);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
dispatch({
|
||||||
|
type: TOGGLE_CHECKING_REFLECTING,
|
||||||
|
data: false
|
||||||
|
});
|
||||||
|
clearInterval(reflectorCheckInterval);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return function checkFileList() {
|
||||||
|
return _ref.apply(this, arguments);
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
// do it once...
|
||||||
|
checkFileList();
|
||||||
|
// then start the interval if it's not already started
|
||||||
|
if (!checkingReflector) {
|
||||||
|
dispatch({
|
||||||
|
type: TOGGLE_CHECKING_REFLECTING,
|
||||||
|
data: true
|
||||||
|
});
|
||||||
|
reflectorCheckInterval = setInterval(() => {
|
||||||
|
checkFileList();
|
||||||
|
}, 5000);
|
||||||
|
}
|
||||||
|
};
|
||||||
const doCheckPendingPublishes = onConfirmed => (dispatch, getState) => {
|
const doCheckPendingPublishes = onConfirmed => (dispatch, getState) => {
|
||||||
let publishCheckInterval;
|
let publishCheckInterval;
|
||||||
|
|
||||||
|
@ -4940,6 +5031,7 @@ const defaultState = {
|
||||||
fetchingMyChannels: false,
|
fetchingMyChannels: false,
|
||||||
abandoningById: {},
|
abandoningById: {},
|
||||||
pendingById: {},
|
pendingById: {},
|
||||||
|
reflectingById: {},
|
||||||
claimSearchError: false,
|
claimSearchError: false,
|
||||||
claimSearchByQuery: {},
|
claimSearchByQuery: {},
|
||||||
claimSearchByQueryLastPageReached: {},
|
claimSearchByQueryLastPageReached: {},
|
||||||
|
@ -4956,7 +5048,9 @@ const defaultState = {
|
||||||
myClaimsPageNumber: undefined,
|
myClaimsPageNumber: undefined,
|
||||||
myClaimsPageTotalResults: undefined,
|
myClaimsPageTotalResults: undefined,
|
||||||
isFetchingClaimListMine: false,
|
isFetchingClaimListMine: false,
|
||||||
isCheckingNameForPublish: false
|
isCheckingNameForPublish: false,
|
||||||
|
checkingPending: false,
|
||||||
|
checkingReflecting: false
|
||||||
};
|
};
|
||||||
|
|
||||||
function handleClaimAction(state, action) {
|
function handleClaimAction(state, action) {
|
||||||
|
@ -5438,6 +5532,38 @@ reducers[CLEAR_REPOST_ERROR] = state => {
|
||||||
repostError: null
|
repostError: null
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
reducers[ADD_FILES_REFLECTING] = (state, action) => {
|
||||||
|
const pendingClaim = action.data;
|
||||||
|
const { reflectingById } = state;
|
||||||
|
const claimId = pendingClaim && pendingClaim.claim_id;
|
||||||
|
|
||||||
|
reflectingById[claimId] = { fileListItem: pendingClaim, progress: 0, stalled: false };
|
||||||
|
|
||||||
|
return Object.assign({}, state, _extends$9({}, state, {
|
||||||
|
reflectingById: reflectingById
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
reducers[UPDATE_FILES_REFLECTING] = (state, action) => {
|
||||||
|
const newReflectingById = action.data;
|
||||||
|
|
||||||
|
return Object.assign({}, state, _extends$9({}, state, {
|
||||||
|
reflectingById: newReflectingById
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
reducers[TOGGLE_CHECKING_REFLECTING] = (state, action) => {
|
||||||
|
const checkingReflecting = action.data;
|
||||||
|
|
||||||
|
return Object.assign({}, state, _extends$9({}, state, {
|
||||||
|
checkingReflecting
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
reducers[TOGGLE_CHECKING_PENDING] = (state, action) => {
|
||||||
|
const checking = action.data;
|
||||||
|
|
||||||
|
return Object.assign({}, state, _extends$9({}, state, {
|
||||||
|
checkingPending: checking
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
function claimsReducer(state = defaultState, action) {
|
function claimsReducer(state = defaultState, action) {
|
||||||
const handler = reducers[action.type];
|
const handler = reducers[action.type];
|
||||||
|
@ -6715,6 +6841,7 @@ exports.doBlurSearchInput = doBlurSearchInput;
|
||||||
exports.doCheckAddressIsMine = doCheckAddressIsMine;
|
exports.doCheckAddressIsMine = doCheckAddressIsMine;
|
||||||
exports.doCheckPendingPublishes = doCheckPendingPublishes;
|
exports.doCheckPendingPublishes = doCheckPendingPublishes;
|
||||||
exports.doCheckPublishNameAvailability = doCheckPublishNameAvailability;
|
exports.doCheckPublishNameAvailability = doCheckPublishNameAvailability;
|
||||||
|
exports.doCheckReflectingFiles = doCheckReflectingFiles;
|
||||||
exports.doClaimSearch = doClaimSearch;
|
exports.doClaimSearch = doClaimSearch;
|
||||||
exports.doClearPublish = doClearPublish;
|
exports.doClearPublish = doClearPublish;
|
||||||
exports.doClearRepostError = doClearRepostError;
|
exports.doClearRepostError = doClearRepostError;
|
||||||
|
@ -6824,6 +6951,7 @@ exports.makeSelectPermanentUrlForUri = makeSelectPermanentUrlForUri;
|
||||||
exports.makeSelectPublishFormValue = makeSelectPublishFormValue;
|
exports.makeSelectPublishFormValue = makeSelectPublishFormValue;
|
||||||
exports.makeSelectQueryWithOptions = makeSelectQueryWithOptions;
|
exports.makeSelectQueryWithOptions = makeSelectQueryWithOptions;
|
||||||
exports.makeSelectRecommendedContentForUri = makeSelectRecommendedContentForUri;
|
exports.makeSelectRecommendedContentForUri = makeSelectRecommendedContentForUri;
|
||||||
|
exports.makeSelectReflectingClaimForUri = makeSelectReflectingClaimForUri;
|
||||||
exports.makeSelectResolvedRecommendedContentForUri = makeSelectResolvedRecommendedContentForUri;
|
exports.makeSelectResolvedRecommendedContentForUri = makeSelectResolvedRecommendedContentForUri;
|
||||||
exports.makeSelectResolvedSearchResults = makeSelectResolvedSearchResults;
|
exports.makeSelectResolvedSearchResults = makeSelectResolvedSearchResults;
|
||||||
exports.makeSelectResolvedSearchResultsLastPageReached = makeSelectResolvedSearchResultsLastPageReached;
|
exports.makeSelectResolvedSearchResultsLastPageReached = makeSelectResolvedSearchResultsLastPageReached;
|
||||||
|
@ -6928,6 +7056,7 @@ exports.selectPurchaseUriErrorMessage = selectPurchaseUriErrorMessage;
|
||||||
exports.selectPurchasedUris = selectPurchasedUris;
|
exports.selectPurchasedUris = selectPurchasedUris;
|
||||||
exports.selectReceiveAddress = selectReceiveAddress;
|
exports.selectReceiveAddress = selectReceiveAddress;
|
||||||
exports.selectRecentTransactions = selectRecentTransactions;
|
exports.selectRecentTransactions = selectRecentTransactions;
|
||||||
|
exports.selectReflectingById = selectReflectingById;
|
||||||
exports.selectRepostError = selectRepostError;
|
exports.selectRepostError = selectRepostError;
|
||||||
exports.selectRepostLoading = selectRepostLoading;
|
exports.selectRepostLoading = selectRepostLoading;
|
||||||
exports.selectReservedBalance = selectReservedBalance;
|
exports.selectReservedBalance = selectReservedBalance;
|
||||||
|
|
3
dist/flow-typed/File.js
vendored
3
dist/flow-typed/File.js
vendored
|
@ -20,6 +20,7 @@ declare type FileListItem = {
|
||||||
outpoint: string,
|
outpoint: string,
|
||||||
points_paid: number,
|
points_paid: number,
|
||||||
protobuf: string,
|
protobuf: string,
|
||||||
|
reflector_progress: number,
|
||||||
sd_hash: string,
|
sd_hash: string,
|
||||||
status: string,
|
status: string,
|
||||||
stopped: false,
|
stopped: false,
|
||||||
|
@ -29,10 +30,12 @@ declare type FileListItem = {
|
||||||
suggested_file_name: string,
|
suggested_file_name: string,
|
||||||
total_bytes: number,
|
total_bytes: number,
|
||||||
total_bytes_lower_bound: number,
|
total_bytes_lower_bound: number,
|
||||||
|
is_fully_reflected: boolean,
|
||||||
// TODO: sdk plans to change `tx`
|
// TODO: sdk plans to change `tx`
|
||||||
// It isn't currently used by the apps
|
// It isn't currently used by the apps
|
||||||
tx: {},
|
tx: {},
|
||||||
txid: string,
|
txid: string,
|
||||||
|
uploading_to_reflector: boolean,
|
||||||
written_bytes: number,
|
written_bytes: number,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
5
dist/flow-typed/Reflector.js
vendored
Normal file
5
dist/flow-typed/Reflector.js
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
declare type ReflectingUpdate = {
|
||||||
|
fileListItem: FileListItem,
|
||||||
|
progress: number | boolean,
|
||||||
|
stalled: boolean,
|
||||||
|
};
|
3
flow-typed/File.js
vendored
3
flow-typed/File.js
vendored
|
@ -20,6 +20,7 @@ declare type FileListItem = {
|
||||||
outpoint: string,
|
outpoint: string,
|
||||||
points_paid: number,
|
points_paid: number,
|
||||||
protobuf: string,
|
protobuf: string,
|
||||||
|
reflector_progress: number,
|
||||||
sd_hash: string,
|
sd_hash: string,
|
||||||
status: string,
|
status: string,
|
||||||
stopped: false,
|
stopped: false,
|
||||||
|
@ -29,10 +30,12 @@ declare type FileListItem = {
|
||||||
suggested_file_name: string,
|
suggested_file_name: string,
|
||||||
total_bytes: number,
|
total_bytes: number,
|
||||||
total_bytes_lower_bound: number,
|
total_bytes_lower_bound: number,
|
||||||
|
is_fully_reflected: boolean,
|
||||||
// TODO: sdk plans to change `tx`
|
// TODO: sdk plans to change `tx`
|
||||||
// It isn't currently used by the apps
|
// It isn't currently used by the apps
|
||||||
tx: {},
|
tx: {},
|
||||||
txid: string,
|
txid: string,
|
||||||
|
uploading_to_reflector: boolean,
|
||||||
written_bytes: number,
|
written_bytes: number,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
5
flow-typed/Reflector.js
vendored
Normal file
5
flow-typed/Reflector.js
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
declare type ReflectingUpdate = {
|
||||||
|
fileListItem: FileListItem,
|
||||||
|
progress: number | boolean,
|
||||||
|
stalled: boolean,
|
||||||
|
};
|
|
@ -122,6 +122,10 @@ export const CHECK_PUBLISH_NAME_STARTED = 'CHECK_PUBLISH_NAME_STARTED';
|
||||||
export const CHECK_PUBLISH_NAME_COMPLETED = 'CHECK_PUBLISH_NAME_COMPLETED';
|
export const CHECK_PUBLISH_NAME_COMPLETED = 'CHECK_PUBLISH_NAME_COMPLETED';
|
||||||
export const UPDATE_PENDING_CLAIMS = 'UPDATE_PENDING_CLAIMS';
|
export const UPDATE_PENDING_CLAIMS = 'UPDATE_PENDING_CLAIMS';
|
||||||
export const UPDATE_CONFIRMED_CLAIMS = 'UPDATE_CONFIRMED_CLAIMS';
|
export const UPDATE_CONFIRMED_CLAIMS = 'UPDATE_CONFIRMED_CLAIMS';
|
||||||
|
export const ADD_FILES_REFLECTING = 'ADD_FILES_REFLECTING';
|
||||||
|
export const UPDATE_FILES_REFLECTING = 'UPDATE_FILES_REFLECTING';
|
||||||
|
export const TOGGLE_CHECKING_REFLECTING = 'TOGGLE_CHECKING_REFLECTING';
|
||||||
|
export const TOGGLE_CHECKING_PENDING = 'TOGGLE_CHECKING_PENDING';
|
||||||
|
|
||||||
// Comments
|
// Comments
|
||||||
export const COMMENT_LIST_STARTED = 'COMMENT_LIST_STARTED';
|
export const COMMENT_LIST_STARTED = 'COMMENT_LIST_STARTED';
|
||||||
|
|
|
@ -94,6 +94,7 @@ export {
|
||||||
doPrepareEdit,
|
doPrepareEdit,
|
||||||
doPublish,
|
doPublish,
|
||||||
doCheckPendingPublishes,
|
doCheckPendingPublishes,
|
||||||
|
doCheckReflectingFiles,
|
||||||
} from 'redux/actions/publish';
|
} from 'redux/actions/publish';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
@ -206,12 +207,14 @@ export {
|
||||||
makeSelectChannelForClaimUri,
|
makeSelectChannelForClaimUri,
|
||||||
makeSelectClaimIsPending,
|
makeSelectClaimIsPending,
|
||||||
makeSelectPendingByUri,
|
makeSelectPendingByUri,
|
||||||
|
makeSelectReflectingClaimForUri,
|
||||||
makeSelectClaimsInChannelForCurrentPageState,
|
makeSelectClaimsInChannelForCurrentPageState,
|
||||||
makeSelectShortUrlForUri,
|
makeSelectShortUrlForUri,
|
||||||
makeSelectCanonicalUrlForUri,
|
makeSelectCanonicalUrlForUri,
|
||||||
makeSelectPermanentUrlForUri,
|
makeSelectPermanentUrlForUri,
|
||||||
makeSelectSupportsForUri,
|
makeSelectSupportsForUri,
|
||||||
selectPendingById,
|
selectPendingById,
|
||||||
|
selectReflectingById,
|
||||||
selectClaimsById,
|
selectClaimsById,
|
||||||
selectClaimsByUri,
|
selectClaimsByUri,
|
||||||
selectAllClaimsByChannel,
|
selectAllClaimsByChannel,
|
||||||
|
|
|
@ -12,6 +12,7 @@ import {
|
||||||
selectMyChannelClaims,
|
selectMyChannelClaims,
|
||||||
selectPendingById,
|
selectPendingById,
|
||||||
selectMyClaimsWithoutChannels,
|
selectMyClaimsWithoutChannels,
|
||||||
|
selectReflectingById,
|
||||||
} from 'redux/selectors/claims';
|
} from 'redux/selectors/claims';
|
||||||
import { selectPublishFormValues, selectMyClaimForUri } from 'redux/selectors/publish';
|
import { selectPublishFormValues, selectMyClaimForUri } from 'redux/selectors/publish';
|
||||||
|
|
||||||
|
@ -354,7 +355,78 @@ export const doPublish = (success: Function, fail: Function) => (
|
||||||
return Lbry.publish(publishPayload).then(success, fail);
|
return Lbry.publish(publishPayload).then(success, fail);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Calls claim_list_mine until any pending publishes are confirmed
|
// Calls file_list until any reflecting files are done
|
||||||
|
export const doCheckReflectingFiles = () => (dispatch: Dispatch, getState: GetState) => {
|
||||||
|
const state = getState();
|
||||||
|
const { checkingReflector } = state.claims;
|
||||||
|
let reflectorCheckInterval;
|
||||||
|
|
||||||
|
const checkFileList = async() => {
|
||||||
|
const state = getState();
|
||||||
|
const reflectingById = selectReflectingById(state);
|
||||||
|
const ids = Object.keys(reflectingById);
|
||||||
|
|
||||||
|
const newReflectingById = {};
|
||||||
|
const promises = [];
|
||||||
|
// TODO: just use file_list({claim_id: Array<claimId>})
|
||||||
|
if (Object.keys(reflectingById).length) {
|
||||||
|
ids.forEach(claimId => {
|
||||||
|
promises.push(Lbry.file_list({ claim_id: claimId }));
|
||||||
|
});
|
||||||
|
|
||||||
|
Promise.all(promises)
|
||||||
|
.then(results => {
|
||||||
|
results.forEach(res => {
|
||||||
|
const fileListItem = res.items[0];
|
||||||
|
const fileClaimId = fileListItem.claim_id;
|
||||||
|
const {
|
||||||
|
is_fully_reflected: done,
|
||||||
|
uploading_to_reflector: uploading,
|
||||||
|
reflector_progress: progress,
|
||||||
|
} = fileListItem;
|
||||||
|
if (uploading) {
|
||||||
|
newReflectingById[fileClaimId] = {
|
||||||
|
fileListItem: fileListItem,
|
||||||
|
progress,
|
||||||
|
stalled: !done && !uploading,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.UPDATE_FILES_REFLECTING,
|
||||||
|
data: newReflectingById,
|
||||||
|
});
|
||||||
|
if (!Object.keys(newReflectingById).length) {
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.TOGGLE_CHECKING_REFLECTING,
|
||||||
|
data: false,
|
||||||
|
});
|
||||||
|
clearInterval(reflectorCheckInterval);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.TOGGLE_CHECKING_REFLECTING,
|
||||||
|
data: false,
|
||||||
|
});
|
||||||
|
clearInterval(reflectorCheckInterval);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// do it once...
|
||||||
|
checkFileList();
|
||||||
|
// then start the interval if it's not already started
|
||||||
|
if (!checkingReflector) {
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.TOGGLE_CHECKING_REFLECTING,
|
||||||
|
data: true,
|
||||||
|
});
|
||||||
|
reflectorCheckInterval = setInterval(() => {
|
||||||
|
checkFileList();
|
||||||
|
}, 5000);
|
||||||
|
}
|
||||||
|
};
|
||||||
export const doCheckPendingPublishes = (onConfirmed: Function) => (
|
export const doCheckPendingPublishes = (onConfirmed: Function) => (
|
||||||
dispatch: Dispatch,
|
dispatch: Dispatch,
|
||||||
getState: GetState
|
getState: GetState
|
||||||
|
@ -387,7 +459,7 @@ export const doCheckPendingPublishes = (onConfirmed: Function) => (
|
||||||
}
|
}
|
||||||
return Object.keys(pendingById).length;
|
return Object.keys(pendingById).length;
|
||||||
})
|
})
|
||||||
.then((len) => {
|
.then(len => {
|
||||||
if (!len) {
|
if (!len) {
|
||||||
clearInterval(publishCheckInterval);
|
clearInterval(publishCheckInterval);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ type State = {
|
||||||
byId: { [string]: Claim },
|
byId: { [string]: Claim },
|
||||||
resolvingUris: Array<string>,
|
resolvingUris: Array<string>,
|
||||||
pendingById: { [string]: Claim },
|
pendingById: { [string]: Claim },
|
||||||
|
reflectingById: { [string]: ReflectingUpdate },
|
||||||
myClaims: ?Array<string>,
|
myClaims: ?Array<string>,
|
||||||
myChannelClaims: ?Array<string>,
|
myChannelClaims: ?Array<string>,
|
||||||
abandoningById: { [string]: boolean },
|
abandoningById: { [string]: boolean },
|
||||||
|
@ -46,6 +47,8 @@ type State = {
|
||||||
myClaimsPageTotalResults: ?number,
|
myClaimsPageTotalResults: ?number,
|
||||||
isFetchingClaimListMine: boolean,
|
isFetchingClaimListMine: boolean,
|
||||||
isCheckingNameForPublish: boolean,
|
isCheckingNameForPublish: boolean,
|
||||||
|
checkingPending: boolean,
|
||||||
|
checkingReflecting: boolean,
|
||||||
};
|
};
|
||||||
|
|
||||||
const reducers = {};
|
const reducers = {};
|
||||||
|
@ -63,6 +66,7 @@ const defaultState = {
|
||||||
fetchingMyChannels: false,
|
fetchingMyChannels: false,
|
||||||
abandoningById: {},
|
abandoningById: {},
|
||||||
pendingById: {},
|
pendingById: {},
|
||||||
|
reflectingById: {},
|
||||||
claimSearchError: false,
|
claimSearchError: false,
|
||||||
claimSearchByQuery: {},
|
claimSearchByQuery: {},
|
||||||
claimSearchByQueryLastPageReached: {},
|
claimSearchByQueryLastPageReached: {},
|
||||||
|
@ -80,6 +84,8 @@ const defaultState = {
|
||||||
myClaimsPageTotalResults: undefined,
|
myClaimsPageTotalResults: undefined,
|
||||||
isFetchingClaimListMine: false,
|
isFetchingClaimListMine: false,
|
||||||
isCheckingNameForPublish: false,
|
isCheckingNameForPublish: false,
|
||||||
|
checkingPending: false,
|
||||||
|
checkingReflecting: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
function handleClaimAction(state: State, action: any): State {
|
function handleClaimAction(state: State, action: any): State {
|
||||||
|
@ -362,7 +368,7 @@ reducers[ACTIONS.ABANDON_CLAIM_STARTED] = (state: State, action: any): State =>
|
||||||
};
|
};
|
||||||
|
|
||||||
reducers[ACTIONS.UPDATE_PENDING_CLAIMS] = (state: State, action: any): State => {
|
reducers[ACTIONS.UPDATE_PENDING_CLAIMS] = (state: State, action: any): State => {
|
||||||
const { claims }: { claims: Array<GenericClaim> } = action.data;
|
const { claims }: { claims: Array<Claim> } = action.data;
|
||||||
const byId = Object.assign({}, state.byId);
|
const byId = Object.assign({}, state.byId);
|
||||||
const byUri = Object.assign({}, state.claimsByUri);
|
const byUri = Object.assign({}, state.claimsByUri);
|
||||||
const pendingById: { [string]: Claim } = Object.assign({}, state.pendingById);
|
const pendingById: { [string]: Claim } = Object.assign({}, state.pendingById);
|
||||||
|
@ -387,13 +393,13 @@ reducers[ACTIONS.UPDATE_PENDING_CLAIMS] = (state: State, action: any): State =>
|
||||||
};
|
};
|
||||||
|
|
||||||
reducers[ACTIONS.UPDATE_CONFIRMED_CLAIMS] = (state: State, action: any): State => {
|
reducers[ACTIONS.UPDATE_CONFIRMED_CLAIMS] = (state: State, action: any): State => {
|
||||||
const { claims }: { claims: Array<GenericClaim> } = action.data;
|
const { claims }: { claims: Array<Claim> } = action.data;
|
||||||
const byId = Object.assign({}, state.byId);
|
const byId = Object.assign({}, state.byId);
|
||||||
const byUri = Object.assign({}, state.claimsByUri);
|
const byUri = Object.assign({}, state.claimsByUri);
|
||||||
const pendingById: { [string]: Claim } = Object.assign({}, state.pendingById);
|
const pendingById: { [string]: Claim } = Object.assign({}, state.pendingById);
|
||||||
let myClaimIds = new Set(state.myClaims);
|
let myClaimIds = new Set(state.myClaims);
|
||||||
|
|
||||||
claims.forEach((claim: Claim) => {
|
claims.forEach((claim: GenericClaim) => {
|
||||||
const uri = buildURI({ streamName: claim.name, streamClaimId: claim.claim_id });
|
const uri = buildURI({ streamName: claim.name, streamClaimId: claim.claim_id });
|
||||||
const { claim_id: claimId } = claim;
|
const { claim_id: claimId } = claim;
|
||||||
if (claim.type && claim.type.match(/claim|update/)) {
|
if (claim.type && claim.type.match(/claim|update/)) {
|
||||||
|
@ -594,6 +600,42 @@ reducers[ACTIONS.CLEAR_REPOST_ERROR] = (state: State): State => {
|
||||||
repostError: null,
|
repostError: null,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
reducers[ACTIONS.ADD_FILES_REFLECTING] = (state: State, action): State => {
|
||||||
|
const pendingClaim = action.data;
|
||||||
|
const { reflectingById } = state;
|
||||||
|
const claimId = pendingClaim && pendingClaim.claim_id;
|
||||||
|
|
||||||
|
reflectingById[claimId] = { fileListItem: pendingClaim, progress: 0, stalled: false };
|
||||||
|
|
||||||
|
return Object.assign({}, state, {
|
||||||
|
...state,
|
||||||
|
reflectingById: reflectingById,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
reducers[ACTIONS.UPDATE_FILES_REFLECTING] = (state: State, action): State => {
|
||||||
|
const newReflectingById = action.data;
|
||||||
|
|
||||||
|
return Object.assign({}, state, {
|
||||||
|
...state,
|
||||||
|
reflectingById: newReflectingById,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
reducers[ACTIONS.TOGGLE_CHECKING_REFLECTING] = (state: State, action): State => {
|
||||||
|
const checkingReflecting = action.data;
|
||||||
|
|
||||||
|
return Object.assign({}, state, {
|
||||||
|
...state,
|
||||||
|
checkingReflecting,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
reducers[ACTIONS.TOGGLE_CHECKING_PENDING] = (state: State, action): State => {
|
||||||
|
const checking = action.data;
|
||||||
|
|
||||||
|
return Object.assign({}, state, {
|
||||||
|
...state,
|
||||||
|
checkingPending: checking,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export function claimsReducer(state: State = defaultState, action: any) {
|
export function claimsReducer(state: State = defaultState, action: any) {
|
||||||
const handler = reducers[action.type];
|
const handler = reducers[action.type];
|
||||||
|
|
|
@ -111,6 +111,10 @@ export const makeSelectPendingByUri = (uri: string) =>
|
||||||
return pendingById[claimId];
|
return pendingById[claimId];
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
export const selectReflectingById = createSelector(
|
||||||
|
selectState,
|
||||||
|
state => state.reflectingById
|
||||||
|
);
|
||||||
|
|
||||||
export const makeSelectClaimForUri = (uri: string, returnRepost: boolean = true) =>
|
export const makeSelectClaimForUri = (uri: string, returnRepost: boolean = true) =>
|
||||||
createSelector(
|
createSelector(
|
||||||
|
@ -314,8 +318,8 @@ export const makeSelectDateForUri = (uri: string) =>
|
||||||
(claim.value.release_time
|
(claim.value.release_time
|
||||||
? claim.value.release_time * 1000
|
? claim.value.release_time * 1000
|
||||||
: claim.meta && claim.meta.creation_timestamp
|
: claim.meta && claim.meta.creation_timestamp
|
||||||
? claim.meta.creation_timestamp * 1000
|
? claim.meta.creation_timestamp * 1000
|
||||||
: null);
|
: null);
|
||||||
if (!timestamp) {
|
if (!timestamp) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
@ -717,6 +721,16 @@ export const selectUpdateChannelError = createSelector(
|
||||||
state => state.updateChannelError
|
state => state.updateChannelError
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const makeSelectReflectingClaimForUri = (uri: string) =>
|
||||||
|
createSelector(
|
||||||
|
makeSelectClaimForUri(uri),
|
||||||
|
selectReflectingById,
|
||||||
|
(claim, reflectingById) => {
|
||||||
|
const claimId = claim && claim.claimId;
|
||||||
|
return reflectingById[claimId];
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
export const makeSelectMyStreamUrlsForPage = (page: number = 1) =>
|
export const makeSelectMyStreamUrlsForPage = (page: number = 1) =>
|
||||||
createSelector(
|
createSelector(
|
||||||
selectMyClaimUrisWithoutChannels,
|
selectMyClaimUrisWithoutChannels,
|
||||||
|
|
Loading…
Reference in a new issue