Run 'claim_search' with 'has_no_source' to bring up buried active livestreams.
Scenarios where active livestreams will not appear: - creation date is way back. - homepage section options excludes livestreams. Make an explicit `claim_search` but with `has_no_source` if the client wants `liveLivestreamsFirst`. If there are lots of channels with livestreams, there's a possibility that the final list will be larger than what was requested. We could trim it to be within the original `options.pageSize` range, but I left that out for now.
This commit is contained in:
parent
41380d20df
commit
6ef42cd121
2 changed files with 41 additions and 13 deletions
|
@ -40,8 +40,7 @@ type Props = {
|
||||||
limitClaimsPerChannel?: number,
|
limitClaimsPerChannel?: number,
|
||||||
hasNoSource?: boolean,
|
hasNoSource?: boolean,
|
||||||
renderProperties?: (Claim) => ?Node,
|
renderProperties?: (Claim) => ?Node,
|
||||||
// Passing in 'livestreamMap' indicates that we want to sort "live"
|
liveLivestreamsFirst?: boolean,
|
||||||
// livestreams first, and also embelish the "live" tiles.
|
|
||||||
livestreamMap?: { [string]: any },
|
livestreamMap?: { [string]: any },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -71,6 +70,7 @@ function ClaimTilesDiscover(props: Props) {
|
||||||
renderProperties,
|
renderProperties,
|
||||||
blockedUris,
|
blockedUris,
|
||||||
mutedUris,
|
mutedUris,
|
||||||
|
liveLivestreamsFirst,
|
||||||
livestreamMap,
|
livestreamMap,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
|
@ -156,25 +156,50 @@ function ClaimTilesDiscover(props: Props) {
|
||||||
const claimSearchCacheQuery = createNormalizedClaimSearchKey(options);
|
const claimSearchCacheQuery = createNormalizedClaimSearchKey(options);
|
||||||
let uris = (prefixUris || []).concat(claimSearchByQuery[claimSearchCacheQuery] || []);
|
let uris = (prefixUris || []).concat(claimSearchByQuery[claimSearchCacheQuery] || []);
|
||||||
|
|
||||||
// Push active livestreams to the front:
|
if (liveLivestreamsFirst && livestreamMap) {
|
||||||
if (livestreamMap) {
|
let liveChannelIds = Object.keys(livestreamMap);
|
||||||
const liveChannelIds = Object.keys(livestreamMap);
|
|
||||||
|
|
||||||
uris.forEach((uri) => {
|
const claimIsLive = (claim, liveChannelIds) => {
|
||||||
const claim = claimsByUri[uri];
|
// This function relies on:
|
||||||
if (
|
// 1. Only 1 actual livestream per channel (i.e. all other livestream-claims
|
||||||
|
// for that channel actually point to the same source).
|
||||||
|
// 2. 'liveChannelIds' needs to be pruned after being accounted for,
|
||||||
|
// otherwise all livestream-claims will be "live" (we'll only take the
|
||||||
|
// latest one as "live").
|
||||||
|
return (
|
||||||
claim &&
|
claim &&
|
||||||
claim.value_type === 'stream' &&
|
claim.value_type === 'stream' &&
|
||||||
claim.value.source === undefined &&
|
claim.value.source === undefined &&
|
||||||
claim.signing_channel &&
|
claim.signing_channel &&
|
||||||
liveChannelIds.includes(claim.signing_channel.claim_id)
|
liveChannelIds.includes(claim.signing_channel.claim_id)
|
||||||
) {
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 1. Collect active livestreams from the primary search to put in front.
|
||||||
|
uris.forEach((uri) => {
|
||||||
|
const claim = claimsByUri[uri];
|
||||||
|
if (claimIsLive(claim, liveChannelIds)) {
|
||||||
liveUris.push(uri);
|
liveUris.push(uri);
|
||||||
// This live channel has been accounted for, so ignore it's older livestreams:
|
// This live channel has been accounted for, so remove it.
|
||||||
liveChannelIds.splice(liveChannelIds.indexOf(claim.signing_channel.claim_id), 1);
|
liveChannelIds.splice(liveChannelIds.indexOf(claim.signing_channel.claim_id), 1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 2. Now, repeat on the secondary search.
|
||||||
|
const livestreamsOnlySearchCacheQuery = createNormalizedClaimSearchKey({ ...options, has_no_source: true });
|
||||||
|
const livestreamsOnlyUris = claimSearchByQuery[livestreamsOnlySearchCacheQuery];
|
||||||
|
if (livestreamsOnlyUris) {
|
||||||
|
livestreamsOnlyUris.forEach((uri) => {
|
||||||
|
const claim = claimsByUri[uri];
|
||||||
|
if (!uris.includes(uri) && claimIsLive(claim, liveChannelIds)) {
|
||||||
|
liveUris.push(uri);
|
||||||
|
// This live channel has been accounted for, so remove it.
|
||||||
|
liveChannelIds.splice(liveChannelIds.indexOf(claim.signing_channel.claim_id), 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Finalize uris by putting live livestreams in front.
|
||||||
uris = liveUris.concat(uris.filter((uri) => !liveUris.includes(uri)));
|
uris = liveUris.concat(uris.filter((uri) => !liveUris.includes(uri)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,11 +212,14 @@ function ClaimTilesDiscover(props: Props) {
|
||||||
if (shouldPerformSearch) {
|
if (shouldPerformSearch) {
|
||||||
const searchOptions = JSON.parse(optionsStringForEffect);
|
const searchOptions = JSON.parse(optionsStringForEffect);
|
||||||
doClaimSearch(searchOptions);
|
doClaimSearch(searchOptions);
|
||||||
|
if (liveLivestreamsFirst) {
|
||||||
|
doClaimSearch({ ...searchOptions, has_no_source: true });
|
||||||
}
|
}
|
||||||
}, [doClaimSearch, shouldPerformSearch, optionsStringForEffect]);
|
}
|
||||||
|
}, [doClaimSearch, shouldPerformSearch, optionsStringForEffect, liveLivestreamsFirst]);
|
||||||
|
|
||||||
const resolveLive = (index) => {
|
const resolveLive = (index) => {
|
||||||
if (livestreamMap && index < liveUris.length) {
|
if (liveLivestreamsFirst && livestreamMap && index < liveUris.length) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|
|
@ -93,7 +93,7 @@ function HomePage(props: Props) {
|
||||||
</h1>
|
</h1>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<ClaimTilesDiscover {...options} livestreamMap={livestreamMap} />
|
<ClaimTilesDiscover {...options} liveLivestreamsFirst livestreamMap={livestreamMap} />
|
||||||
{(route || link) && (
|
{(route || link) && (
|
||||||
<Button
|
<Button
|
||||||
className="claim-grid__title--secondary"
|
className="claim-grid__title--secondary"
|
||||||
|
|
Loading…
Reference in a new issue