fix RESOLVE_URIS_COMPLETED, to have one large action instead of hundr… (#798)
* fix RESOLVE_URIS_COMPLETED, to have one large action instead of hundreds of small ones * Addressed comments. * Addressed comments. * Addressed comments. Co-authored-by: Asad Umar <au@visuary.fr>
This commit is contained in:
parent
231ac139d4
commit
65ad2df643
1 changed files with 54 additions and 33 deletions
|
@ -185,35 +185,6 @@ export const doFetchItemsInCollections = (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatForClaimActions(resultClaimsByUri) {
|
|
||||||
const formattedClaims = {};
|
|
||||||
Object.entries(resultClaimsByUri).forEach(([uri, uriResolveInfo]) => {
|
|
||||||
// Flow has terrible Object.entries support
|
|
||||||
// https://github.com/facebook/flow/issues/2221
|
|
||||||
if (uriResolveInfo) {
|
|
||||||
let result = {};
|
|
||||||
if (uriResolveInfo.value_type === 'channel') {
|
|
||||||
result.channel = uriResolveInfo;
|
|
||||||
// $FlowFixMe
|
|
||||||
result.claimsInChannel = uriResolveInfo.meta.claims_in_channel;
|
|
||||||
// ALSO SKIP COLLECTIONS
|
|
||||||
} else if (uriResolveInfo.value_type === 'collection') {
|
|
||||||
result.collection = uriResolveInfo;
|
|
||||||
} else {
|
|
||||||
result.stream = uriResolveInfo;
|
|
||||||
if (uriResolveInfo.signing_channel) {
|
|
||||||
result.channel = uriResolveInfo.signing_channel;
|
|
||||||
result.claimsInChannel =
|
|
||||||
(uriResolveInfo.signing_channel.meta && uriResolveInfo.signing_channel.meta.claims_in_channel) || 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// $FlowFixMe
|
|
||||||
formattedClaims[uri] = result;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return formattedClaims;
|
|
||||||
}
|
|
||||||
|
|
||||||
const invalidCollectionIds = [];
|
const invalidCollectionIds = [];
|
||||||
const promisedCollectionItemFetches = [];
|
const promisedCollectionItemFetches = [];
|
||||||
collectionIds.forEach((collectionId) => {
|
collectionIds.forEach((collectionId) => {
|
||||||
|
@ -287,11 +258,18 @@ export const doFetchItemsInCollections = (
|
||||||
invalidCollectionIds.push(collectionId);
|
invalidCollectionIds.push(collectionId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const formattedClaimsByUri = formatForClaimActions(collectionItemsById);
|
|
||||||
|
|
||||||
dispatch({
|
const resolveInfo: ClaimActionResolveInfo = {};
|
||||||
type: ACTIONS.RESOLVE_URIS_COMPLETED,
|
|
||||||
data: { resolveInfo: formattedClaimsByUri },
|
const resolveReposts = true;
|
||||||
|
|
||||||
|
collectionItemsById.forEach((collection) => {
|
||||||
|
// GenericClaim type probably needs to be updated to avoid this "Any"
|
||||||
|
collection.items &&
|
||||||
|
collection.items.forEach((result: any) => {
|
||||||
|
result = { [result.canonical_url]: result };
|
||||||
|
processResult(result, resolveInfo, resolveReposts);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
|
@ -301,8 +279,51 @@ export const doFetchItemsInCollections = (
|
||||||
failedCollectionIds: invalidCollectionIds,
|
failedCollectionIds: invalidCollectionIds,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.RESOLVE_URIS_COMPLETED,
|
||||||
|
data: { resolveInfo },
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function processResult(result, resolveInfo = {}, checkReposts = false) {
|
||||||
|
const fallbackResolveInfo = {
|
||||||
|
stream: null,
|
||||||
|
claimsInChannel: null,
|
||||||
|
channel: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.entries(result).forEach(([uri, uriResolveInfo]) => {
|
||||||
|
// Flow has terrible Object.entries support
|
||||||
|
// https://github.com/facebook/flow/issues/2221
|
||||||
|
if (uriResolveInfo) {
|
||||||
|
if (uriResolveInfo.error) {
|
||||||
|
// $FlowFixMe
|
||||||
|
resolveInfo[uri] = { ...fallbackResolveInfo };
|
||||||
|
} else {
|
||||||
|
let result = {};
|
||||||
|
if (uriResolveInfo.value_type === 'channel') {
|
||||||
|
result.channel = uriResolveInfo;
|
||||||
|
// $FlowFixMe
|
||||||
|
result.claimsInChannel = uriResolveInfo.meta.claims_in_channel;
|
||||||
|
} else if (uriResolveInfo.value_type === 'collection') {
|
||||||
|
result.collection = uriResolveInfo;
|
||||||
|
// $FlowFixMe
|
||||||
|
} else {
|
||||||
|
result.stream = uriResolveInfo;
|
||||||
|
if (uriResolveInfo.signing_channel) {
|
||||||
|
result.channel = uriResolveInfo.signing_channel;
|
||||||
|
result.claimsInChannel =
|
||||||
|
(uriResolveInfo.signing_channel.meta && uriResolveInfo.signing_channel.meta.claims_in_channel) || 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// $FlowFixMe
|
||||||
|
resolveInfo[uri] = result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export const doFetchItemsInCollection = (options: { collectionId: string, pageSize?: number }, cb?: () => void) => {
|
export const doFetchItemsInCollection = (options: { collectionId: string, pageSize?: number }, cb?: () => void) => {
|
||||||
const { collectionId, pageSize } = options;
|
const { collectionId, pageSize } = options;
|
||||||
const newOptions: { collectionIds: Array<string>, pageSize?: number } = {
|
const newOptions: { collectionIds: Array<string>, pageSize?: number } = {
|
||||||
|
|
Loading…
Reference in a new issue