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';
|
|
|
|
import { selectBlackListedOutpoints, selectFilteredOutpoints } 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-10-25 16:56:31 +02:00
|
|
|
selectBlackListedOutpoints,
|
|
|
|
selectFilteredOutpoints,
|
|
|
|
selectMutedChannels,
|
|
|
|
selectModerationBlockList,
|
2021-11-18 03:21:21 +01:00
|
|
|
(claim, blackListedOutpoints, filteredOutpoints, 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.
|
|
|
|
if (blackListedOutpoints) {
|
2021-11-18 03:21:21 +01:00
|
|
|
if (
|
|
|
|
blackListedOutpoints.some(
|
|
|
|
(outpoint) =>
|
|
|
|
(channelClaim && outpoint.txid === channelClaim.txid && outpoint.nout === channelClaim.nout) ||
|
|
|
|
(outpoint.txid === claim.txid && outpoint.nout === claim.nout)
|
|
|
|
)
|
|
|
|
) {
|
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.
|
|
|
|
if (filteredOutpoints) {
|
2021-11-18 03:21:21 +01:00
|
|
|
if (
|
|
|
|
filteredOutpoints.some(
|
|
|
|
(outpoint) =>
|
|
|
|
(channelClaim && outpoint.txid === channelClaim.txid && outpoint.nout === channelClaim.nout) ||
|
|
|
|
(outpoint.txid === claim.txid && outpoint.nout === claim.nout)
|
|
|
|
)
|
|
|
|
) {
|
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));
|