2021-10-25 16:56:31 +02: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';
|
|
|
|
import { selectClaimForUri } from 'redux/selectors/claims';
|
|
|
|
import { selectMutedChannels } from 'redux/selectors/blocked';
|
|
|
|
import { selectModerationBlockList } from 'redux/selectors/comments';
|
2021-12-01 16:24:27 +01:00
|
|
|
import { selectBlacklistedOutpointMap, selectFilteredOutpointMap } from 'lbryinc';
|
2021-11-18 03:21:21 +01:00
|
|
|
import { getChannelFromClaim } from 'util/claim';
|
2021-10-25 16:56:31 +02:00
|
|
|
import { isURIEqual } from 'util/lbryURI';
|
|
|
|
|
|
|
|
export const selectBanStateForUri = createCachedSelector(
|
2021-11-18 03:21:21 +01:00
|
|
|
selectClaimForUri,
|
2021-12-01 16:24:27 +01:00
|
|
|
selectBlacklistedOutpointMap,
|
|
|
|
selectFilteredOutpointMap,
|
2021-10-25 16:56:31 +02:00
|
|
|
selectMutedChannels,
|
|
|
|
selectModerationBlockList,
|
2021-12-01 16:24:27 +01:00
|
|
|
(claim, blackListedOutpointMap, filteredOutpointMap, mutedChannelUris, personalBlocklist) => {
|
2021-10-25 16:56:31 +02:00
|
|
|
const banState = {};
|
|
|
|
|
2021-11-18 03:21:21 +01:00
|
|
|
if (!claim) {
|
2021-10-25 16:56:31 +02:00
|
|
|
return banState;
|
|
|
|
}
|
|
|
|
|
2021-11-18 03:21:21 +01:00
|
|
|
const channelClaim = getChannelFromClaim(claim);
|
|
|
|
|
2021-10-25 16:56:31 +02:00
|
|
|
// This will be replaced once blocking is done at the wallet server level.
|
2021-12-01 16:24:27 +01:00
|
|
|
if (blackListedOutpointMap) {
|
2021-11-18 03:21:21 +01:00
|
|
|
if (
|
2021-12-01 16:24:27 +01:00
|
|
|
(channelClaim && blackListedOutpointMap[`${channelClaim.txid}:${channelClaim.nout}`]) ||
|
|
|
|
blackListedOutpointMap[`${claim.txid}:${claim.nout}`]
|
2021-11-18 03:21:21 +01:00
|
|
|
) {
|
2021-10-25 16:56:31 +02:00
|
|
|
banState['blacklisted'] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We're checking to see if the stream outpoint or signing channel outpoint
|
|
|
|
// is in the filter list.
|
2021-12-01 16:24:27 +01:00
|
|
|
if (filteredOutpointMap) {
|
2021-11-18 03:21:21 +01:00
|
|
|
if (
|
2021-12-01 16:24:27 +01:00
|
|
|
(channelClaim && filteredOutpointMap[`${channelClaim.txid}:${channelClaim.nout}`]) ||
|
|
|
|
filteredOutpointMap[`${claim.txid}:${claim.nout}`]
|
2021-11-18 03:21:21 +01:00
|
|
|
) {
|
2021-10-25 16:56:31 +02:00
|
|
|
banState['filtered'] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// block stream claims
|
|
|
|
// block channel claims if we can't control for them in claim search
|
2021-11-18 03:21:21 +01:00
|
|
|
if (mutedChannelUris.length && channelClaim) {
|
|
|
|
if (mutedChannelUris.some((blockedUri) => isURIEqual(blockedUri, channelClaim.permanent_url))) {
|
2021-10-25 16:56:31 +02:00
|
|
|
banState['muted'] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Commentron blocklist
|
2021-11-18 03:21:21 +01:00
|
|
|
if (personalBlocklist.length && channelClaim) {
|
|
|
|
if (personalBlocklist.some((blockedUri) => isURIEqual(blockedUri, channelClaim.permanent_url))) {
|
2021-10-25 16:56:31 +02:00
|
|
|
banState['blocked'] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return banState;
|
|
|
|
}
|
|
|
|
)((state, uri) => String(uri));
|