update: more options for resolving
This commit is contained in:
parent
973bbd780a
commit
b937a5d595
2 changed files with 44 additions and 23 deletions
18
dist/bundle.js
vendored
18
dist/bundle.js
vendored
|
@ -2065,14 +2065,20 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
|
||||||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
||||||
|
|
||||||
function doResolveUris(uris) {
|
function doResolveUris(uris) {
|
||||||
|
var returnCachedClaims = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
||||||
|
|
||||||
return function (dispatch, getState) {
|
return function (dispatch, getState) {
|
||||||
var normalizedUris = uris.map(_lbryURI.normalizeURI);
|
var normalizedUris = uris.map(_lbryURI.normalizeURI);
|
||||||
var state = getState();
|
var state = getState();
|
||||||
|
|
||||||
// Filter out URIs that are already resolving
|
|
||||||
var resolvingUris = (0, _claims.selectResolvingUris)(state);
|
var resolvingUris = (0, _claims.selectResolvingUris)(state);
|
||||||
|
var claimsByUri = (0, _claims.selectClaimsByUri)(state);
|
||||||
var urisToResolve = normalizedUris.filter(function (uri) {
|
var urisToResolve = normalizedUris.filter(function (uri) {
|
||||||
return !resolvingUris.includes(uri);
|
if (resolvingUris.includes(uri)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnCachedClaims ? !claimsByUri[uri] : true;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (urisToResolve.length === 0) {
|
if (urisToResolve.length === 0) {
|
||||||
|
@ -2190,6 +2196,8 @@ function doAbandonClaim(txid, nout) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function doFetchFeaturedUris() {
|
function doFetchFeaturedUris() {
|
||||||
|
var offloadResolve = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
||||||
|
|
||||||
return function (dispatch) {
|
return function (dispatch) {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.FETCH_FEATURED_CONTENT_STARTED
|
type: ACTIONS.FETCH_FEATURED_CONTENT_STARTED
|
||||||
|
@ -2203,13 +2211,17 @@ function doFetchFeaturedUris() {
|
||||||
urisToResolve = [].concat(_toConsumableArray(urisToResolve), _toConsumableArray(Uris[category]));
|
urisToResolve = [].concat(_toConsumableArray(urisToResolve), _toConsumableArray(Uris[category]));
|
||||||
});
|
});
|
||||||
|
|
||||||
var actions = [doResolveUris(urisToResolve), {
|
var actions = [{
|
||||||
type: ACTIONS.FETCH_FEATURED_CONTENT_COMPLETED,
|
type: ACTIONS.FETCH_FEATURED_CONTENT_COMPLETED,
|
||||||
data: {
|
data: {
|
||||||
uris: Uris,
|
uris: Uris,
|
||||||
success: true
|
success: true
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
|
if (urisToResolve.length && !offloadResolve) {
|
||||||
|
actions.push(doResolveUris(urisToResolve));
|
||||||
|
}
|
||||||
|
|
||||||
dispatch(_batchActions.batchActions.apply(undefined, actions));
|
dispatch(_batchActions.batchActions.apply(undefined, actions));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3,18 +3,24 @@ import Lbry from 'lbry';
|
||||||
import Lbryapi from 'lbryapi';
|
import Lbryapi from 'lbryapi';
|
||||||
import { normalizeURI } from 'lbryURI';
|
import { normalizeURI } from 'lbryURI';
|
||||||
import { doToast } from 'redux/actions/notifications';
|
import { doToast } from 'redux/actions/notifications';
|
||||||
import { selectMyClaimsRaw, selectResolvingUris } from 'redux/selectors/claims';
|
import { selectMyClaimsRaw, selectResolvingUris, selectClaimsByUri } from 'redux/selectors/claims';
|
||||||
import { batchActions } from 'util/batchActions';
|
import { batchActions } from 'util/batchActions';
|
||||||
import { doFetchTransactions } from 'redux/actions/wallet';
|
import { doFetchTransactions } from 'redux/actions/wallet';
|
||||||
|
|
||||||
export function doResolveUris(uris) {
|
export function doResolveUris(uris, returnCachedClaims = false) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const normalizedUris = uris.map(normalizeURI);
|
const normalizedUris = uris.map(normalizeURI);
|
||||||
const state = getState();
|
const state = getState();
|
||||||
|
|
||||||
// Filter out URIs that are already resolving
|
|
||||||
const resolvingUris = selectResolvingUris(state);
|
const resolvingUris = selectResolvingUris(state);
|
||||||
const urisToResolve = normalizedUris.filter((uri) => !resolvingUris.includes(uri));
|
const claimsByUri = selectClaimsByUri(state);
|
||||||
|
const urisToResolve = normalizedUris.filter(uri => {
|
||||||
|
if (resolvingUris.includes(uri)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnCachedClaims ? !claimsByUri[uri] : true;
|
||||||
|
});
|
||||||
|
|
||||||
if (urisToResolve.length === 0) {
|
if (urisToResolve.length === 0) {
|
||||||
return;
|
return;
|
||||||
|
@ -26,7 +32,7 @@ export function doResolveUris(uris) {
|
||||||
});
|
});
|
||||||
|
|
||||||
const resolveInfo = {};
|
const resolveInfo = {};
|
||||||
Lbry.resolve({ uris: urisToResolve }).then((result) => {
|
Lbry.resolve({ uris: urisToResolve }).then(result => {
|
||||||
Object.entries(result).forEach(([uri, uriResolveInfo]) => {
|
Object.entries(result).forEach(([uri, uriResolveInfo]) => {
|
||||||
const fallbackResolveInfo = {
|
const fallbackResolveInfo = {
|
||||||
claim: null,
|
claim: null,
|
||||||
|
@ -53,12 +59,12 @@ export function doResolveUri(uri) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function doFetchClaimListMine() {
|
export function doFetchClaimListMine() {
|
||||||
return (dispatch) => {
|
return dispatch => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.FETCH_CLAIM_LIST_MINE_STARTED,
|
type: ACTIONS.FETCH_CLAIM_LIST_MINE_STARTED,
|
||||||
});
|
});
|
||||||
|
|
||||||
Lbry.claim_list_mine().then((claims) => {
|
Lbry.claim_list_mine().then(claims => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.FETCH_CLAIM_LIST_MINE_COMPLETED,
|
type: ACTIONS.FETCH_CLAIM_LIST_MINE_COMPLETED,
|
||||||
data: {
|
data: {
|
||||||
|
@ -74,7 +80,7 @@ export function doAbandonClaim(txid, nout) {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
const myClaims = selectMyClaimsRaw(state);
|
const myClaims = selectMyClaimsRaw(state);
|
||||||
const { claim_id: claimId } = myClaims.find(
|
const { claim_id: claimId } = myClaims.find(
|
||||||
(claim) => claim.txid === txid && claim.nout === nout
|
claim => claim.txid === txid && claim.nout === nout
|
||||||
);
|
);
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
|
@ -93,7 +99,7 @@ export function doAbandonClaim(txid, nout) {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const successCallback = (results) => {
|
const successCallback = results => {
|
||||||
if (results.success === true) {
|
if (results.success === true) {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.ABANDON_CLAIM_SUCCEEDED,
|
type: ACTIONS.ABANDON_CLAIM_SUCCEEDED,
|
||||||
|
@ -128,20 +134,19 @@ export function doAbandonClaim(txid, nout) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function doFetchFeaturedUris() {
|
export function doFetchFeaturedUris(offloadResolve = false) {
|
||||||
return (dispatch) => {
|
return dispatch => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.FETCH_FEATURED_CONTENT_STARTED,
|
type: ACTIONS.FETCH_FEATURED_CONTENT_STARTED,
|
||||||
});
|
});
|
||||||
|
|
||||||
const success = ({ Uris }) => {
|
const success = ({ Uris }) => {
|
||||||
let urisToResolve = [];
|
let urisToResolve = [];
|
||||||
Object.keys(Uris).forEach((category) => {
|
Object.keys(Uris).forEach(category => {
|
||||||
urisToResolve = [...urisToResolve, ...Uris[category]];
|
urisToResolve = [...urisToResolve, ...Uris[category]];
|
||||||
});
|
});
|
||||||
|
|
||||||
const actions = [
|
const actions = [
|
||||||
doResolveUris(urisToResolve),
|
|
||||||
{
|
{
|
||||||
type: ACTIONS.FETCH_FEATURED_CONTENT_COMPLETED,
|
type: ACTIONS.FETCH_FEATURED_CONTENT_COMPLETED,
|
||||||
data: {
|
data: {
|
||||||
|
@ -150,6 +155,10 @@ export function doFetchFeaturedUris() {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
if (urisToResolve.length && !offloadResolve) {
|
||||||
|
actions.push(doResolveUris(urisToResolve));
|
||||||
|
}
|
||||||
|
|
||||||
dispatch(batchActions(...actions));
|
dispatch(batchActions(...actions));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -167,13 +176,13 @@ export function doFetchFeaturedUris() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function doFetchTrendingUris() {
|
export function doFetchTrendingUris() {
|
||||||
return (dispatch) => {
|
return dispatch => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.FETCH_TRENDING_CONTENT_STARTED,
|
type: ACTIONS.FETCH_TRENDING_CONTENT_STARTED,
|
||||||
});
|
});
|
||||||
|
|
||||||
const success = (data) => {
|
const success = data => {
|
||||||
const urisToResolve = data.map((uri) => uri.url);
|
const urisToResolve = data.map(uri => uri.url);
|
||||||
const actions = [
|
const actions = [
|
||||||
doResolveUris(urisToResolve),
|
doResolveUris(urisToResolve),
|
||||||
{
|
{
|
||||||
|
@ -201,13 +210,13 @@ export function doFetchTrendingUris() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function doFetchClaimsByChannel(uri, page) {
|
export function doFetchClaimsByChannel(uri, page) {
|
||||||
return (dispatch) => {
|
return dispatch => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.FETCH_CHANNEL_CLAIMS_STARTED,
|
type: ACTIONS.FETCH_CHANNEL_CLAIMS_STARTED,
|
||||||
data: { uri, page },
|
data: { uri, page },
|
||||||
});
|
});
|
||||||
|
|
||||||
Lbry.claim_list_by_channel({ uri, page: page || 1 }).then((result) => {
|
Lbry.claim_list_by_channel({ uri, page: page || 1 }).then(result => {
|
||||||
const claimResult = result[uri] || {};
|
const claimResult = result[uri] || {};
|
||||||
const { claims_in_channel: claimsInChannel, returned_page: returnedPage } = claimResult;
|
const { claims_in_channel: claimsInChannel, returned_page: returnedPage } = claimResult;
|
||||||
|
|
||||||
|
@ -224,13 +233,13 @@ export function doFetchClaimsByChannel(uri, page) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function doFetchClaimCountByChannel(uri) {
|
export function doFetchClaimCountByChannel(uri) {
|
||||||
return (dispatch) => {
|
return dispatch => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.FETCH_CHANNEL_CLAIM_COUNT_STARTED,
|
type: ACTIONS.FETCH_CHANNEL_CLAIM_COUNT_STARTED,
|
||||||
data: { uri },
|
data: { uri },
|
||||||
});
|
});
|
||||||
|
|
||||||
Lbry.claim_list_by_channel({ uri }).then((result) => {
|
Lbry.claim_list_by_channel({ uri }).then(result => {
|
||||||
const claimResult = result[uri];
|
const claimResult = result[uri];
|
||||||
const totalClaims = claimResult ? claimResult.claims_in_channel : 0;
|
const totalClaims = claimResult ? claimResult.claims_in_channel : 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue