Fix selectIsSubscribedForUri not handling abandoned claims

I yanked out the parseURI part in a prior commit ... the comment was misleading me to think it was redundant. But it had another hidden function, which is to handle abandoned claims which `claim` will be `null`.
This commit is contained in:
infinite-persistence 2021-12-01 21:12:07 +08:00
parent dcd93af6eb
commit 8bc6718a4a
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0

View file

@ -9,7 +9,7 @@ import {
selectClaimForUri, selectClaimForUri,
} from 'redux/selectors/claims'; } from 'redux/selectors/claims';
import { swapKeyAndValue } from 'util/swap-json'; import { swapKeyAndValue } from 'util/swap-json';
import { getChannelFromClaim } from 'util/claim'; import { getChannelFromClaim, isChannelClaim } from 'util/claim';
// Returns the entire subscriptions state // Returns the entire subscriptions state
const selectState = (state) => state.subscriptions || {}; const selectState = (state) => state.subscriptions || {};
@ -114,14 +114,21 @@ export const makeSelectChannelInSubscriptions = (uri) =>
createSelector(selectSubscriptions, (subscriptions) => subscriptions.some((sub) => sub.uri === uri)); createSelector(selectSubscriptions, (subscriptions) => subscriptions.some((sub) => sub.uri === uri));
export const selectIsSubscribedForUri = createCachedSelector( export const selectIsSubscribedForUri = createCachedSelector(
(state, uri) => uri,
selectClaimForUri, selectClaimForUri,
selectSubscriptions, selectSubscriptions,
(claim, subscriptions) => { (uri, claim, subscriptions) => {
const channelClaim = getChannelFromClaim(claim); const channelClaim = getChannelFromClaim(claim);
if (channelClaim) { if (channelClaim) {
const uri = channelClaim.permanent_url; const permanentUrl = channelClaim.permanent_url;
return subscriptions.some((sub) => isURIEqual(sub.uri, permanentUrl));
}
// If it failed, it could be an abandoned channel. Try parseURI:
if (isChannelClaim(claim, uri)) {
return subscriptions.some((sub) => isURIEqual(sub.uri, uri)); return subscriptions.some((sub) => isURIEqual(sub.uri, uri));
} }
return false; return false;
} }
)((state, uri) => String(uri)); )((state, uri) => String(uri));