Support not_channel_ids through Category definition

Mainly only useful for Wild West, which doesn't use `channel_ids` (otherwise, the homepage maintainer could just exclude the id from `channel_ids` directly).
This commit is contained in:
infinite-persistence 2022-04-19 20:56:37 +08:00
parent 9ad73c9878
commit e64d661dcd
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
6 changed files with 28 additions and 4 deletions

View file

@ -22,6 +22,7 @@ declare type RowDataItem = {
pinnedClaimIds?: Array<string>, // takes precedence over pinnedUrls
options?: {
channelIds?: Array<string>,
excludedChannelIds?: Array<string>,
limitClaimsPerChannel?: number,
pageSize?: number,
releaseTime?: string,

View file

@ -71,6 +71,7 @@ type Props = {
limitClaimsPerChannel?: number,
channelIds?: Array<string>,
excludedChannelIds?: Array<string>,
claimIds?: Array<string>,
subscribedChannels: Array<Subscription>,
@ -128,6 +129,7 @@ function ClaimListDiscover(props: Props) {
meta,
subSection,
channelIds,
excludedChannelIds,
showNsfw,
hideReposts,
fetchViewCount,
@ -265,6 +267,7 @@ function ClaimListDiscover(props: Props) {
const durationParam = urlParams.get(CS.DURATION_KEY) || null;
const channelIdsInUrl = urlParams.get(CS.CHANNEL_IDS_KEY);
const channelIdsParam = channelIdsInUrl ? channelIdsInUrl.split(',') : channelIds;
const excludedIdsParam = excludedChannelIds;
const feeAmountParam = urlParams.get('fee_amount') || feeAmount;
// const originalPageSize = pageSize || CS.PAGE_SIZE;
const originalPageSize = 12;
@ -354,6 +357,10 @@ function ClaimListDiscover(props: Props) {
options.channel_ids = channelIdsParam;
}
if (excludedIdsParam) {
options.not_channel_ids = (options.not_channel_ids || []).concat(excludedIdsParam);
}
if (tagsParam) {
if (tagsParam !== CS.TAGS_ALL && tagsParam !== '') {
if (tagsParam === CS.TAGS_FOLLOWED) {

View file

@ -23,6 +23,7 @@ function getTileLimit(isLargeScreen, originalSize) {
type Props = {
tileLayout: boolean,
channelIds?: Array<string>,
excludedChannelIds?: Array<string>,
activeLivestreams: ?LivestreamInfo,
doFetchActiveLivestreams: (orderBy: ?Array<string>, lang: ?Array<string>) => void,
searchLanguages?: Array<string>,
@ -35,6 +36,7 @@ export default function LivestreamSection(props: Props) {
const {
tileLayout,
channelIds,
excludedChannelIds,
activeLivestreams,
doFetchActiveLivestreams,
searchLanguages,
@ -51,7 +53,7 @@ export default function LivestreamSection(props: Props) {
const initialLiveTileLimit = getTileLimit(isLargeScreen, DEFAULT_LIVESTREAM_TILE_LIMIT);
const [liveSection, setLiveSection] = React.useState(liveSectionStore || SECTION.COLLAPSED);
const livestreamUris = getLivestreamUris(activeLivestreams, channelIds);
const livestreamUris = getLivestreamUris(activeLivestreams, channelIds, excludedChannelIds);
const liveTilesOverLimit = livestreamUris && livestreamUris.length > initialLiveTileLimit;
function collapseSection() {

View file

@ -66,8 +66,8 @@ function DiscoverPage(props: Props) {
// Eventually allow more than one tag on this page
// Restricting to one to make follow/unfollow simpler
const tag = (tags && tags[0]) || null;
const channelIds =
(dynamicRouteProps && dynamicRouteProps.options && dynamicRouteProps.options.channelIds) || undefined;
const channelIds = dynamicRouteProps?.options?.channelIds || undefined;
const excludedChannelIds = dynamicRouteProps?.options?.excludedChannelIds || undefined;
const isFollowing = followedTags.map(({ name }) => name).includes(tag);
let label = isFollowing ? __('Following --[button label indicating a channel has been followed]--') : __('Follow');
@ -113,6 +113,7 @@ function DiscoverPage(props: Props) {
<LivestreamSection
tileLayout={repostedUri ? false : tileLayout}
channelIds={channelIds}
excludedChannelIds={excludedChannelIds}
activeLivestreams={activeLivestreams}
doFetchActiveLivestreams={doFetchActiveLivestreams}
searchLanguages={dynamicRouteProps?.options?.searchLanguages}
@ -207,6 +208,7 @@ function DiscoverPage(props: Props) {
releaseTime={releaseTime || undefined}
feeAmount={isWildWest || tags ? CS.FEE_AMOUNT_ANY : undefined}
channelIds={channelIds}
excludedChannelIds={excludedChannelIds}
limitClaimsPerChannel={
SIMPLE_SITE
? (dynamicRouteProps && dynamicRouteProps.options && dynamicRouteProps.options.limitClaimsPerChannel) || 3

View file

@ -21,6 +21,7 @@ export type HomepageCat = {
tags?: Array<string>,
pinnedUrls?: Array<string>,
pinnedClaimIds?: Array<string>, // takes precedence over pinnedUrls
excludedChannelIds?: Array<string>,
searchLanguages?: Array<string>,
mixIn?: Array<string>,
};
@ -96,6 +97,7 @@ export const getHomepageRowForCat = (key: string, cat: HomepageCat) => {
options: {
claimType: cat.claimType || ['stream', 'repost'],
channelIds: cat.channelIds,
excludedChannelIds: cat.excludedChannelIds,
orderBy: orderValue,
pageSize: cat.pageSize || undefined,
limitClaimsPerChannel: limitClaims,

View file

@ -34,9 +34,14 @@ type StreamData = {
*
* @param activeLivestreams Object obtained from `selectActiveLivestreams`.
* @param channelIds List of channel IDs to filter the results with.
* @param excludedChannelIds
* @returns {[]|Array<*>}
*/
export function getLivestreamUris(activeLivestreams: ?LivestreamInfo, channelIds: ?Array<string>) {
export function getLivestreamUris(
activeLivestreams: ?LivestreamInfo,
channelIds: ?Array<string>,
excludedChannelIds?: Array<string>
) {
let values = (activeLivestreams && Object.values(activeLivestreams)) || [];
if (channelIds && channelIds.length > 0) {
@ -47,6 +52,11 @@ export function getLivestreamUris(activeLivestreams: ?LivestreamInfo, channelIds
values = values.filter((v) => Boolean(v.claimUri));
}
if (excludedChannelIds) {
// $FlowFixMe
values = values.filter((v) => !excludedChannelIds.includes(v.creatorId));
}
// $FlowFixMe
return values.map((v) => v.claimUri);
}