From 8dd7150d672b004f514b82f5d0f3eaffb2b00bd5 Mon Sep 17 00:00:00 2001 From: jessopb <36554050+jessopb@users.noreply.github.com> Date: Fri, 18 Nov 2022 10:22:32 -0500 Subject: [PATCH] fix unfollowing unpublished channels (#7737) --- ui/redux/selectors/subscriptions.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ui/redux/selectors/subscriptions.js b/ui/redux/selectors/subscriptions.js index 193092dc8..4c190efde 100644 --- a/ui/redux/selectors/subscriptions.js +++ b/ui/redux/selectors/subscriptions.js @@ -9,7 +9,7 @@ import { selectClaimForUri, } from 'redux/selectors/claims'; import { swapKeyAndValue } from 'util/swap-json'; -import { getChannelFromClaim } from 'util/claim'; +import { getChannelFromClaim, isChannelClaim } from 'util/claim'; // Returns the entire subscriptions state const selectState = (state) => state.subscriptions || {}; @@ -114,12 +114,18 @@ export const makeSelectChannelInSubscriptions = (uri) => createSelector(selectSubscriptions, (subscriptions) => subscriptions.some((sub) => sub.uri === uri)); export const selectIsSubscribedForUri = createCachedSelector( + (state, uri) => uri, selectClaimForUri, selectSubscriptions, - (claim, subscriptions) => { + (uri, claim, subscriptions) => { const channelClaim = getChannelFromClaim(claim); 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 false;