Simplify ad-injection logic

Since `<Ads>` is already checking against SHOW_ADS and membershipship details, there is no need for all clients to repeat the same thing.
This commit is contained in:
infinite-persistence 2022-03-10 19:44:11 +08:00
parent 803a779e9e
commit 2dd0fc283d
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
8 changed files with 10 additions and 35 deletions

View file

@ -11,7 +11,6 @@ import { doResolveUris } from 'redux/actions/claims';
import * as SETTINGS from 'constants/settings'; import * as SETTINGS from 'constants/settings';
import { makeSelectChannelIsMuted } from 'redux/selectors/blocked'; import { makeSelectChannelIsMuted } from 'redux/selectors/blocked';
import { withRouter } from 'react-router'; import { withRouter } from 'react-router';
import { selectOdyseeMembershipIsPremiumPlus } from 'redux/selectors/user';
import { selectClientSetting, selectShowMatureContent } from 'redux/selectors/settings'; import { selectClientSetting, selectShowMatureContent } from 'redux/selectors/settings';
import { doFetchChannelLiveStatus } from 'redux/actions/livestream'; import { doFetchChannelLiveStatus } from 'redux/actions/livestream';
import { selectActiveLivestreamForChannel, selectActiveLivestreamInitialized } from 'redux/selectors/livestream'; import { selectActiveLivestreamForChannel, selectActiveLivestreamInitialized } from 'redux/selectors/livestream';
@ -36,7 +35,6 @@ const select = (state, props) => {
tileLayout: selectClientSetting(state, SETTINGS.TILE_LAYOUT), tileLayout: selectClientSetting(state, SETTINGS.TILE_LAYOUT),
activeLivestreamForChannel: selectActiveLivestreamForChannel(state, channelClaimId), activeLivestreamForChannel: selectActiveLivestreamForChannel(state, channelClaimId),
activeLivestreamInitialized: selectActiveLivestreamInitialized(state), activeLivestreamInitialized: selectActiveLivestreamInitialized(state),
userHasPremiumPlus: selectOdyseeMembershipIsPremiumPlus(state),
}; };
}; };

View file

@ -1,5 +1,5 @@
// @flow // @flow
import { SHOW_ADS, SIMPLE_SITE } from 'config'; import { SIMPLE_SITE } from 'config';
import * as CS from 'constants/claim_search'; import * as CS from 'constants/claim_search';
import * as ICONS from 'constants/icons'; import * as ICONS from 'constants/icons';
import React, { Fragment } from 'react'; import React, { Fragment } from 'react';
@ -39,7 +39,6 @@ type Props = {
doFetchChannelLiveStatus: (string) => void, doFetchChannelLiveStatus: (string) => void,
activeLivestreamForChannel: any, activeLivestreamForChannel: any,
activeLivestreamInitialized: boolean, activeLivestreamInitialized: boolean,
userHasPremiumPlus: boolean,
}; };
function ChannelContent(props: Props) { function ChannelContent(props: Props) {
@ -61,7 +60,6 @@ function ChannelContent(props: Props) {
doFetchChannelLiveStatus, doFetchChannelLiveStatus,
activeLivestreamForChannel, activeLivestreamForChannel,
activeLivestreamInitialized, activeLivestreamInitialized,
userHasPremiumPlus,
} = props; } = props;
// const claimsInChannel = (claim && claim.meta.claims_in_channel) || 0; // const claimsInChannel = (claim && claim.meta.claims_in_channel) || 0;
@ -162,7 +160,7 @@ function ChannelContent(props: Props) {
defaultOrderBy={CS.ORDER_BY_NEW} defaultOrderBy={CS.ORDER_BY_NEW}
pageSize={defaultPageSize} pageSize={defaultPageSize}
infiniteScroll={defaultInfiniteScroll} infiniteScroll={defaultInfiniteScroll}
injectedItem={SHOW_ADS && !userHasPremiumPlus && { node: <Ads type="video" tileLayout={tileLayout} small /> }} injectedItem={{ node: <Ads type="video" tileLayout={tileLayout} small /> }}
meta={ meta={
showFilters && ( showFilters && (
<Form onSubmit={() => {}} className="wunderbar--inline"> <Form onSubmit={() => {}} className="wunderbar--inline">

View file

@ -5,7 +5,6 @@ import { makeSelectClaimForUri } from 'redux/selectors/claims';
import * as SETTINGS from 'constants/settings'; import * as SETTINGS from 'constants/settings';
import { doFetchActiveLivestreams } from 'redux/actions/livestream'; import { doFetchActiveLivestreams } from 'redux/actions/livestream';
import { selectActiveLivestreams } from 'redux/selectors/livestream'; import { selectActiveLivestreams } from 'redux/selectors/livestream';
import { selectOdyseeMembershipIsPremiumPlus } from 'redux/selectors/user';
import { selectFollowedTags } from 'redux/selectors/tags'; import { selectFollowedTags } from 'redux/selectors/tags';
import { doToggleTagFollowDesktop } from 'redux/actions/tags'; import { doToggleTagFollowDesktop } from 'redux/actions/tags';
import { selectClientSetting, selectLanguage } from 'redux/selectors/settings'; import { selectClientSetting, selectLanguage } from 'redux/selectors/settings';
@ -22,7 +21,6 @@ const select = (state, props) => {
repostedClaim: repostedUri ? makeSelectClaimForUri(repostedUri)(state) : null, repostedClaim: repostedUri ? makeSelectClaimForUri(repostedUri)(state) : null,
tileLayout: selectClientSetting(state, SETTINGS.TILE_LAYOUT), tileLayout: selectClientSetting(state, SETTINGS.TILE_LAYOUT),
activeLivestreams: selectActiveLivestreams(state), activeLivestreams: selectActiveLivestreams(state),
userHasPremiumPlus: selectOdyseeMembershipIsPremiumPlus(state),
languageSetting: selectLanguage(state), languageSetting: selectLanguage(state),
searchInLanguage: selectClientSetting(state, SETTINGS.SEARCH_IN_LANGUAGE), searchInLanguage: selectClientSetting(state, SETTINGS.SEARCH_IN_LANGUAGE),
}; };

View file

@ -1,5 +1,5 @@
// @flow // @flow
import { SHOW_ADS, DOMAIN, SIMPLE_SITE } from 'config'; import { DOMAIN, SIMPLE_SITE } from 'config';
import * as ICONS from 'constants/icons'; import * as ICONS from 'constants/icons';
import * as PAGES from 'constants/pages'; import * as PAGES from 'constants/pages';
import * as CS from 'constants/claim_search'; import * as CS from 'constants/claim_search';
@ -31,7 +31,6 @@ type Props = {
tileLayout: boolean, tileLayout: boolean,
activeLivestreams: ?LivestreamInfo, activeLivestreams: ?LivestreamInfo,
doFetchActiveLivestreams: (orderBy: ?Array<string>, lang: ?Array<string>) => void, doFetchActiveLivestreams: (orderBy: ?Array<string>, lang: ?Array<string>) => void,
userHasPremiumPlus: boolean,
}; };
function DiscoverPage(props: Props) { function DiscoverPage(props: Props) {
@ -48,7 +47,6 @@ function DiscoverPage(props: Props) {
activeLivestreams, activeLivestreams,
doFetchActiveLivestreams, doFetchActiveLivestreams,
dynamicRouteProps, dynamicRouteProps,
userHasPremiumPlus,
} = props; } = props;
const buttonRef = useRef(); const buttonRef = useRef();
@ -190,9 +188,7 @@ function DiscoverPage(props: Props) {
tags={tags} tags={tags}
hiddenNsfwMessage={<HiddenNsfw type="page" />} hiddenNsfwMessage={<HiddenNsfw type="page" />}
repostedClaimId={repostedClaim ? repostedClaim.claim_id : null} repostedClaimId={repostedClaim ? repostedClaim.claim_id : null}
injectedItem={ injectedItem={!isWildWest && { node: <Ads small type="video" tileLayout={tileLayout} /> }}
SHOW_ADS && !userHasPremiumPlus && !isWildWest && { node: <Ads small type="video" tileLayout={tileLayout} /> }
}
// Assume wild west page if no dynamicRouteProps // Assume wild west page if no dynamicRouteProps
// Not a very good solution, but just doing it for now // Not a very good solution, but just doing it for now
// until we are sure this page will stay around // until we are sure this page will stay around

View file

@ -3,7 +3,7 @@ import * as SETTINGS from 'constants/settings';
import { doFetchActiveLivestreams } from 'redux/actions/livestream'; import { doFetchActiveLivestreams } from 'redux/actions/livestream';
import { selectActiveLivestreams, selectFetchingActiveLivestreams } from 'redux/selectors/livestream'; import { selectActiveLivestreams, selectFetchingActiveLivestreams } from 'redux/selectors/livestream';
import { selectFollowedTags } from 'redux/selectors/tags'; import { selectFollowedTags } from 'redux/selectors/tags';
import { selectUserVerifiedEmail, selectOdyseeMembershipIsPremiumPlus } from 'redux/selectors/user'; import { selectUserVerifiedEmail } from 'redux/selectors/user';
import { selectSubscriptions } from 'redux/selectors/subscriptions'; import { selectSubscriptions } from 'redux/selectors/subscriptions';
import { selectShowMatureContent, selectHomepageData, selectClientSetting } from 'redux/selectors/settings'; import { selectShowMatureContent, selectHomepageData, selectClientSetting } from 'redux/selectors/settings';
@ -18,7 +18,6 @@ const select = (state) => ({
activeLivestreams: selectActiveLivestreams(state), activeLivestreams: selectActiveLivestreams(state),
fetchingActiveLivestreams: selectFetchingActiveLivestreams(state), fetchingActiveLivestreams: selectFetchingActiveLivestreams(state),
hideScheduledLivestreams: selectClientSetting(state, SETTINGS.HIDE_SCHEDULED_LIVESTREAMS), hideScheduledLivestreams: selectClientSetting(state, SETTINGS.HIDE_SCHEDULED_LIVESTREAMS),
userHasPremiumPlus: selectOdyseeMembershipIsPremiumPlus(state),
}); });
const perform = (dispatch) => ({ const perform = (dispatch) => ({

View file

@ -1,7 +1,7 @@
// @flow // @flow
import * as ICONS from 'constants/icons'; import * as ICONS from 'constants/icons';
import * as PAGES from 'constants/pages'; import * as PAGES from 'constants/pages';
import { SHOW_ADS, SITE_NAME, SIMPLE_SITE, ENABLE_NO_SOURCE_CLAIMS } from 'config'; import { SITE_NAME, SIMPLE_SITE, ENABLE_NO_SOURCE_CLAIMS } from 'config';
import React, { useState } from 'react'; import React, { useState } from 'react';
import Page from 'component/page'; import Page from 'component/page';
import Button from 'component/button'; import Button from 'component/button';
@ -31,7 +31,6 @@ type Props = {
doFetchActiveLivestreams: () => void, doFetchActiveLivestreams: () => void,
fetchingActiveLivestreams: boolean, fetchingActiveLivestreams: boolean,
hideScheduledLivestreams: boolean, hideScheduledLivestreams: boolean,
userHasPremiumPlus: boolean,
}; };
function HomePage(props: Props) { function HomePage(props: Props) {
@ -45,7 +44,6 @@ function HomePage(props: Props) {
doFetchActiveLivestreams, doFetchActiveLivestreams,
fetchingActiveLivestreams, fetchingActiveLivestreams,
hideScheduledLivestreams, hideScheduledLivestreams,
userHasPremiumPlus,
} = props; } = props;
const showPersonalizedChannels = (authenticated || !IS_WEB) && subscribedChannels && subscribedChannels.length > 0; const showPersonalizedChannels = (authenticated || !IS_WEB) && subscribedChannels && subscribedChannels.length > 0;
const showPersonalizedTags = (authenticated || !IS_WEB) && followedTags && followedTags.length > 0; const showPersonalizedTags = (authenticated || !IS_WEB) && followedTags && followedTags.length > 0;
@ -101,11 +99,7 @@ function HomePage(props: Props) {
hasSource hasSource
prefixUris={getLivestreamUris(activeLivestreams, options.channelIds)} prefixUris={getLivestreamUris(activeLivestreams, options.channelIds)}
pinUrls={pinUrls} pinUrls={pinUrls}
injectedItem={ injectedItem={index === 0 && { node: <Ads small type="video" tileLayout />, replace: true }}
index === 0 &&
SHOW_ADS &&
!userHasPremiumPlus && { node: <Ads small type="video" tileLayout />, replace: true }
}
/> />
); );

View file

@ -8,7 +8,6 @@ import {
makeSelectHasReachedMaxResultsLength, makeSelectHasReachedMaxResultsLength,
} from 'redux/selectors/search'; } from 'redux/selectors/search';
import { selectShowMatureContent } from 'redux/selectors/settings'; import { selectShowMatureContent } from 'redux/selectors/settings';
import { selectUserVerifiedEmail } from 'redux/selectors/user';
import { getSearchQueryString } from 'util/query-params'; import { getSearchQueryString } from 'util/query-params';
import SearchPage from './view'; import SearchPage from './view';
@ -36,7 +35,6 @@ const select = (state, props) => {
searchOptions, searchOptions,
isSearching: selectIsSearching(state), isSearching: selectIsSearching(state),
uris: uris, uris: uris,
isAuthenticated: selectUserVerifiedEmail(state),
hasReachedMaxResultsLength: hasReachedMaxResultsLength, hasReachedMaxResultsLength: hasReachedMaxResultsLength,
}; };
}; };

View file

@ -1,5 +1,5 @@
// @flow // @flow
import { SIMPLE_SITE, SHOW_ADS } from 'config'; import { SIMPLE_SITE } from 'config';
import React, { useEffect } from 'react'; import React, { useEffect } from 'react';
import Lbry from 'lbry'; import Lbry from 'lbry';
import { parseURI, isNameValid } from 'util/lbryURI'; import { parseURI, isNameValid } from 'util/lbryURI';
@ -23,7 +23,7 @@ type Props = {
}; };
export default function SearchPage(props: Props) { export default function SearchPage(props: Props) {
const { urlQuery, searchOptions, search, uris, isSearching, isAuthenticated, hasReachedMaxResultsLength } = props; const { urlQuery, searchOptions, search, uris, isSearching, hasReachedMaxResultsLength } = props;
const { push } = useHistory(); const { push } = useHistory();
const [from, setFrom] = React.useState(0); const [from, setFrom] = React.useState(0);
@ -103,13 +103,7 @@ export default function SearchPage(props: Props) {
onSearchOptionsChanged={resetPage} onSearchOptionsChanged={resetPage}
/> />
} }
injectedItem={ injectedItem={{ node: <Ads small type="video" />, index: 3 }}
SHOW_ADS &&
!isAuthenticated && {
node: <Ads small type="video" />,
index: 3,
}
}
/> />
<div className="main--empty help">{__('These search results are provided by Odysee.')}</div> <div className="main--empty help">{__('These search results are provided by Odysee.')}</div>