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 { selectModerationBlockList } from 'redux/selectors/comments';
|
|
|
|
import { getChannelFromClaim } from 'util/claim';
|
|
|
|
import { isURIEqual } from 'util/lbryURI';
|
|
|
|
|
|
|
|
export const selectBanStateForUri = createCachedSelector(
|
|
|
|
selectClaimForUri,
|
|
|
|
selectModerationBlockList,
|
2022-08-09 17:19:23 +02:00
|
|
|
(state, uri) => makeSelectIsBlacklisted(uri)(state),
|
2022-08-30 22:22:30 +02:00
|
|
|
(claim, 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
|
|
|
// Commentron blocklist
|
|
|
|
if (personalBlocklist.length && channelClaim) {
|
|
|
|
if (personalBlocklist.some((blockedUri) => isURIEqual(blockedUri, channelClaim.permanent_url))) {
|
|
|
|
banState['blocked'] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return banState;
|
|
|
|
}
|
|
|
|
)((state, uri) => String(uri));
|