diff --git a/extras/recsys/recsys.js b/extras/recsys/recsys.js index ca0a9faf6..dfd34e9a5 100644 --- a/extras/recsys/recsys.js +++ b/extras/recsys/recsys.js @@ -9,6 +9,7 @@ import { X_LBRY_AUTH_TOKEN } from 'constants/token'; import { makeSelectClaimForUri } from 'redux/selectors/claims'; import { selectPlayingUri, selectPrimaryUri } from 'redux/selectors/content'; import { selectClientSetting, selectDaemonSettings } from 'redux/selectors/settings'; +import { selectIsSubscribedForClaimId } from 'redux/selectors/subscriptions'; import { history } from 'ui/store'; const recsysEndpoint = RECSYS_ENDPOINT; @@ -109,6 +110,8 @@ const recsys = { recClickedVideoIdx: [], pageLoadedAt: Date.now(), events: [], + incognito: !(user && user.has_verified_email), + isFollowing: selectIsSubscribedForClaimId(state, claimId), }; if (parentUuid) { diff --git a/ui/redux/selectors/claims.js b/ui/redux/selectors/claims.js index 65de8726d..3177c6220 100644 --- a/ui/redux/selectors/claims.js +++ b/ui/redux/selectors/claims.js @@ -93,8 +93,11 @@ export const selectClaimIdForUri = (state: State, uri: string) => selectClaimIds export const selectReflectingById = (state: State) => selectState(state).reflectingById; +// OBSOLETE: use selectClaimForClaimId instead export const makeSelectClaimForClaimId = (claimId: string) => createSelector(selectClaimsById, (byId) => byId[claimId]); +export const selectClaimForClaimId = (state: State, claimId: string) => selectClaimsById(state)[claimId]; + export const selectClaimForUri = createCachedSelector( selectClaimIdsByUri, selectClaimsById, diff --git a/ui/redux/selectors/subscriptions.js b/ui/redux/selectors/subscriptions.js index 7087e93de..3af206b8b 100644 --- a/ui/redux/selectors/subscriptions.js +++ b/ui/redux/selectors/subscriptions.js @@ -7,6 +7,7 @@ import { makeSelectChannelForClaimUri, makeSelectClaimForUri, selectClaimForUri, + selectClaimForClaimId, } from 'redux/selectors/claims'; import { swapKeyAndValue } from 'util/swap-json'; import { getChannelFromClaim, isChannelClaim } from 'util/claim'; @@ -135,6 +136,23 @@ export const selectIsSubscribedForUri = createCachedSelector( } )((state, uri) => String(uri)); +/** + * Unlike its 'selectIsSubscribedForUri' counterpart, this does not try to use + * parseURI as a fallback (since it only has claimId and not the uri). + */ +export const selectIsSubscribedForClaimId = createCachedSelector( + selectClaimForClaimId, // (state, claimId) + selectSubscriptions, // (state) + (claim, subscriptions) => { + const channelClaim = getChannelFromClaim(claim); + if (channelClaim) { + const permanentUrl = channelClaim.permanent_url; + return subscriptions.some((sub) => isURIEqual(sub.uri, permanentUrl)); + } + return false; + } +)((state, claimId) => String(claimId)); + export const makeSelectNotificationsDisabled = (uri) => createSelector( selectFollowing,