Ad blacklist terms (#434)

* coming along well

* working properly

* check claim name and dont have side effect if the environment vars are not set

* check against claim name
This commit is contained in:
mayeaux 2021-12-06 19:01:40 +01:00 committed by GitHub
parent 62122f6a96
commit 1bfe9e2eda
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 4 deletions

View file

@ -87,6 +87,8 @@ const config = {
FIREBASE_MEASUREMENT_ID: process.env.FIREBASE_MEASUREMENT_ID,
FIREBASE_VAPID_KEY: process.env.FIREBASE_VAPID_KEY,
AD_KEYWORD_BLOCKLIST: process.env.AD_KEYWORD_BLOCKLIST,
AD_KEYWORD_BLOCKLIST_CHECK_DESCRIPTION: process.env.AD_KEYWORD_BLOCKLIST_CHECK_DESCRIPTION
};
config.SDK_API_PATH = `${config.LBRY_WEB_API}/api/v1`;

View file

@ -1,5 +1,5 @@
import { connect } from 'react-redux';
import { makeSelectClaimForUri } from 'redux/selectors/claims';
import { makeSelectClaimForUri, makeSelectMetadataForUri } from 'redux/selectors/claims';
import { doFetchRecommendedContent } from 'redux/actions/search';
import { selectRecommendedContentForUri, selectIsSearching } from 'redux/selectors/search';
import { selectUserVerifiedEmail } from 'redux/selectors/user';
@ -10,6 +10,7 @@ const select = (state, props) => {
const { claim_id: claimId } = claim;
const recommendedContentUris = selectRecommendedContentForUri(state, props.uri);
const nextRecommendedUri = recommendedContentUris && recommendedContentUris[0];
const metadata = makeSelectMetadataForUri(props.uri)(state);
return {
claim,
@ -18,6 +19,7 @@ const select = (state, props) => {
nextRecommendedUri,
isSearching: selectIsSearching(state),
isAuthenticated: selectUserVerifiedEmail(state),
metadata,
};
};

View file

@ -1,5 +1,5 @@
// @flow
import { SHOW_ADS } from 'config';
import { SHOW_ADS, AD_KEYWORD_BLOCKLIST, AD_KEYWORD_BLOCKLIST_CHECK_DESCRIPTION } from 'config';
import React from 'react';
import ClaimList from 'component/claimList';
import ClaimListDiscover from 'component/claimListDiscover';
@ -22,6 +22,7 @@ type Props = {
isAuthenticated: boolean,
claim: ?StreamClaim,
claimId: string,
metadata: any,
};
export default React.memo<Props>(function RecommendedContent(props: Props) {
@ -34,7 +35,41 @@ export default React.memo<Props>(function RecommendedContent(props: Props) {
isAuthenticated,
claim,
claimId,
metadata,
} = props;
let { description, title } = metadata;
if (description) {
description = description.toLowerCase();
}
if (title) {
title = title.toLowerCase();
}
const checkDescriptionForBlacklistWords = AD_KEYWORD_BLOCKLIST_CHECK_DESCRIPTION === 'true';
let triggerBlacklist = false;
if (AD_KEYWORD_BLOCKLIST) {
const termsToCheck = AD_KEYWORD_BLOCKLIST.split(',');
// eslint-disable-next-line no-unused-vars
if (title) {
for (const term of termsToCheck) {
if (claim && claim.name && claim.name.includes(term)) {
triggerBlacklist = true;
}
if (title.includes(term)) {
triggerBlacklist = true;
}
if (description && checkDescriptionForBlacklistWords && description.includes(term)) {
triggerBlacklist = true;
}
}
}
}
const [viewMode, setViewMode] = React.useState(VIEW_ALL_RELATED);
const signingChannel = claim && claim.signing_channel;
const channelName = signingChannel ? signingChannel.name : null;
@ -99,7 +134,7 @@ export default React.memo<Props>(function RecommendedContent(props: Props) {
loading={isSearching}
uris={recommendedContentUris}
hideMenu={isMobile}
injectedItem={SHOW_ADS && IS_WEB && !isAuthenticated && <Ads small type={'video'} />}
injectedItem={SHOW_ADS && IS_WEB && !isAuthenticated && <Ads small type={'video'} triggerBlacklist={triggerBlacklist} />}
empty={__('No related content found')}
onClick={handleRecommendationClicked}
/>

View file

@ -30,6 +30,7 @@ type Props = {
claim: Claim,
isMature: boolean,
authenticated: boolean,
triggerBlacklist: boolean
};
function removeIfExists(querySelector) {
@ -43,6 +44,7 @@ function Ads(props: Props) {
type = 'video',
small,
authenticated,
triggerBlacklist,
} = props;
// load ad and tags here
@ -131,7 +133,7 @@ function Ads(props: Props) {
</div>
);
if (!SHOW_ADS) {
if (!SHOW_ADS || triggerBlacklist) {
return false;
}
if (type === 'video') {