simplify claims resolve reducer

This commit is contained in:
Sean Yesmunt 2019-06-09 21:25:55 -04:00
parent 85c24ae37d
commit 50d1b166f5
4 changed files with 34 additions and 30 deletions

4
flow-typed/Claim.js vendored
View file

@ -4,13 +4,13 @@ declare type Claim = StreamClaim | ChannelClaim;
declare type ChannelClaim = GenericClaim & {
is_channel_signature_valid?: boolean, // we may have signed channels in the future, fixes some flow issues for now.
signing_channel?: ChannelMetadata,
signing_channel?: ChannelClaim,
value: ChannelMetadata,
};
declare type StreamClaim = GenericClaim & {
is_channel_signature_valid?: boolean,
signing_channel?: ChannelMetadata,
signing_channel?: ChannelClaim,
value: StreamMetadata,
};

View file

@ -63,7 +63,8 @@ export function doResolveUris(uris: Array<string>, returnCachedClaims: boolean =
result.stream = uriResolveInfo;
if (uriResolveInfo.signing_channel) {
result.channel = uriResolveInfo.signing_channel;
result.claimsInChannel = uriResolveInfo.signing_channel.meta.claims_in_channel;
result.claimsInChannel =
(uriResolveInfo.meta && uriResolveInfo.meta.claims_in_channel) || 0;
}
}
@ -195,8 +196,12 @@ export function doFetchClaimsByChannel(uri: string, page: number = 1) {
data: { uri, page },
});
Lbry.claim_search({ channel: uri, is_controlling: true, page: page || 1, order_by: ['release_time'] }).then(
(result: ClaimSearchResponse) => {
Lbry.claim_search({
channel: uri,
is_controlling: true,
page: page || 1,
order_by: ['release_time'],
}).then((result: ClaimSearchResponse) => {
const { items: claimsInChannel, page: returnedPage } = result;
dispatch({
@ -207,8 +212,7 @@ export function doFetchClaimsByChannel(uri: string, page: number = 1) {
page: returnedPage || undefined,
},
});
}
);
});
};
}

View file

@ -69,20 +69,15 @@ reducers[ACTIONS.RESOLVE_URIS_COMPLETED] = (state: State, action: any): State =>
// $FlowFixMe
Object.entries(resolveInfo).forEach(([uri, { channel, stream }]) => {
if (stream && !channel) {
if (stream) {
byId[stream.claim_id] = stream;
byUri[uri] = stream.claim_id;
} else if (stream && channel) {
byId[stream.claim_id] = stream;
byUri[uri] = stream.claim_id;
}
if (channel) {
byId[channel.claim_id] = channel;
const channelUri = channel.permanent_url;
byUri[channelUri] = channel.claim_id;
} else if (!stream && channel) {
byId[channel.claim_id] = channel;
byUri[uri] = channel.claim_id;
} else {
byUri[stream ? channel.permanent_url : uri] = channel.claim_id;
}
if (!stream && !channel) {
byUri[uri] = null;
}
});

View file

@ -190,7 +190,12 @@ export const makeSelectDateForUri = (uri: string) =>
createSelector(
makeSelectClaimForUri(uri),
claim => {
const timestamp = claim && claim.value && (claim.value.release_time ? claim.value.release_time * 1000 : claim.meta.creation_timestamp * 1000);
const timestamp =
claim &&
claim.value &&
(claim.value.release_time
? claim.value.release_time * 1000
: claim.meta.creation_timestamp * 1000);
if (!timestamp) {
return undefined;
}
@ -418,7 +423,7 @@ export const makeSelectFirstRecommendedFileForUri = (uri: string) =>
export const makeSelectChannelForClaimUri = (uri: string, includePrefix: boolean = false) =>
createSelector(
makeSelectClaimForUri(uri),
(claim: ?Claim) => {
(claim: ?StreamClaim) => {
if (!claim || !claim.signing_channel) {
return null;
}