simplify claims resolve reducer
This commit is contained in:
parent
85c24ae37d
commit
50d1b166f5
4 changed files with 34 additions and 30 deletions
4
flow-typed/Claim.js
vendored
4
flow-typed/Claim.js
vendored
|
@ -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,
|
||||
};
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ export function doResolveUris(uris: Array<string>, returnCachedClaims: boolean =
|
|||
resolveInfo[uri] = { ...fallbackResolveInfo };
|
||||
} else {
|
||||
let result = {};
|
||||
if (uriResolveInfo.value_type === 'channel' ) {
|
||||
if (uriResolveInfo.value_type === 'channel') {
|
||||
result.channel = uriResolveInfo;
|
||||
// $FlowFixMe
|
||||
result.claimsInChannel = uriResolveInfo.meta.claims_in_channel;
|
||||
|
@ -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,20 +196,23 @@ 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) => {
|
||||
const { items: claimsInChannel, page: returnedPage } = result;
|
||||
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({
|
||||
type: ACTIONS.FETCH_CHANNEL_CLAIMS_COMPLETED,
|
||||
data: {
|
||||
uri,
|
||||
claims: claimsInChannel || [],
|
||||
page: returnedPage || undefined,
|
||||
},
|
||||
});
|
||||
}
|
||||
);
|
||||
dispatch({
|
||||
type: ACTIONS.FETCH_CHANNEL_CLAIMS_COMPLETED,
|
||||
data: {
|
||||
uri,
|
||||
claims: claimsInChannel || [],
|
||||
page: returnedPage || undefined,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue