Livestream-only query cleanup. (#6036)
This completes the change in c24c016e
, covering ClaimListDiscover as well.
This commit is contained in:
parent
e5795baa10
commit
c85d7f12c8
3 changed files with 32 additions and 43 deletions
|
@ -14,6 +14,7 @@ import ClaimPreviewTile from 'component/claimPreviewTile';
|
||||||
import I18nMessage from 'component/i18nMessage';
|
import I18nMessage from 'component/i18nMessage';
|
||||||
import ClaimListHeader from 'component/claimListHeader';
|
import ClaimListHeader from 'component/claimListHeader';
|
||||||
import { useIsLargeScreen } from 'effects/use-screensize';
|
import { useIsLargeScreen } from 'effects/use-screensize';
|
||||||
|
import { getLivestreamOnlyOptions } from 'util/search';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
uris: Array<string>,
|
uris: Array<string>,
|
||||||
|
@ -23,11 +24,11 @@ type Props = {
|
||||||
doClaimSearch: ({}) => void,
|
doClaimSearch: ({}) => void,
|
||||||
loading: boolean,
|
loading: boolean,
|
||||||
personalView: boolean,
|
personalView: boolean,
|
||||||
doToggleTagFollowDesktop: string => void,
|
doToggleTagFollowDesktop: (string) => void,
|
||||||
meta?: Node,
|
meta?: Node,
|
||||||
showNsfw: boolean,
|
showNsfw: boolean,
|
||||||
hideReposts: boolean,
|
hideReposts: boolean,
|
||||||
history: { action: string, push: string => void, replace: string => void },
|
history: { action: string, push: (string) => void, replace: (string) => void },
|
||||||
location: { search: string, pathname: string },
|
location: { search: string, pathname: string },
|
||||||
claimSearchByQuery: {
|
claimSearchByQuery: {
|
||||||
[string]: Array<string>,
|
[string]: Array<string>,
|
||||||
|
@ -52,7 +53,7 @@ type Props = {
|
||||||
defaultClaimType?: Array<string>,
|
defaultClaimType?: Array<string>,
|
||||||
streamType?: string | Array<string>,
|
streamType?: string | Array<string>,
|
||||||
defaultStreamType?: string | Array<string>,
|
defaultStreamType?: string | Array<string>,
|
||||||
renderProperties?: Claim => Node,
|
renderProperties?: (Claim) => Node,
|
||||||
includeSupportAction?: boolean,
|
includeSupportAction?: boolean,
|
||||||
repostedClaimId?: string,
|
repostedClaimId?: string,
|
||||||
pageSize?: number,
|
pageSize?: number,
|
||||||
|
@ -133,14 +134,14 @@ function ClaimListDiscover(props: Props) {
|
||||||
const isLargeScreen = useIsLargeScreen();
|
const isLargeScreen = useIsLargeScreen();
|
||||||
const [orderParamEntry, setOrderParamEntry] = usePersistedState(`entry-${location.pathname}`, CS.ORDER_BY_TRENDING);
|
const [orderParamEntry, setOrderParamEntry] = usePersistedState(`entry-${location.pathname}`, CS.ORDER_BY_TRENDING);
|
||||||
const [orderParamUser, setOrderParamUser] = usePersistedState(`orderUser-${location.pathname}`, CS.ORDER_BY_TRENDING);
|
const [orderParamUser, setOrderParamUser] = usePersistedState(`orderUser-${location.pathname}`, CS.ORDER_BY_TRENDING);
|
||||||
const followed = (followedTags && followedTags.map(t => t.name)) || [];
|
const followed = (followedTags && followedTags.map((t) => t.name)) || [];
|
||||||
const urlParams = new URLSearchParams(search);
|
const urlParams = new URLSearchParams(search);
|
||||||
const tagsParam = // can be 'x,y,z' or 'x' or ['x','y'] or CS.CONSTANT
|
const tagsParam = // can be 'x,y,z' or 'x' or ['x','y'] or CS.CONSTANT
|
||||||
(tags && getParamFromTags(tags)) ||
|
(tags && getParamFromTags(tags)) ||
|
||||||
(urlParams.get(CS.TAGS_KEY) !== null && urlParams.get(CS.TAGS_KEY)) ||
|
(urlParams.get(CS.TAGS_KEY) !== null && urlParams.get(CS.TAGS_KEY)) ||
|
||||||
(defaultTags && getParamFromTags(defaultTags));
|
(defaultTags && getParamFromTags(defaultTags));
|
||||||
const freshnessParam = freshness || urlParams.get(CS.FRESH_KEY) || defaultFreshness;
|
const freshnessParam = freshness || urlParams.get(CS.FRESH_KEY) || defaultFreshness;
|
||||||
const mutedAndBlockedChannelIds = Array.from(new Set(mutedUris.concat(blockedUris).map(uri => uri.split('#')[1])));
|
const mutedAndBlockedChannelIds = Array.from(new Set(mutedUris.concat(blockedUris).map((uri) => uri.split('#')[1])));
|
||||||
|
|
||||||
const langParam = urlParams.get(CS.LANGUAGE_KEY) || null;
|
const langParam = urlParams.get(CS.LANGUAGE_KEY) || null;
|
||||||
const languageParams = searchInLanguage
|
const languageParams = searchInLanguage
|
||||||
|
@ -265,12 +266,7 @@ function ClaimListDiscover(props: Props) {
|
||||||
|
|
||||||
if (claimType !== CS.CLAIM_CHANNEL) {
|
if (claimType !== CS.CLAIM_CHANNEL) {
|
||||||
if (orderParam === CS.ORDER_BY_TOP && freshnessParam !== CS.FRESH_ALL) {
|
if (orderParam === CS.ORDER_BY_TOP && freshnessParam !== CS.FRESH_ALL) {
|
||||||
options.release_time = `>${Math.floor(
|
options.release_time = `>${Math.floor(moment().subtract(1, freshnessParam).startOf('hour').unix())}`;
|
||||||
moment()
|
|
||||||
.subtract(1, freshnessParam)
|
|
||||||
.startOf('hour')
|
|
||||||
.unix()
|
|
||||||
)}`;
|
|
||||||
} else if (orderParam === CS.ORDER_BY_NEW || orderParam === CS.ORDER_BY_TRENDING) {
|
} else if (orderParam === CS.ORDER_BY_NEW || orderParam === CS.ORDER_BY_TRENDING) {
|
||||||
// Warning - hack below
|
// Warning - hack below
|
||||||
// If users are following more than 10 channels or tags, limit results to stuff less than a year old
|
// If users are following more than 10 channels or tags, limit results to stuff less than a year old
|
||||||
|
@ -281,29 +277,15 @@ function ClaimListDiscover(props: Props) {
|
||||||
(options.channel_ids && options.channel_ids.length > 20) ||
|
(options.channel_ids && options.channel_ids.length > 20) ||
|
||||||
(options.any_tags && options.any_tags.length > 20)
|
(options.any_tags && options.any_tags.length > 20)
|
||||||
) {
|
) {
|
||||||
options.release_time = `>${Math.floor(
|
options.release_time = `>${Math.floor(moment().subtract(3, CS.FRESH_MONTH).startOf('week').unix())}`;
|
||||||
moment()
|
|
||||||
.subtract(3, CS.FRESH_MONTH)
|
|
||||||
.startOf('week')
|
|
||||||
.unix()
|
|
||||||
)}`;
|
|
||||||
} else if (
|
} else if (
|
||||||
(options.channel_ids && options.channel_ids.length > 10) ||
|
(options.channel_ids && options.channel_ids.length > 10) ||
|
||||||
(options.any_tags && options.any_tags.length > 10)
|
(options.any_tags && options.any_tags.length > 10)
|
||||||
) {
|
) {
|
||||||
options.release_time = `>${Math.floor(
|
options.release_time = `>${Math.floor(moment().subtract(1, CS.FRESH_YEAR).startOf('week').unix())}`;
|
||||||
moment()
|
|
||||||
.subtract(1, CS.FRESH_YEAR)
|
|
||||||
.startOf('week')
|
|
||||||
.unix()
|
|
||||||
)}`;
|
|
||||||
} else {
|
} else {
|
||||||
// Hack for at least the New page until https://github.com/lbryio/lbry-sdk/issues/2591 is fixed
|
// Hack for at least the New page until https://github.com/lbryio/lbry-sdk/issues/2591 is fixed
|
||||||
options.release_time = `<${Math.floor(
|
options.release_time = `<${Math.floor(moment().startOf('minute').unix())}`;
|
||||||
moment()
|
|
||||||
.startOf('minute')
|
|
||||||
.unix()
|
|
||||||
)}`;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -351,14 +333,14 @@ function ClaimListDiscover(props: Props) {
|
||||||
if (hideReposts && !options.reposted_claim_id && !forceShowReposts) {
|
if (hideReposts && !options.reposted_claim_id && !forceShowReposts) {
|
||||||
if (Array.isArray(options.claim_type)) {
|
if (Array.isArray(options.claim_type)) {
|
||||||
if (options.claim_type.length > 1) {
|
if (options.claim_type.length > 1) {
|
||||||
options.claim_type = options.claim_type.filter(claimType => claimType !== 'repost');
|
options.claim_type = options.claim_type.filter((claimType) => claimType !== 'repost');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
options.claim_type = ['stream', 'channel'];
|
options.claim_type = ['stream', 'channel'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const hasMatureTags = tagsParam && tagsParam.split(',').some(t => MATURE_TAGS.includes(t));
|
const hasMatureTags = tagsParam && tagsParam.split(',').some((t) => MATURE_TAGS.includes(t));
|
||||||
const claimSearchCacheQuery = createNormalizedClaimSearchKey(options);
|
const claimSearchCacheQuery = createNormalizedClaimSearchKey(options);
|
||||||
const claimSearchResult = claimSearchByQuery[claimSearchCacheQuery];
|
const claimSearchResult = claimSearchByQuery[claimSearchCacheQuery];
|
||||||
const claimSearchResultLastPageReached = claimSearchByQueryLastPageReached[claimSearchCacheQuery];
|
const claimSearchResultLastPageReached = claimSearchByQueryLastPageReached[claimSearchCacheQuery];
|
||||||
|
@ -471,9 +453,7 @@ function ClaimListDiscover(props: Props) {
|
||||||
doClaimSearch(searchOptions);
|
doClaimSearch(searchOptions);
|
||||||
|
|
||||||
if (liveLivestreamsFirst && options.page === 1) {
|
if (liveLivestreamsFirst && options.page === 1) {
|
||||||
delete searchOptions.has_source;
|
doClaimSearch(getLivestreamOnlyOptions(searchOptions));
|
||||||
delete searchOptions.stream_types;
|
|
||||||
doClaimSearch({ ...searchOptions, has_no_source: true });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [doClaimSearch, shouldPerformSearch, optionsStringForEffect, forceRefresh]);
|
}, [doClaimSearch, shouldPerformSearch, optionsStringForEffect, forceRefresh]);
|
||||||
|
|
|
@ -6,14 +6,7 @@ import React from 'react';
|
||||||
import { createNormalizedClaimSearchKey, MATURE_TAGS } from 'lbry-redux';
|
import { createNormalizedClaimSearchKey, MATURE_TAGS } from 'lbry-redux';
|
||||||
import ClaimPreviewTile from 'component/claimPreviewTile';
|
import ClaimPreviewTile from 'component/claimPreviewTile';
|
||||||
import { useHistory } from 'react-router';
|
import { useHistory } from 'react-router';
|
||||||
|
import { getLivestreamOnlyOptions } from 'util/search';
|
||||||
const getNoSourceOptions = (options) => {
|
|
||||||
const newOptions = Object.assign({}, options);
|
|
||||||
delete newOptions.has_source;
|
|
||||||
delete newOptions.stream_types;
|
|
||||||
newOptions.has_no_source = true;
|
|
||||||
return newOptions;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates 'uris' by adding and/or moving active livestreams to the front of
|
* Updates 'uris' by adding and/or moving active livestreams to the front of
|
||||||
|
@ -68,7 +61,7 @@ export function prioritizeActiveLivestreams(
|
||||||
|
|
||||||
// 2. Now, repeat on the secondary search.
|
// 2. Now, repeat on the secondary search.
|
||||||
if (options) {
|
if (options) {
|
||||||
const livestreamsOnlySearchCacheQuery = createNormalizedClaimSearchKey(getNoSourceOptions(options));
|
const livestreamsOnlySearchCacheQuery = createNormalizedClaimSearchKey(getLivestreamOnlyOptions(options));
|
||||||
const livestreamsOnlyUris = claimSearchByQuery[livestreamsOnlySearchCacheQuery];
|
const livestreamsOnlyUris = claimSearchByQuery[livestreamsOnlySearchCacheQuery];
|
||||||
if (livestreamsOnlyUris) {
|
if (livestreamsOnlyUris) {
|
||||||
livestreamsOnlyUris.forEach((uri) => {
|
livestreamsOnlyUris.forEach((uri) => {
|
||||||
|
@ -254,7 +247,7 @@ function ClaimTilesDiscover(props: Props) {
|
||||||
doClaimSearch(searchOptions);
|
doClaimSearch(searchOptions);
|
||||||
|
|
||||||
if (liveLivestreamsFirst) {
|
if (liveLivestreamsFirst) {
|
||||||
doClaimSearch(getNoSourceOptions(searchOptions));
|
doClaimSearch(getLivestreamOnlyOptions(searchOptions));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [doClaimSearch, shouldPerformSearch, optionsStringForEffect, liveLivestreamsFirst]);
|
}, [doClaimSearch, shouldPerformSearch, optionsStringForEffect, liveLivestreamsFirst]);
|
||||||
|
|
|
@ -17,3 +17,19 @@ export function createNormalizedSearchKey(query: string) {
|
||||||
}
|
}
|
||||||
return normalizedQuery;
|
return normalizedQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the "livestream only" version of the given 'options'.
|
||||||
|
*
|
||||||
|
* Currently, the 'has_source' attribute is being used to identify livestreams.
|
||||||
|
*
|
||||||
|
* @param options
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
export function getLivestreamOnlyOptions(options: any) {
|
||||||
|
const newOptions = Object.assign({}, options);
|
||||||
|
delete newOptions.has_source;
|
||||||
|
delete newOptions.stream_types;
|
||||||
|
newOptions.has_no_source = true;
|
||||||
|
return newOptions;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue