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 doResolveUris(uris) {
|
||||
var returnCachedClaims = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
||||
|
||||
return function (dispatch, getState) {
|
||||
var normalizedUris = uris.map(_lbryURI.normalizeURI);
|
||||
var state = getState();
|
||||
|
||||
// Filter out URIs that are already resolving
|
||||
var resolvingUris = (0, _claims.selectResolvingUris)(state);
|
||||
var claimsByUri = (0, _claims.selectClaimsByUri)(state);
|
||||
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) {
|
||||
|
@ -2190,6 +2196,8 @@ function doAbandonClaim(txid, nout) {
|
|||
}
|
||||
|
||||
function doFetchFeaturedUris() {
|
||||
var offloadResolve = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
||||
|
||||
return function (dispatch) {
|
||||
dispatch({
|
||||
type: ACTIONS.FETCH_FEATURED_CONTENT_STARTED
|
||||
|
@ -2203,13 +2211,17 @@ function doFetchFeaturedUris() {
|
|||
urisToResolve = [].concat(_toConsumableArray(urisToResolve), _toConsumableArray(Uris[category]));
|
||||
});
|
||||
|
||||
var actions = [doResolveUris(urisToResolve), {
|
||||
var actions = [{
|
||||
type: ACTIONS.FETCH_FEATURED_CONTENT_COMPLETED,
|
||||
data: {
|
||||
uris: Uris,
|
||||
success: true
|
||||
}
|
||||
}];
|
||||
if (urisToResolve.length && !offloadResolve) {
|
||||
actions.push(doResolveUris(urisToResolve));
|
||||
}
|
||||
|
||||
dispatch(_batchActions.batchActions.apply(undefined, actions));
|
||||
};
|
||||
|
||||
|
|
|
@ -3,18 +3,24 @@ import Lbry from 'lbry';
|
|||
import Lbryapi from 'lbryapi';
|
||||
import { normalizeURI } from 'lbryURI';
|
||||
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 { doFetchTransactions } from 'redux/actions/wallet';
|
||||
|
||||
export function doResolveUris(uris) {
|
||||
export function doResolveUris(uris, returnCachedClaims = false) {
|
||||
return (dispatch, getState) => {
|
||||
const normalizedUris = uris.map(normalizeURI);
|
||||
const state = getState();
|
||||
|
||||
// Filter out URIs that are already resolving
|
||||
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) {
|
||||
return;
|
||||
|
@ -26,7 +32,7 @@ export function doResolveUris(uris) {
|
|||
});
|
||||
|
||||
const resolveInfo = {};
|
||||
Lbry.resolve({ uris: urisToResolve }).then((result) => {
|
||||
Lbry.resolve({ uris: urisToResolve }).then(result => {
|
||||
Object.entries(result).forEach(([uri, uriResolveInfo]) => {
|
||||
const fallbackResolveInfo = {
|
||||
claim: null,
|
||||
|
@ -53,12 +59,12 @@ export function doResolveUri(uri) {
|
|||
}
|
||||
|
||||
export function doFetchClaimListMine() {
|
||||
return (dispatch) => {
|
||||
return dispatch => {
|
||||
dispatch({
|
||||
type: ACTIONS.FETCH_CLAIM_LIST_MINE_STARTED,
|
||||
});
|
||||
|
||||
Lbry.claim_list_mine().then((claims) => {
|
||||
Lbry.claim_list_mine().then(claims => {
|
||||
dispatch({
|
||||
type: ACTIONS.FETCH_CLAIM_LIST_MINE_COMPLETED,
|
||||
data: {
|
||||
|
@ -74,7 +80,7 @@ export function doAbandonClaim(txid, nout) {
|
|||
const state = getState();
|
||||
const myClaims = selectMyClaimsRaw(state);
|
||||
const { claim_id: claimId } = myClaims.find(
|
||||
(claim) => claim.txid === txid && claim.nout === nout
|
||||
claim => claim.txid === txid && claim.nout === nout
|
||||
);
|
||||
|
||||
dispatch({
|
||||
|
@ -93,7 +99,7 @@ export function doAbandonClaim(txid, nout) {
|
|||
);
|
||||
};
|
||||
|
||||
const successCallback = (results) => {
|
||||
const successCallback = results => {
|
||||
if (results.success === true) {
|
||||
dispatch({
|
||||
type: ACTIONS.ABANDON_CLAIM_SUCCEEDED,
|
||||
|
@ -128,20 +134,19 @@ export function doAbandonClaim(txid, nout) {
|
|||
};
|
||||
}
|
||||
|
||||
export function doFetchFeaturedUris() {
|
||||
return (dispatch) => {
|
||||
export function doFetchFeaturedUris(offloadResolve = false) {
|
||||
return dispatch => {
|
||||
dispatch({
|
||||
type: ACTIONS.FETCH_FEATURED_CONTENT_STARTED,
|
||||
});
|
||||
|
||||
const success = ({ Uris }) => {
|
||||
let urisToResolve = [];
|
||||
Object.keys(Uris).forEach((category) => {
|
||||
Object.keys(Uris).forEach(category => {
|
||||
urisToResolve = [...urisToResolve, ...Uris[category]];
|
||||
});
|
||||
|
||||
const actions = [
|
||||
doResolveUris(urisToResolve),
|
||||
{
|
||||
type: ACTIONS.FETCH_FEATURED_CONTENT_COMPLETED,
|
||||
data: {
|
||||
|
@ -150,6 +155,10 @@ export function doFetchFeaturedUris() {
|
|||
},
|
||||
},
|
||||
];
|
||||
if (urisToResolve.length && !offloadResolve) {
|
||||
actions.push(doResolveUris(urisToResolve));
|
||||
}
|
||||
|
||||
dispatch(batchActions(...actions));
|
||||
};
|
||||
|
||||
|
@ -167,13 +176,13 @@ export function doFetchFeaturedUris() {
|
|||
}
|
||||
|
||||
export function doFetchTrendingUris() {
|
||||
return (dispatch) => {
|
||||
return dispatch => {
|
||||
dispatch({
|
||||
type: ACTIONS.FETCH_TRENDING_CONTENT_STARTED,
|
||||
});
|
||||
|
||||
const success = (data) => {
|
||||
const urisToResolve = data.map((uri) => uri.url);
|
||||
const success = data => {
|
||||
const urisToResolve = data.map(uri => uri.url);
|
||||
const actions = [
|
||||
doResolveUris(urisToResolve),
|
||||
{
|
||||
|
@ -201,13 +210,13 @@ export function doFetchTrendingUris() {
|
|||
}
|
||||
|
||||
export function doFetchClaimsByChannel(uri, page) {
|
||||
return (dispatch) => {
|
||||
return dispatch => {
|
||||
dispatch({
|
||||
type: ACTIONS.FETCH_CHANNEL_CLAIMS_STARTED,
|
||||
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 { claims_in_channel: claimsInChannel, returned_page: returnedPage } = claimResult;
|
||||
|
||||
|
@ -224,13 +233,13 @@ export function doFetchClaimsByChannel(uri, page) {
|
|||
}
|
||||
|
||||
export function doFetchClaimCountByChannel(uri) {
|
||||
return (dispatch) => {
|
||||
return dispatch => {
|
||||
dispatch({
|
||||
type: ACTIONS.FETCH_CHANNEL_CLAIM_COUNT_STARTED,
|
||||
data: { uri },
|
||||
});
|
||||
|
||||
Lbry.claim_list_by_channel({ uri }).then((result) => {
|
||||
Lbry.claim_list_by_channel({ uri }).then(result => {
|
||||
const claimResult = result[uri];
|
||||
const totalClaims = claimResult ? claimResult.claims_in_channel : 0;
|
||||
|
||||
|
|
Loading…
Reference in a new issue