Merge pull request #326 from lbryio/revert-325-pendingChannels

Revert "support pending channels"
This commit is contained in:
jessopb 2020-06-19 13:11:44 -04:00 committed by GitHub
commit 273090d42f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 488 additions and 467 deletions

597
dist/bundle.es.js vendored

File diff suppressed because it is too large Load diff

View file

@ -22,7 +22,7 @@ declare type GenericClaim = {
timestamp?: number, // date of last transaction timestamp?: number, // date of last transaction
height: number, // block height the tx was confirmed height: number, // block height the tx was confirmed
is_channel_signature_valid?: boolean, is_channel_signature_valid?: boolean,
is_my_output: boolean, is_my_output: true,
name: string, name: string,
normalized_name: string, // `name` normalized via unicode NFD spec, normalized_name: string, // `name` normalized via unicode NFD spec,
nout: number, // index number for an output of a tx nout: number, // index number for an output of a tx

2
flow-typed/Claim.js vendored
View file

@ -22,7 +22,7 @@ declare type GenericClaim = {
timestamp?: number, // date of last transaction timestamp?: number, // date of last transaction
height: number, // block height the tx was confirmed height: number, // block height the tx was confirmed
is_channel_signature_valid?: boolean, is_channel_signature_valid?: boolean,
is_my_output: boolean, is_my_output: true,
name: string, name: string,
normalized_name: string, // `name` normalized via unicode NFD spec, normalized_name: string, // `name` normalized via unicode NFD spec,
nout: number, // index number for an output of a tx nout: number, // index number for an output of a tx

View file

@ -76,7 +76,6 @@ export {
doClearRepostError, doClearRepostError,
doCheckPublishNameAvailability, doCheckPublishNameAvailability,
doPurchaseList, doPurchaseList,
doCheckPendingClaims,
} from 'redux/actions/claims'; } from 'redux/actions/claims';
export { doClearPurchasedUriSuccess, doPurchaseUri, doFileGet } from 'redux/actions/file'; export { doClearPurchasedUriSuccess, doPurchaseUri, doFileGet } from 'redux/actions/file';
@ -95,6 +94,7 @@ export {
doUploadThumbnail, doUploadThumbnail,
doPrepareEdit, doPrepareEdit,
doPublish, doPublish,
doCheckPendingPublishes,
doCheckReflectingFiles, doCheckReflectingFiles,
} from 'redux/actions/publish'; } from 'redux/actions/publish';
@ -198,6 +198,7 @@ export {
makeSelectFirstRecommendedFileForUri, makeSelectFirstRecommendedFileForUri,
makeSelectChannelForClaimUri, makeSelectChannelForClaimUri,
makeSelectClaimIsPending, makeSelectClaimIsPending,
makeSelectPendingByUri,
makeSelectReflectingClaimForUri, makeSelectReflectingClaimForUri,
makeSelectClaimsInChannelForCurrentPageState, makeSelectClaimsInChannelForCurrentPageState,
makeSelectShortUrlForUri, makeSelectShortUrlForUri,
@ -206,6 +207,7 @@ export {
makeSelectSupportsForUri, makeSelectSupportsForUri,
makeSelectMyPurchasesForPage, makeSelectMyPurchasesForPage,
makeSelectClaimWasPurchased, makeSelectClaimWasPurchased,
selectPendingById,
selectReflectingById, selectReflectingById,
selectClaimsById, selectClaimsById,
selectClaimsByUri, selectClaimsByUri,
@ -215,9 +217,9 @@ export {
selectMyActiveClaims, selectMyActiveClaims,
selectAllFetchingChannelClaims, selectAllFetchingChannelClaims,
selectIsFetchingClaimListMine, selectIsFetchingClaimListMine,
selectPendingClaims,
selectMyClaims, selectMyClaims,
selectMyClaimsWithoutChannels, selectMyClaimsWithoutChannels,
selectMyChannelUrls,
selectMyClaimUrisWithoutChannels, selectMyClaimUrisWithoutChannels,
selectAllMyClaimsByOutpoint, selectAllMyClaimsByOutpoint,
selectMyClaimsOutpoints, selectMyClaimsOutpoints,

View file

@ -9,7 +9,6 @@ import {
selectResolvingUris, selectResolvingUris,
selectClaimsByUri, selectClaimsByUri,
selectMyChannelClaims, selectMyChannelClaims,
selectPendingIds,
} from 'redux/selectors/claims'; } from 'redux/selectors/claims';
import { doFetchTxoPage } from 'redux/actions/wallet'; import { doFetchTxoPage } from 'redux/actions/wallet';
import { selectSupportsByOutpoint } from 'redux/selectors/wallet'; import { selectSupportsByOutpoint } from 'redux/selectors/wallet';
@ -339,7 +338,7 @@ export function doFetchClaimsByChannel(uri: string, page: number = 1) {
}; };
} }
export function doCreateChannel(name: string, amount: number, optionalParams: any, cb: any) { export function doCreateChannel(name: string, amount: number, optionalParams: any) {
return (dispatch: Dispatch) => { return (dispatch: Dispatch) => {
dispatch({ dispatch({
type: ACTIONS.CREATE_CHANNEL_STARTED, type: ACTIONS.CREATE_CHANNEL_STARTED,
@ -396,13 +395,6 @@ export function doCreateChannel(name: string, amount: number, optionalParams: an
type: ACTIONS.CREATE_CHANNEL_COMPLETED, type: ACTIONS.CREATE_CHANNEL_COMPLETED,
data: { channelClaim }, data: { channelClaim },
}); });
dispatch({
type: ACTIONS.UPDATE_PENDING_CLAIMS,
data: {
claims: [channelClaim],
},
});
dispatch(doCheckPendingClaims(cb));
return channelClaim; return channelClaim;
}) })
.catch(error => { .catch(error => {
@ -416,7 +408,7 @@ export function doCreateChannel(name: string, amount: number, optionalParams: an
}; };
} }
export function doUpdateChannel(params: any, cb: any) { export function doUpdateChannel(params: any) {
return (dispatch: Dispatch, getState: GetState) => { return (dispatch: Dispatch, getState: GetState) => {
dispatch({ dispatch({
type: ACTIONS.UPDATE_CHANNEL_STARTED, type: ACTIONS.UPDATE_CHANNEL_STARTED,
@ -462,16 +454,7 @@ export function doUpdateChannel(params: any, cb: any) {
type: ACTIONS.UPDATE_CHANNEL_COMPLETED, type: ACTIONS.UPDATE_CHANNEL_COMPLETED,
data: { channelClaim }, data: { channelClaim },
}); });
dispatch({
type: ACTIONS.UPDATE_PENDING_CLAIMS,
data: {
claims: [channelClaim],
},
});
dispatch(doCheckPendingClaims(cb));
return Boolean(result.outputs[0]);
}) })
.then()
.catch(error => { .catch(error => {
dispatch({ dispatch({
type: ACTIONS.UPDATE_CHANNEL_FAILED, type: ACTIONS.UPDATE_CHANNEL_FAILED,
@ -686,48 +669,3 @@ export function doPurchaseList(page: number = 1, pageSize: number = PAGE_SIZE) {
}).then(success, failure); }).then(success, failure);
}; };
} }
export const doCheckPendingClaims = (onConfirmed: Function) => (
dispatch: Dispatch,
getState: GetState
) => {
let claimCheckInterval;
const checkClaimList = () => {
const state = getState();
const pendingIdSet = new Set(selectPendingIds(state));
Lbry.claim_list({ page: 1, page_size: 10 })
.then(result => {
const claims = result.items;
const claimsToConfirm = [];
claims.forEach(claim => {
const { claim_id: claimId } = claim;
if (claim.confirmations > 0 && pendingIdSet.has(claimId)) {
pendingIdSet.delete(claimId);
claimsToConfirm.push(claim);
if (onConfirmed) {
onConfirmed(claim);
}
}
});
if (claimsToConfirm.length) {
dispatch({
type: ACTIONS.UPDATE_CONFIRMED_CLAIMS,
data: {
claims: claimsToConfirm,
},
});
}
return pendingIdSet.size;
})
.then(len => {
if (!len) {
clearInterval(claimCheckInterval);
}
});
};
claimCheckInterval = setInterval(() => {
checkClaimList();
}, 30000);
};

View file

@ -10,6 +10,7 @@ import { doError } from 'redux/actions/notifications';
import { isClaimNsfw } from 'util/claim'; import { isClaimNsfw } from 'util/claim';
import { import {
selectMyChannelClaims, selectMyChannelClaims,
selectPendingById,
selectMyClaimsWithoutChannels, selectMyClaimsWithoutChannels,
selectReflectingById, selectReflectingById,
} from 'redux/selectors/claims'; } from 'redux/selectors/claims';
@ -426,3 +427,46 @@ export const doCheckReflectingFiles = () => (dispatch: Dispatch, getState: GetSt
}, 5000); }, 5000);
} }
}; };
export const doCheckPendingPublishes = (onConfirmed: Function) => (
dispatch: Dispatch,
getState: GetState
) => {
let publishCheckInterval;
const checkFileList = () => {
const state = getState();
const pendingById = selectPendingById(state);
Lbry.claim_list({ page: 1, page_size: 10 })
.then(result => {
const claims = result.items;
const claimsToConfirm = [];
claims.forEach(claim => {
if (claim.confirmations > 0 && pendingById[claim.claim_id]) {
delete pendingById[claim.claim_id];
claimsToConfirm.push(claim);
if (onConfirmed) {
onConfirmed(claim);
}
}
});
if (claimsToConfirm.length) {
dispatch({
type: ACTIONS.UPDATE_CONFIRMED_CLAIMS,
data: {
claims: claimsToConfirm,
},
});
}
return Object.keys(pendingById).length;
})
.then(len => {
if (!len) {
clearInterval(publishCheckInterval);
}
});
};
publishCheckInterval = setInterval(() => {
checkFileList();
}, 30000);
};

View file

@ -9,7 +9,7 @@
// - Sean // - Sean
import * as ACTIONS from 'constants/action_types'; import * as ACTIONS from 'constants/action_types';
import mergeClaim from 'util/merge-claim'; import { buildURI, parseURI } from 'lbryURI';
type State = { type State = {
createChannelError: ?string, createChannelError: ?string,
@ -17,7 +17,7 @@ type State = {
claimsByUri: { [string]: string }, claimsByUri: { [string]: string },
byId: { [string]: Claim }, byId: { [string]: Claim },
resolvingUris: Array<string>, resolvingUris: Array<string>,
pendingIds: Array<string>, pendingById: { [string]: Claim },
reflectingById: { [string]: ReflectingUpdate }, reflectingById: { [string]: ReflectingUpdate },
myClaims: ?Array<string>, myClaims: ?Array<string>,
myChannelClaims: ?Array<string>, myChannelClaims: ?Array<string>,
@ -75,7 +75,7 @@ const defaultState = {
fetchingMyPurchasesError: undefined, fetchingMyPurchasesError: undefined,
fetchingMyChannels: false, fetchingMyChannels: false,
abandoningById: {}, abandoningById: {},
pendingIds: [], pendingById: {},
reflectingById: {}, reflectingById: {},
claimSearchError: false, claimSearchError: false,
claimSearchByQuery: {}, claimSearchByQuery: {},
@ -112,19 +112,18 @@ function handleClaimAction(state: State, action: any): State {
const byUri = Object.assign({}, state.claimsByUri); const byUri = Object.assign({}, state.claimsByUri);
const byId = Object.assign({}, state.byId); const byId = Object.assign({}, state.byId);
const channelClaimCounts = Object.assign({}, state.channelClaimCounts); const channelClaimCounts = Object.assign({}, state.channelClaimCounts);
const pendingIds = state.pendingIds;
let newResolvingUrls = new Set(state.resolvingUris); let newResolvingUrls = new Set(state.resolvingUris);
Object.entries(resolveInfo).forEach(([url: string, resolveResponse: ResolveResponse]) => { Object.entries(resolveInfo).forEach(([url: string, resolveResponse: ResolveResponse]) => {
// $FlowFixMe // $FlowFixMe
const { claimsInChannel, stream, channel } = resolveResponse; const { claimsInChannel, stream, channel } = resolveResponse;
if (claimsInChannel) {
channelClaimCounts[url] = claimsInChannel;
channelClaimCounts[channel.canonical_url] = claimsInChannel;
}
if (stream) { if (stream) {
if (pendingIds.includes(stream.claim_id)) { byId[stream.claim_id] = stream;
byId[stream.claim_id] = mergeClaim(stream, byId[stream.claim_id]);
} else {
byId[stream.claim_id] = stream;
}
byUri[url] = stream.claim_id; byUri[url] = stream.claim_id;
// If url isn't a canonical_url, make sure that is added too // If url isn't a canonical_url, make sure that is added too
@ -136,18 +135,12 @@ function handleClaimAction(state: State, action: any): State {
newResolvingUrls.delete(stream.permanent_url); newResolvingUrls.delete(stream.permanent_url);
} }
if (channel && channel.claim_id) { if (channel) {
if (claimsInChannel) { if (!stream) {
channelClaimCounts[url] = claimsInChannel; byUri[url] = channel.claim_id;
channelClaimCounts[channel.canonical_url] = claimsInChannel;
} }
byUri[url] = channel.claim_id;
if (pendingIds.includes(channel.claim_id)) { byId[channel.claim_id] = channel;
byId[channel.claim_id] = mergeClaim(channel, byId[channel.claim_id]);
} else {
byId[channel.claim_id] = channel;
}
// Also add the permanent_url here until lighthouse returns canonical_url for search results // Also add the permanent_url here until lighthouse returns canonical_url for search results
byUri[channel.permanent_url] = channel.claim_id; byUri[channel.permanent_url] = channel.claim_id;
byUri[channel.canonical_url] = channel.claim_id; byUri[channel.canonical_url] = channel.claim_id;
@ -205,37 +198,47 @@ reducers[ACTIONS.FETCH_CLAIM_LIST_MINE_COMPLETED] = (state: State, action: any):
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 pendingIds = state.pendingIds || []; const pendingById: { [string]: Claim } = Object.assign({}, state.pendingById);
let myClaimIds = new Set(state.myClaims); let myClaimIds = new Set(state.myClaims);
let urlsForCurrentPage = []; let urlsForCurrentPage = [];
const pendingIdSet = new Set(pendingIds);
claims.forEach((claim: Claim) => { claims.forEach((claim: Claim) => {
const { permanent_url: permanentUri, claim_id: claimId } = claim; const uri = buildURI({ streamName: claim.name, streamClaimId: claim.claim_id });
const { claim_id: claimId } = claim;
if (claim.type && claim.type.match(/claim|update/)) { if (claim.type && claim.type.match(/claim|update/)) {
urlsForCurrentPage.push(permanentUri); urlsForCurrentPage.push(uri);
if (claim.confirmations < 1) { if (claim.confirmations < 1) {
pendingIdSet.add(claimId); pendingById[claimId] = claim;
} else if (!resolve && pendingIdSet.has(claimId) && claim.confirmations > 0) { delete byId[claimId];
pendingIdSet.delete(claimId); delete byUri[claimId];
}
if (pendingIds.includes(claimId)) {
byId[claimId] = mergeClaim(claim, byId[claimId]);
} else { } else {
byId[claimId] = claim; byId[claimId] = claim;
byUri[uri] = claimId;
} }
byUri[permanentUri] = claimId;
myClaimIds.add(claimId); myClaimIds.add(claimId);
if (!resolve && pendingById[claimId] && claim.confirmations > 0) {
delete pendingById[claimId];
}
} }
}); });
// Remove old pending publishes if resolve if false (resolve=true means confirmations on updates are not 0)
if (!resolve) {
Object.values(pendingById)
// $FlowFixMe
.filter(pendingClaim => byId[pendingClaim.claim_id])
.forEach(pendingClaim => {
// $FlowFixMe
delete pendingById[pendingClaim.claim_id];
});
}
return Object.assign({}, state, { return Object.assign({}, state, {
isFetchingClaimListMine: false, isFetchingClaimListMine: false,
myClaims: Array.from(myClaimIds), myClaims: Array.from(myClaimIds),
byId, byId,
pendingIds: Array.from(pendingIdSet),
claimsByUri: byUri, claimsByUri: byUri,
pendingById,
myClaimsPageResults: urlsForCurrentPage, myClaimsPageResults: urlsForCurrentPage,
myClaimsPageNumber: page, myClaimsPageNumber: page,
myClaimsPageTotalResults: totalItems, myClaimsPageTotalResults: totalItems,
@ -249,7 +252,7 @@ reducers[ACTIONS.FETCH_CHANNEL_LIST_COMPLETED] = (state: State, action: any): St
const { claims }: { claims: Array<ChannelClaim> } = action.data; const { claims }: { claims: Array<ChannelClaim> } = action.data;
const myClaims = state.myClaims || []; const myClaims = state.myClaims || [];
let myClaimIds = new Set(state.myClaims); let myClaimIds = new Set(state.myClaims);
const pendingIds = state.pendingIds || []; const pendingById = Object.assign(state.pendingById);
let myChannelClaims; let myChannelClaims;
const byId = Object.assign({}, state.byId); const byId = Object.assign({}, state.byId);
const byUri = Object.assign({}, state.claimsByUri); const byUri = Object.assign({}, state.claimsByUri);
@ -272,10 +275,18 @@ reducers[ACTIONS.FETCH_CHANNEL_LIST_COMPLETED] = (state: State, action: any): St
// $FlowFixMe // $FlowFixMe
myChannelClaims.add(claimId); myChannelClaims.add(claimId);
if (!pendingIds.some(c => c === claimId)) { if (!byId[claimId]) {
byId[claimId] = claim; byId[claimId] = claim;
} }
myClaimIds.add(claimId); myClaimIds.add(claimId);
if (pendingById[claimId] && claim.confirmations > 0) {
delete pendingById[claimId];
}
if (pendingById[claimId] && claim.confirmations > 0) {
delete pendingById[claimId];
}
}); });
} }
@ -285,7 +296,7 @@ reducers[ACTIONS.FETCH_CHANNEL_LIST_COMPLETED] = (state: State, action: any): St
channelClaimCounts, channelClaimCounts,
fetchingMyChannels: false, fetchingMyChannels: false,
myChannelClaims: myChannelClaims ? Array.from(myChannelClaims) : null, myChannelClaims: myChannelClaims ? Array.from(myChannelClaims) : null,
myClaims: myClaimIds ? Array.from(myClaimIds) : null, myClaims: Array.from(myClaimIds),
}); });
}; };
@ -374,31 +385,19 @@ 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: pendingClaims }: { claims: Array<Claim> } = 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 pendingIds = state.pendingIds; const pendingById: { [string]: Claim } = Object.assign({}, state.pendingById);
const pendingIdSet = new Set(pendingIds);
let myClaimIds = new Set(state.myClaims); let myClaimIds = new Set(state.myClaims);
const myChannelClaims = new Set(state.myChannelClaims);
// $FlowFixMe // $FlowFixMe
pendingClaims.forEach((claim: Claim) => { claims.forEach((claim: Claim) => {
let newClaim; const uri = buildURI({ streamName: claim.name, streamClaimId: claim.claim_id });
const { permanent_url: uri, claim_id: claimId, type, value_type: valueType } = claim; const { claim_id: claimId } = claim;
pendingIdSet.add(claimId); if (claim.type && claim.type.match(/claim|update/)) {
const oldClaim = byId[claimId]; pendingById[claimId] = claim;
if (oldClaim && oldClaim.canonical_url) { delete byId[claimId];
newClaim = mergeClaim(oldClaim, claim);
} else {
newClaim = claim;
}
if (valueType === 'channel') {
myChannelClaims.add(claimId);
}
if (type && type.match(/claim|update/)) {
byId[claimId] = newClaim;
byUri[uri] = claimId; byUri[uri] = claimId;
} }
myClaimIds.add(claimId); myClaimIds.add(claimId);
@ -406,35 +405,32 @@ reducers[ACTIONS.UPDATE_PENDING_CLAIMS] = (state: State, action: any): State =>
return Object.assign({}, state, { return Object.assign({}, state, {
myClaims: Array.from(myClaimIds), myClaims: Array.from(myClaimIds),
byId, byId,
myChannelClaims: Array.from(myChannelClaims),
claimsByUri: byUri, claimsByUri: byUri,
pendingIds: Array.from(pendingIdSet), pendingById,
}); });
}; };
reducers[ACTIONS.UPDATE_CONFIRMED_CLAIMS] = (state: State, action: any): State => { reducers[ACTIONS.UPDATE_CONFIRMED_CLAIMS] = (state: State, action: any): State => {
const { claims: confirmedClaims }: { claims: Array<Claim> } = 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 pendingIds = state.pendingIds; const pendingById: { [string]: Claim } = Object.assign({}, state.pendingById);
const pendingIdSet = new Set(pendingIds); let myClaimIds = new Set(state.myClaims);
confirmedClaims.forEach((claim: GenericClaim) => { claims.forEach((claim: GenericClaim) => {
const { permanent_url: permanentUri, claim_id: claimId, type } = claim; const uri = buildURI({ streamName: claim.name, streamClaimId: claim.claim_id });
let newClaim = claim; const { claim_id: claimId } = claim;
const oldClaim = byId[claimId]; if (claim.type && claim.type.match(/claim|update/)) {
if (oldClaim && oldClaim.canonical_url) { delete pendingById[claimId];
newClaim = mergeClaim(oldClaim, claim); byId[claimId] = claim;
}
if (type && type.match(/claim|update|channel/)) {
byId[claimId] = newClaim;
pendingIdSet.delete(claimId);
} }
myClaimIds.add(claimId);
}); });
return Object.assign({}, state, { return Object.assign({}, state, {
pendingIds: Array.from(pendingIdSet), myClaims: Array.from(myClaimIds),
byId, byId,
claimsByUri: byUri, claimsByUri: byUri,
pendingById,
}); });
}; };
@ -470,7 +466,19 @@ reducers[ACTIONS.CREATE_CHANNEL_STARTED] = (state: State): State => ({
}); });
reducers[ACTIONS.CREATE_CHANNEL_COMPLETED] = (state: State, action: any): State => { reducers[ACTIONS.CREATE_CHANNEL_COMPLETED] = (state: State, action: any): State => {
const channelClaim: ChannelClaim = action.data.channelClaim;
const byId = Object.assign({}, state.byId);
const pendingById = Object.assign({}, state.pendingById);
const myChannelClaims = new Set(state.myChannelClaims);
byId[channelClaim.claim_id] = channelClaim;
pendingById[channelClaim.claim_id] = channelClaim;
myChannelClaims.add(channelClaim.claim_id);
return Object.assign({}, state, { return Object.assign({}, state, {
byId,
pendingById,
myChannelClaims: Array.from(myChannelClaims),
creatingChannel: false, creatingChannel: false,
}); });
}; };
@ -490,7 +498,13 @@ reducers[ACTIONS.UPDATE_CHANNEL_STARTED] = (state: State, action: any): State =>
}; };
reducers[ACTIONS.UPDATE_CHANNEL_COMPLETED] = (state: State, action: any): State => { reducers[ACTIONS.UPDATE_CHANNEL_COMPLETED] = (state: State, action: any): State => {
const channelClaim: ChannelClaim = action.data.channelClaim;
const byId = Object.assign({}, state.byId);
byId[channelClaim.claim_id] = channelClaim;
return Object.assign({}, state, { return Object.assign({}, state, {
byId,
updateChannelError: '', updateChannelError: '',
updatingChannel: false, updatingChannel: false,
}); });

View file

@ -6,7 +6,7 @@ import {
} from 'redux/selectors/search'; } from 'redux/selectors/search';
import { selectSupportsByOutpoint } from 'redux/selectors/wallet'; import { selectSupportsByOutpoint } from 'redux/selectors/wallet';
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
import { isClaimNsfw, filterClaims } from 'util/claim'; import { isClaimNsfw, createNormalizedClaimSearchKey, filterClaims } from 'util/claim';
import { getSearchQueryString } from 'util/query-params'; import { getSearchQueryString } from 'util/query-params';
import { PAGE_SIZE } from 'constants/claim'; import { PAGE_SIZE } from 'constants/claim';
@ -48,9 +48,10 @@ export const selectRepostError = createSelector(
); );
export const selectClaimsByUri = createSelector( export const selectClaimsByUri = createSelector(
selectClaimIdsByUri, selectState,
selectClaimsById, selectClaimsById,
(byUri, byId) => { (state, byId) => {
const byUri = state.claimsByUri || {};
const claims = {}; const claims = {};
Object.keys(byUri).forEach(uri => { Object.keys(byUri).forEach(uri => {
@ -75,25 +76,42 @@ export const selectAllClaimsByChannel = createSelector(
state => state.paginatedClaimsByChannel || {} state => state.paginatedClaimsByChannel || {}
); );
export const selectPendingIds = createSelector( export const selectPendingById = createSelector(
selectState, selectState,
state => state.pendingIds || [] state => state.pendingById || {}
);
export const selectPendingClaims = createSelector(
selectState,
state => Object.values(state.pendingById || [])
); );
export const makeSelectClaimIsPending = (uri: string) => export const makeSelectClaimIsPending = (uri: string) =>
createSelector( createSelector(
selectClaimIdsByUri, selectPendingById,
selectPendingIds, pendingById => {
(idsByUri, pendingIds) => { let claimId;
const claimId = idsByUri[normalizeURI(uri)];
try {
const { isChannel, channelClaimId, streamClaimId } = parseURI(uri);
claimId = isChannel ? channelClaimId : streamClaimId;
} catch (e) {}
if (claimId) { if (claimId) {
return pendingIds.some(i => i === claimId); return Boolean(pendingById[claimId]);
} }
return false;
} }
); );
export const makeSelectPendingByUri = (uri: string) =>
createSelector(
selectPendingById,
pendingById => {
const { isChannel, channelClaimId, streamClaimId } = parseURI(uri);
const claimId = isChannel ? channelClaimId : streamClaimId;
return pendingById[claimId];
}
);
export const selectReflectingById = createSelector( export const selectReflectingById = createSelector(
selectState, selectState,
state => state.reflectingById state => state.reflectingById
@ -101,21 +119,30 @@ export const selectReflectingById = createSelector(
export const makeSelectClaimForUri = (uri: string, returnRepost: boolean = true) => export const makeSelectClaimForUri = (uri: string, returnRepost: boolean = true) =>
createSelector( createSelector(
selectClaimIdsByUri, selectClaimsByUri,
selectClaimsById, selectPendingById,
(byUri, byId) => { (byUri, pendingById) => {
let validUri; // Check if a claim is pending first
// It won't be in claimsByUri because resolving it will return nothing
let valid;
let channelClaimId; let channelClaimId;
let streamClaimId; let streamClaimId;
let isChannel; let isChannel;
try { try {
({ isChannel, channelClaimId, streamClaimId } = parseURI(uri)); ({ isChannel, channelClaimId, streamClaimId } = parseURI(uri));
validUri = true; valid = true;
} catch (e) {} } catch (e) {}
if (validUri && byUri) { if (valid && byUri) {
const claimId = uri && byUri[normalizeURI(uri)]; const claimId = isChannel ? channelClaimId : streamClaimId;
const claim = byId[claimId]; const pendingClaim = pendingById[claimId];
if (pendingClaim) {
return pendingClaim;
}
const claim = byUri[normalizeURI(uri)];
if (claim === undefined || claim === null) { if (claim === undefined || claim === null) {
// Make sure to return the claim as is so apps can check if it's been resolved before (null) or still needs to be resolved (undefined) // Make sure to return the claim as is so apps can check if it's been resolved before (null) or still needs to be resolved (undefined)
return claim; return claim;
@ -429,7 +456,8 @@ export const selectMyClaims = createSelector(
selectMyActiveClaims, selectMyActiveClaims,
selectClaimsById, selectClaimsById,
selectAbandoningIds, selectAbandoningIds,
(myClaimIds, byId, abandoningIds) => { selectPendingClaims,
(myClaimIds, byId, abandoningIds, pendingClaims) => {
const claims = []; const claims = [];
myClaimIds.forEach(id => { myClaimIds.forEach(id => {
@ -438,7 +466,7 @@ export const selectMyClaims = createSelector(
if (claim && abandoningIds.indexOf(id) === -1) claims.push(claim); if (claim && abandoningIds.indexOf(id) === -1) claims.push(claim);
}); });
return [...claims]; return [...claims, ...pendingClaims];
} }
); );
@ -510,11 +538,6 @@ export const selectMyChannelClaims = createSelector(
} }
); );
export const selectMyChannelUrls = createSelector(
selectMyChannelClaims,
claims => claims ? claims.map(claim => claim.canonical_url || claim.permanent_url) : undefined
);
export const selectResolvingUris = createSelector( export const selectResolvingUris = createSelector(
selectState, selectState,
state => state.resolvingUris || [] state => state.resolvingUris || []

View file

@ -1,7 +0,0 @@
/*
new claim = { ...maybeResolvedClaim, ...pendingClaim, meta: maybeResolvedClaim['meta'] }
*/
export default function mergeClaims(maybeResolved, pending){
return { ...maybeResolved, ...pending, meta: maybeResolved.meta };
}