2021-12-31 18:52:26 +01:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
// TODO: This should be in 'redux/selectors/claim.js'. Temporarily putting it
|
|
|
|
// here to get past importing issues with 'lbryinc', which the real fix might
|
|
|
|
// involve moving it from 'extras' to 'ui' (big change).
|
|
|
|
|
|
|
|
import { createCachedSelector } from 're-reselect';
|
2022-08-09 17:19:23 +02:00
|
|
|
import { selectClaimForUri, makeSelectIsBlacklisted } from 'redux/selectors/claims';
|
2021-12-31 18:52:26 +01:00
|
|
|
import { selectMutedChannels } from 'redux/selectors/blocked';
|
|
|
|
import { selectModerationBlockList } from 'redux/selectors/comments';
|
|
|
|
import { selectBlacklistedOutpointMap, selectFilteredOutpointMap } from 'lbryinc';
|
|
|
|
import { getChannelFromClaim } from 'util/claim';
|
|
|
|
import { isURIEqual } from 'util/lbryURI';
|
|
|
|
|
|
|
|
export const selectBanStateForUri = createCachedSelector(
|
|
|
|
selectClaimForUri,
|
|
|
|
selectBlacklistedOutpointMap,
|
|
|
|
selectFilteredOutpointMap,
|
|
|
|
selectMutedChannels,
|
|
|
|
selectModerationBlockList,
|
2022-08-09 17:19:23 +02:00
|
|
|
(state, uri) => makeSelectIsBlacklisted(uri)(state),
|
|
|
|
(claim, blackListedOutpointMap, filteredOutpointMap, mutedChannelUris, personalBlocklist, isBlacklisted) => {
|
2021-12-31 18:52:26 +01:00
|
|
|
const banState = {};
|
|
|
|
|
|
|
|
if (!claim) {
|
|
|
|
return banState;
|
|
|
|
}
|
|
|
|
|
|
|
|
const channelClaim = getChannelFromClaim(claim);
|
|
|
|
|
2022-08-09 17:19:23 +02:00
|
|
|
if (isBlacklisted) {
|
|
|
|
banState['blacklisted'] = true;
|
|
|
|
}
|
|
|
|
|
2021-12-31 18:52:26 +01:00
|
|
|
// This will be replaced once blocking is done at the wallet server level.
|
|
|
|
if (blackListedOutpointMap) {
|
|
|
|
if (
|
|
|
|
(channelClaim && blackListedOutpointMap[`${channelClaim.txid}:${channelClaim.nout}`]) ||
|
|
|
|
blackListedOutpointMap[`${claim.txid}:${claim.nout}`]
|
|
|
|
) {
|
|
|
|
banState['blacklisted'] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We're checking to see if the stream outpoint or signing channel outpoint
|
|
|
|
// is in the filter list.
|
|
|
|
if (filteredOutpointMap) {
|
|
|
|
if (
|
|
|
|
(channelClaim && filteredOutpointMap[`${channelClaim.txid}:${channelClaim.nout}`]) ||
|
|
|
|
filteredOutpointMap[`${claim.txid}:${claim.nout}`]
|
|
|
|
) {
|
|
|
|
banState['filtered'] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// block stream claims
|
|
|
|
// block channel claims if we can't control for them in claim search
|
|
|
|
if (mutedChannelUris.length && channelClaim) {
|
|
|
|
if (mutedChannelUris.some((blockedUri) => isURIEqual(blockedUri, channelClaim.permanent_url))) {
|
|
|
|
banState['muted'] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Commentron blocklist
|
|
|
|
if (personalBlocklist.length && channelClaim) {
|
|
|
|
if (personalBlocklist.some((blockedUri) => isURIEqual(blockedUri, channelClaim.permanent_url))) {
|
|
|
|
banState['blocked'] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return banState;
|
|
|
|
}
|
|
|
|
)((state, uri) => String(uri));
|