Compare commits

..
Author SHA1 Message Date
zeppi 0ec0efe2ee bump 2021-09-21 15:20:04 -04:00
38 changed files with 394 additions and 464 deletions

No files matched your search

+1 -1
View File
@@ -156,7 +156,7 @@
"json-loader": "^0.5.4",
"lbry-format": "https://github.com/lbryio/lbry-format.git",
"lbry-redux": "lbryio/lbry-redux#32b578707116d45f5b51b7ab523d200e75668676",
"lbryinc": "lbryio/lbryinc#0b4e41ef90d6347819dd3453f2f9398a5c1b4f36",
"lbryinc": "lbryio/lbryinc#c9ced4f226e06f4f188cb8dc31b561e1c27c5266",
"lint-staged": "^7.0.2",
"localforage": "^1.7.1",
"lodash-es": "^4.17.14",
-1
View File
@@ -154,7 +154,6 @@ const Button = forwardRef<any, {}>((props: Props, ref: any) => {
title={title}
onClick={onClick}
aria-label={ariaLabel}
disabled={disabled} // is there a reason this wasn't here before?
>
{content}
</a>
+1 -31
View File
@@ -276,34 +276,4 @@ function ClaimPreviewTile(props: Props) {
);
}
export default React.memo<Props>(withRouter(ClaimPreviewTile), areEqual);
const BLOCKLIST_KEYS = ['blackListedOutpoints', 'filteredOutpoints', 'blockedChannelUris'];
const HANDLED_KEYS = [...BLOCKLIST_KEYS, 'date'];
function areEqual(prev: Props, next: Props) {
for (let i = 0; i < BLOCKLIST_KEYS.length; ++i) {
const key = BLOCKLIST_KEYS[i];
const a = prev[key];
const b = next[key];
if (((!a || !b) && a !== b) || (a && b && a.length !== b.length)) {
// The arrays are huge, so just compare the length instead of each entry.
return false;
}
}
if (Number(prev.date) !== Number(next.date)) {
return false;
}
const propKeys = Object.keys(next);
for (let i = 0; i < propKeys.length; ++i) {
const pk = propKeys[i];
if (!HANDLED_KEYS.includes(pk) && prev[pk] !== next[pk]) {
return false;
}
}
return true;
}
export default withRouter(ClaimPreviewTile);
+5 -14
View File
@@ -14,7 +14,7 @@ import usePersistedState from 'effects/use-persisted-state';
import { ENABLE_COMMENT_REACTIONS } from 'config';
import Empty from 'component/common/empty';
import debounce from 'util/debounce';
import { useIsMobile, useIsMediumScreen } from 'effects/use-screensize';
import { useIsMobile } from 'effects/use-screensize';
import { getChannelIdFromClaim } from 'util/claim';
const DEBOUNCE_SCROLL_HANDLER_MS = 200;
@@ -87,8 +87,7 @@ function CommentList(props: Props) {
linkedCommentId ? 0 : MAX_LINKED_COMMENT_SCROLL_ATTEMPTS
);
const isMobile = useIsMobile();
const isMediumScreen = useIsMediumScreen();
const [expandedComments, setExpandedComments] = React.useState(!isMobile && !isMediumScreen);
const [expandedComments, setExpandedComments] = React.useState(!isMobile);
const totalFetchedComments = allCommentIds ? allCommentIds.length : 0;
const channelId = getChannelIdFromClaim(claim);
const channelSettings = channelId ? settingsByChannelId[channelId] : undefined;
@@ -244,7 +243,7 @@ function CommentList(props: Props) {
}
const handleCommentScroll = debounce(() => {
if (!isMobile && !isMediumScreen && shouldFetchNextPage(page, topLevelTotalPages, window, document)) {
if (!isMobile && shouldFetchNextPage(page, topLevelTotalPages, window, document)) {
setPage(page + 1);
}
}, DEBOUNCE_SCROLL_HANDLER_MS);
@@ -259,7 +258,6 @@ function CommentList(props: Props) {
}
}, [
isMobile,
isMediumScreen,
page,
moreBelow,
spinnerRef,
@@ -269,13 +267,6 @@ function CommentList(props: Props) {
topLevelTotalPages,
]);
// Expand comments
useEffect(() => {
if (!isMobile && !isMediumScreen && !expandedComments) {
setExpandedComments(true);
}
}, [isMobile, isMediumScreen, expandedComments]);
return (
<Card
title={
@@ -349,7 +340,7 @@ function CommentList(props: Props) {
{readyToDisplayComments && topLevelComments && getCommentElems(topLevelComments)}
</ul>
{(isMobile || isMediumScreen) && (
{isMobile && (
<div className="card__bottom-actions--comments">
{(!expandedComments || moreBelow) && (
<Button
@@ -378,7 +369,7 @@ function CommentList(props: Props) {
</div>
)}
{(isFetchingComments || (!isMobile && !isMediumScreen && moreBelow)) && (
{(isFetchingComments || (!isMobile && moreBelow)) && (
<div className="main--empty" ref={spinnerRef}>
<Spinner type="small" />
</div>
+1 -6
View File
@@ -24,12 +24,7 @@ export default function FileViewCountInline(props: Props) {
formattedViewCount = Number(viewCount).toLocaleString();
}
// Limit the view-count visibility to Channel Pages for now. I believe we'll
// eventually show it everywhere, so this band-aid would be the easiest to
// clean up (only one place edit/remove).
const isChannelPage = window.location.pathname.startsWith('/@');
if (!viewCount || (claim && claim.repost_url) || isLivestream || !isChannelPage) {
if (!viewCount || (claim && claim.repost_url) || isLivestream) {
// (1) Currently, makeSelectViewCountForUri doesn't differentiate between
// un-fetched view-count vs zero view-count. But since it's probably not
// ideal to highlight that a view has 0 count, let's just not show anything.
@@ -1,11 +1,9 @@
import { connect } from 'react-redux';
import fileViewerEmbeddedTitle from './view';
import { makeSelectTagInClaimOrChannelForUri, makeSelectTitleForUri } from 'lbry-redux';
import { PREFERENCE_EMBED } from 'constants/tags';
import { makeSelectTitleForUri } from 'lbry-redux';
export default connect((state, props) => {
return {
title: makeSelectTitleForUri(props.uri)(state),
preferEmbed: makeSelectTagInClaimOrChannelForUri(props.uri, PREFERENCE_EMBED)(state),
};
})(fileViewerEmbeddedTitle);
+9 -17
View File
@@ -11,11 +11,10 @@ type Props = {
uri: string,
title: ?string,
isInApp: boolean,
preferEmbed: boolean,
};
function FileViewerEmbeddedTitle(props: Props) {
const { uri, title, isInApp, preferEmbed } = props;
const { uri, title, isInApp } = props;
let contentLink = `${formatLbryUrlForWeb(uri)}`;
@@ -29,22 +28,15 @@ function FileViewerEmbeddedTitle(props: Props) {
return (
<div className="file-viewer__embedded-header">
<div className="file-viewer__embedded-gradient" />
{preferEmbed ? (
<div className="file-viewer__embedded-title ">
<span dir="auto">{title}</span>
</div>
) : (
<Button
label={title}
aria-label={title}
button="link"
className="file-viewer__embedded-title"
{...contentLinkProps}
/>
)}
<Button
label={title}
aria-label={title}
button="link"
className="file-viewer__embedded-title"
{...contentLinkProps}
/>
<div className="file-viewer__embedded-info">
<Button className="file-viewer__overlay-logo" disabled={preferEmbed} aria-label={__('Home')} {...lbryLinkProps}>
<Button className="file-viewer__overlay-logo" aria-label={__('Home')} {...lbryLinkProps}>
<Logo type={'embed'} />
</Button>
{isInApp && <FilePrice uri={uri} />}
+6 -8
View File
@@ -1,4 +1,3 @@
import { DOMAIN } from 'config';
import { connect } from 'react-redux';
import { doSetDaemonSetting } from 'redux/actions/settings';
import { doSetWelcomeVersion, doToggle3PAnalytics, doSignOut } from 'redux/actions/app';
@@ -10,17 +9,16 @@ import { version as appVersion } from 'package.json';
import PrivacyAgreement from './view';
const select = state => ({
const select = (state) => ({
authenticated: selectUserVerifiedEmail(state),
});
const perform = dispatch => ({
setWelcomeVersion: version => dispatch(doSetWelcomeVersion(version || WELCOME_VERSION)),
setShareDataInternal: share => dispatch(doSetDaemonSetting(DAEMON_SETTINGS.SHARE_USAGE_DATA, share)),
setShareDataThirdParty: share => dispatch(doToggle3PAnalytics(share)),
const perform = (dispatch) => ({
setWelcomeVersion: (version) => dispatch(doSetWelcomeVersion(version || WELCOME_VERSION)),
setShareDataInternal: (share) => dispatch(doSetDaemonSetting(DAEMON_SETTINGS.SHARE_USAGE_DATA, share)),
setShareDataThirdParty: (share) => dispatch(doToggle3PAnalytics(share)),
signOut: () => dispatch(doSignOut()),
authenticateIfSharingData: () =>
dispatch(doAuthenticate(appVersion, undefined, undefined, true, undefined, undefined, DOMAIN)),
authenticateIfSharingData: () => dispatch(doAuthenticate(appVersion, undefined, undefined, true)), // appVersion, shareData?, shareCallback, callInstall
});
export default connect(select, perform)(PrivacyAgreement);
+1 -6
View File
@@ -449,12 +449,7 @@ function PublishFile(props: Props) {
{publishing && <Spinner type={'small'} />}
{inProgress && (
<div>
<Button
button="close"
label={__('New --[clears Publish Form]--')}
icon={ICONS.REFRESH}
onClick={clearPublish}
/>
<Button button="close" label={__('New')} icon={ICONS.REFRESH} onClick={clearPublish} />
</div>
)}
</div>
+16 -9
View File
@@ -1,24 +1,31 @@
import { connect } from 'react-redux';
import { makeSelectClaimForUri } from 'lbry-redux';
import { makeSelectClaimIsNsfw, makeSelectClaimForUri } from 'lbry-redux';
import { doRecommendationUpdate, doRecommendationClicked } from 'redux/actions/content';
import { doFetchRecommendedContent } from 'redux/actions/search';
import { makeSelectRecommendedContentForUri, selectIsSearching } from 'redux/selectors/search';
import { selectUserVerifiedEmail } from 'redux/selectors/user';
import { makeSelectNextUnplayedRecommended } from 'redux/selectors/content';
import RecommendedContent from './view';
const select = (state, props) => {
const claim = makeSelectClaimForUri(props.uri)(state);
const { claim_id: claimId } = claim;
const recommendedContentUris = makeSelectRecommendedContentForUri(props.uri)(state);
const nextRecommendedUri = recommendedContentUris && recommendedContentUris[0];
return {
claim,
claimId,
recommendedContentUris,
nextRecommendedUri,
mature: makeSelectClaimIsNsfw(props.uri)(state),
recommendedContentUris: makeSelectRecommendedContentForUri(props.uri)(state),
nextRecommendedUri: makeSelectNextUnplayedRecommended(props.uri)(state),
isSearching: selectIsSearching(state),
isAuthenticated: selectUserVerifiedEmail(state),
claim,
claimId,
};
};
export default connect(select, { doFetchRecommendedContent })(RecommendedContent);
const perform = (dispatch) => ({
doFetchRecommendedContent: (uri, mature) => dispatch(doFetchRecommendedContent(uri, mature)),
doRecommendationUpdate: (claimId, urls, id, parentId) =>
dispatch(doRecommendationUpdate(claimId, urls, id, parentId)),
doRecommendationClicked: (claimId, index) => dispatch(doRecommendationClicked(claimId, index)),
});
export default connect(select, perform)(RecommendedContent);
+41 -13
View File
@@ -18,9 +18,11 @@ type Props = {
recommendedContentUris: Array<string>,
nextRecommendedUri: string,
isSearching: boolean,
doFetchRecommendedContent: (string) => void,
doFetchRecommendedContent: (string, boolean) => void,
mature: boolean,
isAuthenticated: boolean,
claim: ?StreamClaim,
doRecommendationUpdate: (claimId: string, urls: Array<string>, id: string, parentId: string) => void,
claimId: string,
};
@@ -28,6 +30,7 @@ export default React.memo<Props>(function RecommendedContent(props: Props) {
const {
uri,
doFetchRecommendedContent,
mature,
recommendedContentUris,
nextRecommendedUri,
isSearching,
@@ -36,29 +39,53 @@ export default React.memo<Props>(function RecommendedContent(props: Props) {
claimId,
} = props;
const [viewMode, setViewMode] = React.useState(VIEW_ALL_RELATED);
const [recommendationUrls, setRecommendationUrls] = React.useState();
const signingChannel = claim && claim.signing_channel;
const channelName = signingChannel ? signingChannel.name : null;
const isMobile = useIsMobile();
const isMedium = useIsMediumScreen();
const { onRecsLoaded: onRecommendationsLoaded, onClickedRecommended: onRecommendationClicked } = RecSys;
React.useEffect(() => {
function moveAutoplayNextItemToTop(recommendedContent) {
let newList = recommendedContent;
if (newList) {
const index = newList.indexOf(nextRecommendedUri);
if (index > 0) {
const a = newList[0];
newList[0] = nextRecommendedUri;
newList[index] = a;
}
}
return newList;
}
function listEq(prev, next) {
if (prev && next) {
return prev.length === next.length && prev.every((value, index) => value === next[index]);
} else {
return prev === next;
}
}
const newRecommendationUrls = moveAutoplayNextItemToTop(recommendedContentUris);
if (claim && !listEq(recommendationUrls, newRecommendationUrls)) {
setRecommendationUrls(newRecommendationUrls);
}
}, [recommendedContentUris, nextRecommendedUri, recommendationUrls, setRecommendationUrls, claim]);
React.useEffect(() => {
doFetchRecommendedContent(uri);
}, [uri, doFetchRecommendedContent]);
doFetchRecommendedContent(uri, mature);
}, [uri, mature, doFetchRecommendedContent]);
React.useEffect(() => {
// Right now we only want to record the recs if they actually saw them.
if (
recommendedContentUris &&
recommendedContentUris.length &&
nextRecommendedUri &&
viewMode === VIEW_ALL_RELATED
) {
onRecommendationsLoaded(claimId, recommendedContentUris);
if (recommendationUrls && recommendationUrls.length && nextRecommendedUri && viewMode === VIEW_ALL_RELATED) {
onRecommendationsLoaded(claimId, recommendationUrls);
}
}, [recommendedContentUris, onRecommendationsLoaded, claimId, nextRecommendedUri, viewMode]);
}, [recommendationUrls, onRecommendationsLoaded, claimId, nextRecommendedUri, viewMode]);
function handleRecommendationClicked(e, clickedClaim) {
function handleRecommendationClicked(e, clickedClaim, index: number) {
if (claim) {
onRecommendationClicked(claim.claim_id, clickedClaim.claim_id);
}
@@ -97,7 +124,7 @@ export default React.memo<Props>(function RecommendedContent(props: Props) {
<ClaimList
type="small"
loading={isSearching}
uris={recommendedContentUris}
uris={recommendationUrls}
hideMenu={isMobile}
injectedItem={SHOW_ADS && IS_WEB && !isAuthenticated && <Ads small type={'video'} />}
empty={__('No related content found')}
@@ -137,6 +164,7 @@ function areEqual(prevProps: Props, nextProps: Props) {
a.nextRecommendedUri !== b.nextRecommendedUri ||
a.isAuthenticated !== b.isAuthenticated ||
a.isSearching !== b.isSearching ||
a.mature !== b.mature ||
(a.recommendedContentUris && !b.recommendedContentUris) ||
(!a.recommendedContentUris && b.recommendedContentUris) ||
(a.claim && !b.claim) ||
+3 -3
View File
@@ -17,8 +17,8 @@ type Props = {
winningUri: ?string,
doResolveUris: (Array<string>) => void,
hideLink?: boolean,
setChannelActive: (boolean) => void,
beginPublish: (string) => void,
setChannelActive: boolean => void,
beginPublish: string => void,
pendingIds: Array<string>,
isResolvingWinningUri: boolean,
winningClaim: ?Claim,
@@ -92,7 +92,7 @@ export default function SearchTopClaim(props: Props) {
hideRepostLabel
showNullPlaceholder
uri={winningUri}
properties={(claim) => (
properties={claim => (
<span className="claim-preview__custom-properties">
<ClaimRepostAuthor short uri={winningUri} />
<ClaimEffectiveAmount uri={winningUri} />
@@ -59,7 +59,6 @@ function UserChannelFollowIntro(props: Props) {
<div className="section__body">
<ClaimListDiscover
hideFilters={SIMPLE_SITE}
hideAdvancedFilter={SIMPLE_SITE}
meta={
<Button
button={subscribedChannels.length < 1 ? 'alt' : 'primary'}
+7 -7
View File
@@ -6,7 +6,6 @@ import {
COLLECTIONS_CONSTS,
makeSelectNextUrlForCollectionAndUrl,
makeSelectPreviousUrlForCollectionAndUrl,
makeSelectTagInClaimOrChannelForUri,
} from 'lbry-redux';
import {
doChangeVolume,
@@ -17,15 +16,18 @@ import {
} from 'redux/actions/app';
import { selectVolume, selectMute } from 'redux/selectors/app';
import { savePosition, clearPosition, doPlayUri, doSetPlayingUri } from 'redux/actions/content';
import { makeSelectContentPositionForUri, makeSelectIsPlayerFloating, selectPlayingUri } from 'redux/selectors/content';
import { makeSelectRecommendedContentForUri } from 'redux/selectors/search';
import {
makeSelectContentPositionForUri,
makeSelectIsPlayerFloating,
makeSelectNextUnplayedRecommended,
selectPlayingUri,
} from 'redux/selectors/content';
import VideoViewer from './view';
import { withRouter } from 'react-router';
import { doClaimEligiblePurchaseRewards } from 'redux/actions/rewards';
import { selectDaemonSettings, makeSelectClientSetting, selectHomepageData } from 'redux/selectors/settings';
import { toggleVideoTheaterMode, toggleAutoplayNext, doSetClientSetting } from 'redux/actions/settings';
import { selectUserVerifiedEmail, selectUser } from 'redux/selectors/user';
import { PREFERENCE_EMBED } from 'constants/tags';
const select = (state, props) => {
const { search } = props.location;
@@ -45,8 +47,7 @@ const select = (state, props) => {
nextRecommendedUri = makeSelectNextUrlForCollectionAndUrl(collectionId, uri)(state);
previousListUri = makeSelectPreviousUrlForCollectionAndUrl(collectionId, uri)(state);
} else {
const recommendedContent = makeSelectRecommendedContentForUri(uri)(state);
nextRecommendedUri = recommendedContent && recommendedContent[0];
nextRecommendedUri = makeSelectNextUnplayedRecommended(uri)(state);
}
return {
@@ -56,7 +57,6 @@ const select = (state, props) => {
nextRecommendedUri,
previousListUri,
isMarkdownOrComment,
preferEmbed: makeSelectTagInClaimOrChannelForUri(props.uri, PREFERENCE_EMBED)(state),
autoplayIfEmbedded: Boolean(autoplay),
autoplayNext: makeSelectClientSetting(SETTINGS.AUTOPLAY_NEXT)(state),
volume: selectVolume(state),
+1 -5
View File
@@ -64,7 +64,6 @@ type Props = {
previousListUri: string,
videoTheaterMode: boolean,
isMarkdownOrComment: boolean,
preferEmbed: boolean,
};
/*
@@ -107,7 +106,6 @@ function VideoViewer(props: Props) {
previousListUri,
videoTheaterMode,
isMarkdownOrComment,
preferEmbed,
} = props;
const permanentUrl = claim && claim.permanent_url;
const adApprovedChannelIds = homepageData ? getAllIds(homepageData) : [];
@@ -355,9 +353,7 @@ function VideoViewer(props: Props) {
// first play tracking, used for initializing the watchman api
player.on('tracking:firstplay', doTrackingFirstPlay);
player.on('ended', () => {
if (!preferEmbed) setEnded(true);
});
player.on('ended', () => setEnded(true));
player.on('play', onPlay);
player.on('pause', (event) => onPause(event, player));
player.on('dispose', (event) => onDispose(event, player));
+3 -11
View File
@@ -1,14 +1,7 @@
import { connect } from 'react-redux';
import {
doResolveUris,
makeSelectClaimForUri,
makeSelectIsUriResolving,
makeSelectTagInClaimOrChannelForUri,
parseURI,
} from 'lbry-redux';
import { doResolveUris, makeSelectClaimForUri, makeSelectIsUriResolving, parseURI } from 'lbry-redux';
import { makeSelectWinningUriForQuery } from 'redux/selectors/search';
import WunderbarTopSuggestion from './view';
import { PREFERENCE_EMBED } from 'constants/tags';
const select = (state, props) => {
const uriFromQuery = `lbry://${props.query}`;
@@ -23,12 +16,11 @@ const select = (state, props) => {
}
} catch (e) {}
const resolvingUris = uris.some((uri) => makeSelectIsUriResolving(uri)(state));
const resolvingUris = uris.some(uri => makeSelectIsUriResolving(uri)(state));
const winningUri = makeSelectWinningUriForQuery(props.query)(state);
const winningClaim = winningUri ? makeSelectClaimForUri(winningUri)(state) : undefined;
const preferEmbed = makeSelectTagInClaimOrChannelForUri(winningUri, PREFERENCE_EMBED)(state);
return { resolvingUris, winningUri, winningClaim, uris, preferEmbed };
return { resolvingUris, winningUri, winningClaim, uris };
};
export default connect(select, {
+2 -3
View File
@@ -8,11 +8,10 @@ type Props = {
doResolveUris: (Array<string>) => void,
uris: Array<string>,
resolvingUris: boolean,
preferEmbed: boolean,
};
export default function WunderbarTopSuggestion(props: Props) {
const { uris, resolvingUris, winningUri, doResolveUris, preferEmbed } = props;
const { uris, resolvingUris, winningUri, doResolveUris } = props;
const stringifiedUris = JSON.stringify(uris);
React.useEffect(() => {
@@ -39,7 +38,7 @@ export default function WunderbarTopSuggestion(props: Props) {
);
}
if (!winningUri || preferEmbed) {
if (!winningUri) {
return null;
}
-3
View File
@@ -13,11 +13,9 @@ export const SEARCH_TYPES = {
export const SEARCH_OPTIONS = {
RESULT_COUNT: 'size',
CLAIM_TYPE: 'claimType',
RELATED_TO: 'related_to',
INCLUDE_FILES: 'file',
INCLUDE_CHANNELS: 'channel',
INCLUDE_FILES_AND_CHANNELS: 'file,channel',
INCLUDE_MATURE: 'nsfw',
MEDIA_AUDIO: 'audio',
MEDIA_VIDEO: 'video',
MEDIA_TEXT: 'text',
@@ -27,7 +25,6 @@ export const SEARCH_OPTIONS = {
SORT_ACCENDING: '^release_time',
SORT_DESCENDING: 'release_time',
EXACT: 'exact',
PRICE_FILTER_FREE: 'free_only',
TIME_FILTER: 'time_filter',
TIME_FILTER_LAST_HOUR: 'lasthour',
TIME_FILTER_TODAY: 'today',
+1 -3
View File
@@ -14,10 +14,8 @@ export const DEFAULT_FOLLOWED_TAGS = [
];
export const DISABLE_COMMENTS_TAG = 'disable-comments';
export const DISABLE_SUPPORT_TAG = 'disable-support';
export const PREFERENCE_EMBED = 'preference-embed';
export const UTILITY_TAGS = [DISABLE_COMMENTS_TAG, DISABLE_SUPPORT_TAG, PREFERENCE_EMBED];
export const UTILITY_TAGS = [DISABLE_COMMENTS_TAG];
export const MATURE_TAGS = [
'porn',
+18 -17
View File
@@ -14,7 +14,7 @@ import * as MODALS from 'constants/modal_types';
import React, { Fragment, useState, useEffect } from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { doDaemonReady, doAutoUpdate, doOpenModal, doHideModal, doToggle3PAnalytics } from 'redux/actions/app';
import { doLbryReady, doAutoUpdate, doOpenModal, doHideModal, doToggle3PAnalytics } from 'redux/actions/app';
import { Lbry, isURIValid, apiCall } from 'lbry-redux';
import { setSearchApi } from 'redux/actions/search';
import { doSetLanguage, doFetchLanguage, doUpdateIsNightAsync } from 'redux/actions/settings';
@@ -28,12 +28,7 @@ import { formatLbryUrlForWeb, formatInAppUrl } from 'util/url';
import { PersistGate } from 'redux-persist/integration/react';
import analytics from 'analytics';
import { doToast } from 'redux/actions/notifications';
import {
getAuthToken,
setAuthToken,
doDeprecatedPasswordMigrationMarch2020,
doAuthTokenRefresh,
} from 'util/saved-passwords';
import { getAuthToken, setAuthToken, doAuthTokenRefresh, deleteAuthToken, getTokens } from 'util/saved-passwords';
import { X_LBRY_AUTH_TOKEN } from 'constants/token';
import { LBRY_WEB_API, DEFAULT_LANGUAGE, LBRY_API_URL, LBRY_WEB_PUBLISH_API } from 'config';
@@ -112,28 +107,34 @@ if (process.env.SEARCH_API_URL) {
setSearchApi(process.env.SEARCH_API_URL);
}
// Fix to make sure old users' cookies are set to the correct domain
// This can be removed after March 11th, 2021
// https://github.com/lbryio/lbry-desktop/pull/3830
doDeprecatedPasswordMigrationMarch2020();
doAuthTokenRefresh();
// TODO KEYCLOAK
if (getTokens().auth_token) {
doAuthTokenRefresh();
}
// We need to override Lbryio for getting/setting the authToken
// We interact with ipcRenderer to get the auth key from a users keyring
// We keep a local variable for authToken because `ipcRenderer.send` does not
// contain a response, so there is no way to know when it's been set
let authToken;
Lbryio.setOverride('setAuthToken', (authToken) => {
setAuthToken(authToken);
setAuthToken(authToken); // set the cookie to auth_token=
return authToken;
});
Lbryio.setOverride('deleteAuthToken', () => deleteAuthToken());
Lbryio.setOverride(
'getTokens',
() =>
new Promise((resolve) => {
resolve(getTokens());
})
);
Lbryio.setOverride(
'getAuthToken',
() =>
new Promise((resolve) => {
const authTokenToReturn = authToken || getAuthToken();
resolve(authTokenToReturn);
resolve(getAuthToken());
})
);
@@ -266,7 +267,7 @@ function AppWrapper() {
app.store.dispatch(doFetchLanguage(DEFAULT_LANGUAGE));
}
app.store.dispatch(doUpdateIsNightAsync());
app.store.dispatch(doDaemonReady());
app.store.dispatch(doLbryReady()); // get tokens, users, startup stuff
app.store.dispatch(doBlackListedOutpointsSubscribe());
app.store.dispatch(doFilteredOutpointsSubscribe());
+3 -6
View File
@@ -6,7 +6,7 @@ import { ipcRenderer, remote } from 'electron';
import path from 'path';
import * as ACTIONS from 'constants/action_types';
import * as MODALS from 'constants/modal_types';
import { DOMAIN, SIMPLE_SITE } from 'config';
import { SIMPLE_SITE } from 'config';
import {
Lbry,
doBalanceSubscribe,
@@ -353,7 +353,7 @@ export function doAlertWaitingForSync() {
};
}
export function doDaemonReady() {
export function doLbryReady() {
return (dispatch, getState) => {
const state = getState();
@@ -363,8 +363,6 @@ export function doDaemonReady() {
dispatch(
doAuthenticate(
appVersion,
undefined,
undefined,
shareUsageData,
(status) => {
const trendingAlgorithm =
@@ -377,8 +375,7 @@ export function doDaemonReady() {
analytics.trendingAlgorithmEvent(trendingAlgorithm);
}
},
undefined,
DOMAIN
undefined
)
);
dispatch({ type: ACTIONS.DAEMON_READY });
+14 -10
View File
@@ -21,7 +21,6 @@ import { doAlertWaitingForSync } from 'redux/actions/app';
const isDev = process.env.NODE_ENV !== 'production';
const FETCH_API_FAILED_TO_FETCH = 'Failed to fetch';
const PROMISE_FULFILLED = 'fulfilled';
declare type CommentronErrorMap = {
[string]: {
@@ -1378,7 +1377,9 @@ export function doFetchCommentModAmIList(channelClaim: ChannelClaim) {
const state = getState();
const myChannels = selectMyChannelClaims(state);
dispatch({ type: ACTIONS.COMMENT_MODERATION_AM_I_LIST_STARTED });
dispatch({
type: ACTIONS.COMMENT_MODERATION_AM_I_LIST_STARTED,
});
let channelSignatures = [];
@@ -1398,13 +1399,13 @@ export function doFetchCommentModAmIList(channelClaim: ChannelClaim) {
})
)
)
.then((results) => {
.then((res) => {
const delegatorsById = {};
results.forEach((result, index) => {
if (result.status === PROMISE_FULFILLED) {
const value = result.value;
delegatorsById[value.channel_id] = {
channelSignatures.forEach((chanSig, index) => {
if (chanSig && res[index]) {
const value = res[index].value;
delegatorsById[chanSig.claim_id] = {
global: value ? value.type === 'Global' : false,
delegators: value && value.authorized_channels ? value.authorized_channels : {},
};
@@ -1417,12 +1418,15 @@ export function doFetchCommentModAmIList(channelClaim: ChannelClaim) {
});
})
.catch((err) => {
devToast(dispatch, `AmI: ${err}`);
dispatch({ type: ACTIONS.COMMENT_MODERATION_AM_I_LIST_FAILED });
dispatch({
type: ACTIONS.COMMENT_MODERATION_AM_I_LIST_FAILED,
});
});
})
.catch(() => {
dispatch({ type: ACTIONS.COMMENT_MODERATION_AM_I_LIST_FAILED });
dispatch({
type: ACTIONS.COMMENT_MODERATION_AM_I_LIST_FAILED,
});
});
};
}
+6 -19
View File
@@ -1,15 +1,7 @@
// @flow
import * as ACTIONS from 'constants/action_types';
import { SEARCH_OPTIONS } from 'constants/search';
import { selectShowMatureContent } from 'redux/selectors/settings';
import {
buildURI,
doResolveUris,
batchActions,
isURIValid,
makeSelectClaimForUri,
makeSelectClaimIsNsfw,
} from 'lbry-redux';
import { buildURI, doResolveUris, batchActions, isURIValid, makeSelectClaimForUri } from 'lbry-redux';
import { makeSelectSearchUrisForQuery, selectSearchValue } from 'redux/selectors/search';
import handleFetchResponse from 'util/handle-fetch';
import { getSearchQueryString } from 'util/query-params';
@@ -133,26 +125,21 @@ export const doUpdateSearchOptions = (newOptions: SearchOptions, additionalOptio
}
};
export const doFetchRecommendedContent = (uri: string) => (dispatch: Dispatch, getState: GetState) => {
export const doFetchRecommendedContent = (uri: string, mature: boolean) => (dispatch: Dispatch, getState: GetState) => {
const state = getState();
const claim = makeSelectClaimForUri(uri)(state);
const matureEnabled = selectShowMatureContent(state);
const claimIsMature = makeSelectClaimIsNsfw(uri)(state);
if (claim && claim.value && claim.claim_id) {
const options: SearchOptions = { size: 20, nsfw: matureEnabled, isBackgroundSearch: true };
const options: SearchOptions = { size: 20, related_to: claim.claim_id, isBackgroundSearch: true };
if (!mature) {
options['nsfw'] = false;
}
if (SIMPLE_SITE) {
options[SEARCH_OPTIONS.CLAIM_TYPE] = SEARCH_OPTIONS.INCLUDE_FILES;
options[SEARCH_OPTIONS.MEDIA_VIDEO] = true;
options[SEARCH_OPTIONS.PRICE_FILTER_FREE] = true;
}
if (matureEnabled || !claimIsMature) {
options[SEARCH_OPTIONS.RELATED_TO] = claim.claim_id;
}
const { title } = claim.value;
if (title && options) {
dispatch(doSearch(title, options));
}
+38 -54
View File
@@ -50,11 +50,8 @@ export function doFetchInviteStatus(shouldCallRewardList = true) {
};
}
export function doInstallNew(appVersion, os = null, firebaseToken = null, callbackForUsersWhoAreSharingData, domain) {
export function doInstallNew(appVersion, callbackForUsersWhoAreSharingData, domain) {
const payload = { app_version: appVersion, domain };
if (firebaseToken) {
payload.firebase_token = firebaseToken;
}
Lbry.status().then((status) => {
payload.app_id =
@@ -64,7 +61,7 @@ export function doInstallNew(appVersion, os = null, firebaseToken = null, callba
payload.node_id = status.lbry_id;
Lbry.version().then((version) => {
payload.daemon_version = version.lbrynet_version;
payload.operating_system = os || version.os_system;
payload.operating_system = version.os_system;
payload.platform = version.platform;
Lbryio.call('install', 'new', payload);
@@ -75,33 +72,9 @@ export function doInstallNew(appVersion, os = null, firebaseToken = null, callba
});
}
export function doInstallNewWithParams(
appVersion,
installationId,
nodeId,
lbrynetVersion,
os,
platform,
firebaseToken = null
) {
return () => {
const payload = { app_version: appVersion };
if (firebaseToken) {
payload.firebase_token = firebaseToken;
}
payload.app_id = installationId;
payload.node_id = nodeId;
payload.daemon_version = lbrynetVersion;
payload.operating_system = os;
payload.platform = platform;
Lbryio.call('install', 'new', payload);
};
}
function checkAuthBusy() {
let time = Date.now();
return new Promise(function(resolve, reject) {
return new Promise(function (resolve, reject) {
(function waitForAuth() {
try {
sessionStorage.setItem('test', 'available');
@@ -131,48 +104,59 @@ function checkAuthBusy() {
}
// TODO: Call doInstallNew separately so we don't have to pass appVersion and os_system params?
/**
*
* @param appVersion
* @param shareUsageData
* @param callbackForUsersWhoAreSharingData
* @param callInstall
* @returns {Function}
*
* Lbryio.fetchUser:
* getTokens then getCurrentUser, and if !user, call userNew and return the user
*
*/
export function doAuthenticate(
appVersion,
os = null,
firebaseToken = null,
shareUsageData = true,
callbackForUsersWhoAreSharingData,
callInstall = true,
domain = null
callInstall = true
) {
return (dispatch) => {
return async (dispatch) => {
dispatch({
type: ACTIONS.AUTHENTICATION_STARTED,
});
checkAuthBusy()
.then(() => {
return Lbryio.authenticate(DOMAIN, getDefaultLanguage());
})
.then((user) => {
if (sessionStorageAvailable) window.sessionStorage.removeItem(AUTH_IN_PROGRESS);
Lbryio.getAuthToken().then((token) => {
try {
await checkAuthBusy();
const user = await Lbryio.fetchUser(DOMAIN, getDefaultLanguage());
console.log('USER', user);
if (sessionStorageAvailable) window.sessionStorage.removeItem(AUTH_IN_PROGRESS);
// put this back: accessToken: tokens.access_token
if (user.error) {
throw new Error(user.error.message);
} else {
Lbryio.getTokens().then((tokens) => {
dispatch({
type: ACTIONS.AUTHENTICATION_SUCCESS,
data: { user, accessToken: token },
data: { user, accessToken: tokens.auth_token }, // rename 'accessToken' = authToken
});
if (shareUsageData) {
dispatch(doRewardList());
dispatch(doFetchInviteStatus(false));
if (callInstall) {
doInstallNew(appVersion, os, firebaseToken, callbackForUsersWhoAreSharingData, domain);
doInstallNew(appVersion, callbackForUsersWhoAreSharingData, DOMAIN);
}
}
});
})
.catch((error) => {
if (sessionStorageAvailable) window.sessionStorage.removeItem(AUTH_IN_PROGRESS);
}
} catch (error) {
if (sessionStorageAvailable) window.sessionStorage.removeItem(AUTH_IN_PROGRESS);
dispatch({
type: ACTIONS.AUTHENTICATION_FAILURE,
data: { error },
});
dispatch({
type: ACTIONS.AUTHENTICATION_FAILURE,
data: { error },
});
}
};
}
@@ -183,7 +167,7 @@ export function doUserFetch() {
type: ACTIONS.USER_FETCH_STARTED,
});
Lbryio.getCurrentUser()
Lbryio.fetchCurrentUser()
.then((user) => {
dispatch({
type: ACTIONS.USER_FETCH_SUCCESS,
@@ -204,7 +188,7 @@ export function doUserFetch() {
export function doUserCheckEmailVerified() {
// This will happen in the background so we don't need loading booleans
return (dispatch) => {
Lbryio.getCurrentUser().then((user) => {
Lbryio.fetchCurrentUser().then((user) => {
if (user.has_verified_email) {
dispatch(doRewardList());
+47 -40
View File
@@ -24,37 +24,44 @@ const defaultState = {
invitees: undefined,
referralLink: undefined,
referralCode: undefined,
user: undefined,
accessToken: undefined,
user: { has_verified_email: false },
accessToken: undefined, // rename this
youtubeChannelImportPending: false,
youtubeChannelImportErrorMessage: '',
referrerSetIsPending: false,
referrerSetError: '',
};
reducers[ACTIONS.AUTHENTICATION_STARTED] = state =>
// does this do anything with user?
reducers[ACTIONS.AUTHENTICATION_STARTED] = (state) =>
Object.assign({}, state, {
authenticationIsPending: true,
userIsPending: true,
// distinguish accessToken from authToken
accessToken: defaultState.accessToken,
});
reducers[ACTIONS.AUTHENTICATION_SUCCESS] = (state, action) =>
reducers[ACTIONS.AUTHENTICATION_SUCCESS] = (state, action) => {
const newUserState = Object.assign({}, state, {
authenticationIsPending: false,
userIsPending: false,
});
if (action.data && action.data.user) {
newUserState.user = action.data.user;
}
if (action.data && action.data.accessToken) {
newUserState.accessToken = action.data.accessToken;
}
return newUserState;
};
reducers[ACTIONS.AUTHENTICATION_FAILURE] = (state) =>
Object.assign({}, state, {
authenticationIsPending: false,
userIsPending: false,
accessToken: action.data.accessToken,
user: action.data.user,
});
reducers[ACTIONS.AUTHENTICATION_FAILURE] = state =>
Object.assign({}, state, {
authenticationIsPending: false,
userIsPending: false,
user: null,
});
reducers[ACTIONS.USER_FETCH_STARTED] = state =>
reducers[ACTIONS.USER_FETCH_STARTED] = (state) =>
Object.assign({}, state, {
userIsPending: true,
});
@@ -66,7 +73,7 @@ reducers[ACTIONS.USER_FETCH_SUCCESS] = (state, action) =>
emailToVerify: action.data.user.has_verified_email ? null : state.emailToVerify,
});
reducers[ACTIONS.USER_FETCH_FAILURE] = state =>
reducers[ACTIONS.USER_FETCH_FAILURE] = (state) =>
Object.assign({}, state, {
userIsPending: true,
user: null,
@@ -88,7 +95,7 @@ reducers[ACTIONS.USER_PHONE_NEW_SUCCESS] = (state, action) =>
phoneNewIsPending: false,
});
reducers[ACTIONS.USER_PHONE_RESET] = state =>
reducers[ACTIONS.USER_PHONE_RESET] = (state) =>
Object.assign({}, state, {
phoneToVerify: null,
});
@@ -99,7 +106,7 @@ reducers[ACTIONS.USER_PHONE_NEW_FAILURE] = (state, action) =>
phoneNewErrorMessage: action.data.error,
});
reducers[ACTIONS.USER_PHONE_VERIFY_STARTED] = state =>
reducers[ACTIONS.USER_PHONE_VERIFY_STARTED] = (state) =>
Object.assign({}, state, {
phoneVerifyIsPending: true,
phoneVerifyErrorMessage: '',
@@ -118,7 +125,7 @@ reducers[ACTIONS.USER_PHONE_VERIFY_FAILURE] = (state, action) =>
phoneVerifyErrorMessage: action.data.error,
});
reducers[ACTIONS.USER_EMAIL_NEW_STARTED] = state =>
reducers[ACTIONS.USER_EMAIL_NEW_STARTED] = (state) =>
Object.assign({}, state, {
emailNewIsPending: true,
emailNewErrorMessage: '',
@@ -136,12 +143,12 @@ reducers[ACTIONS.USER_EMAIL_NEW_SUCCESS] = (state, action) => {
});
};
reducers[ACTIONS.USER_EMAIL_NEW_EXISTS] = state =>
reducers[ACTIONS.USER_EMAIL_NEW_EXISTS] = (state) =>
Object.assign({}, state, {
emailAlreadyExists: true,
});
reducers[ACTIONS.USER_EMAIL_NEW_DOES_NOT_EXIST] = state =>
reducers[ACTIONS.USER_EMAIL_NEW_DOES_NOT_EXIST] = (state) =>
Object.assign({}, state, {
emailDoesNotExist: true,
});
@@ -152,7 +159,7 @@ reducers[ACTIONS.USER_EMAIL_NEW_FAILURE] = (state, action) =>
emailNewErrorMessage: action.data.error,
});
reducers[ACTIONS.USER_EMAIL_NEW_CLEAR_ENTRY] = state => {
reducers[ACTIONS.USER_EMAIL_NEW_CLEAR_ENTRY] = (state) => {
const newUser = { ...state.user };
delete newUser.primary_email;
@@ -166,7 +173,7 @@ reducers[ACTIONS.USER_EMAIL_NEW_CLEAR_ENTRY] = state => {
});
};
reducers[ACTIONS.USER_PASSWORD_SET_CLEAR] = state =>
reducers[ACTIONS.USER_PASSWORD_SET_CLEAR] = (state) =>
Object.assign({}, state, {
passwordResetSuccess: false,
passwordResetPending: false,
@@ -175,7 +182,7 @@ reducers[ACTIONS.USER_PASSWORD_SET_CLEAR] = state =>
passwordSetSuccess: false,
});
reducers[ACTIONS.USER_EMAIL_VERIFY_STARTED] = state =>
reducers[ACTIONS.USER_EMAIL_VERIFY_STARTED] = (state) =>
Object.assign({}, state, {
emailVerifyIsPending: true,
emailVerifyErrorMessage: '',
@@ -202,7 +209,7 @@ reducers[ACTIONS.USER_EMAIL_VERIFY_SET] = (state, action) =>
emailToVerify: action.data.email,
});
reducers[ACTIONS.USER_IDENTITY_VERIFY_STARTED] = state =>
reducers[ACTIONS.USER_IDENTITY_VERIFY_STARTED] = (state) =>
Object.assign({}, state, {
identityVerifyIsPending: true,
identityVerifyErrorMessage: '',
@@ -229,7 +236,7 @@ reducers[ACTIONS.FETCH_ACCESS_TOKEN_SUCCESS] = (state, action) => {
});
};
reducers[ACTIONS.USER_INVITE_STATUS_FETCH_STARTED] = state =>
reducers[ACTIONS.USER_INVITE_STATUS_FETCH_STARTED] = (state) =>
Object.assign({}, state, {
inviteStatusIsPending: true,
});
@@ -243,13 +250,13 @@ reducers[ACTIONS.USER_INVITE_STATUS_FETCH_SUCCESS] = (state, action) =>
referralCode: action.data.referralCode,
});
reducers[ACTIONS.USER_INVITE_NEW_STARTED] = state =>
reducers[ACTIONS.USER_INVITE_NEW_STARTED] = (state) =>
Object.assign({}, state, {
inviteNewIsPending: true,
inviteNewErrorMessage: '',
});
reducers[ACTIONS.USER_INVITE_NEW_SUCCESS] = state =>
reducers[ACTIONS.USER_INVITE_NEW_SUCCESS] = (state) =>
Object.assign({}, state, {
inviteNewIsPending: false,
inviteNewErrorMessage: '',
@@ -261,14 +268,14 @@ reducers[ACTIONS.USER_INVITE_NEW_FAILURE] = (state, action) =>
inviteNewErrorMessage: action.data.error.message,
});
reducers[ACTIONS.USER_INVITE_STATUS_FETCH_FAILURE] = state =>
reducers[ACTIONS.USER_INVITE_STATUS_FETCH_FAILURE] = (state) =>
Object.assign({}, state, {
inviteStatusIsPending: false,
invitesRemaining: null,
invitees: null,
});
reducers[ACTIONS.USER_YOUTUBE_IMPORT_STARTED] = state =>
reducers[ACTIONS.USER_YOUTUBE_IMPORT_STARTED] = (state) =>
Object.assign({}, state, {
youtubeChannelImportPending: true,
youtubeChannelImportErrorMessage: '',
@@ -293,28 +300,28 @@ reducers[ACTIONS.USER_YOUTUBE_IMPORT_FAILURE] = (state, action) =>
youtubeChannelImportErrorMessage: action.data,
});
reducers[ACTIONS.USER_EMAIL_VERIFY_RETRY_STARTED] = state =>
reducers[ACTIONS.USER_EMAIL_VERIFY_RETRY_STARTED] = (state) =>
Object.assign({}, state, {
resendingVerificationEmail: true,
});
reducers[ACTIONS.USER_EMAIL_VERIFY_RETRY_SUCCESS] = state =>
reducers[ACTIONS.USER_EMAIL_VERIFY_RETRY_SUCCESS] = (state) =>
Object.assign({}, state, {
resendingVerificationEmail: false,
});
reducers[ACTIONS.USER_EMAIL_VERIFY_RETRY_FAILURE] = state =>
reducers[ACTIONS.USER_EMAIL_VERIFY_RETRY_FAILURE] = (state) =>
Object.assign({}, state, {
resendingVerificationEmail: false,
});
reducers[ACTIONS.USER_SET_REFERRER_STARTED] = state =>
reducers[ACTIONS.USER_SET_REFERRER_STARTED] = (state) =>
Object.assign({}, state, {
referrerSetIsPending: true,
referrerSetError: defaultState.referrerSetError,
});
reducers[ACTIONS.USER_SET_REFERRER_SUCCESS] = state =>
reducers[ACTIONS.USER_SET_REFERRER_SUCCESS] = (state) =>
Object.assign({}, state, {
referrerSetIsPending: false,
referrerSetError: defaultState.referrerSetError,
@@ -326,25 +333,25 @@ reducers[ACTIONS.USER_SET_REFERRER_FAILURE] = (state, action) =>
referrerSetError: action.data.error.message,
});
reducers[ACTIONS.USER_SET_REFERRER_RESET] = state =>
reducers[ACTIONS.USER_SET_REFERRER_RESET] = (state) =>
Object.assign({}, state, {
referrerSetIsPending: false,
referrerSetError: defaultState.referrerSetError,
});
reducers[ACTIONS.USER_PASSWORD_EXISTS] = state =>
reducers[ACTIONS.USER_PASSWORD_EXISTS] = (state) =>
Object.assign({}, state, {
passwordExistsForUser: true,
});
reducers[ACTIONS.USER_PASSWORD_RESET_STARTED] = state =>
reducers[ACTIONS.USER_PASSWORD_RESET_STARTED] = (state) =>
Object.assign({}, state, {
passwordResetPending: true,
passwordResetSuccess: defaultState.passwordResetSuccess,
passwordResetError: null,
});
reducers[ACTIONS.USER_PASSWORD_RESET_SUCCESS] = state =>
reducers[ACTIONS.USER_PASSWORD_RESET_SUCCESS] = (state) =>
Object.assign({}, state, {
passwordResetPending: false,
passwordResetSuccess: true,
@@ -356,13 +363,13 @@ reducers[ACTIONS.USER_PASSWORD_RESET_FAILURE] = (state, action) =>
passwordResetError: action.data.error,
});
reducers[ACTIONS.USER_PASSWORD_SET_STARTED] = state =>
reducers[ACTIONS.USER_PASSWORD_SET_STARTED] = (state) =>
Object.assign({}, state, {
passwordSetPending: true,
passwordSetSuccess: defaultState.passwordSetSuccess,
});
reducers[ACTIONS.USER_PASSWORD_SET_SUCCESS] = state =>
reducers[ACTIONS.USER_PASSWORD_SET_SUCCESS] = (state) =>
Object.assign({}, state, {
passwordSetPending: false,
passwordSetSuccess: true,
+81 -7
View File
@@ -7,10 +7,13 @@ import {
makeSelectClaimIsMine,
makeSelectMediaTypeForUri,
selectBalance,
parseURI,
makeSelectContentTypeForUri,
makeSelectFileNameForUri,
} from 'lbry-redux';
import { makeSelectCostInfoForUri } from 'lbryinc';
import { makeSelectRecommendedContentForUri } from 'redux/selectors/search';
import { selectMutedChannels } from 'redux/selectors/blocked';
import { selectAllCostInfoByUri, makeSelectCostInfoForUri } from 'lbryinc';
import { selectShowMatureContent } from 'redux/selectors/settings';
import * as RENDER_MODES from 'constants/file_render_modes';
import path from 'path';
@@ -32,14 +35,13 @@ export const makeSelectIsPlaying = (uri: string) =>
export const makeSelectIsPlayerFloating = (location: UrlLocation) =>
createSelector(selectPrimaryUri, selectPlayingUri, (primaryUri, playingUri) => {
const hasSecondarySource = playingUri && (playingUri.source === 'comment' || playingUri.source === 'markdown');
const isInlineSecondaryPlayer =
playingUri && playingUri.uri !== primaryUri && location.pathname === playingUri.pathname && hasSecondarySource;
playingUri &&
playingUri.uri !== primaryUri &&
location.pathname === playingUri.pathname &&
(playingUri.source === 'comment' || playingUri.source === 'markdown');
if (
(playingUri && (hasSecondarySource ? playingUri.primaryUri === primaryUri : playingUri.uri === primaryUri)) ||
isInlineSecondaryPlayer
) {
if ((playingUri && playingUri.primaryUri === primaryUri) || isInlineSecondaryPlayer) {
return false;
}
@@ -75,6 +77,78 @@ export const makeSelectHistoryForUri = (uri: string) =>
export const makeSelectHasVisitedUri = (uri: string) =>
createSelector(makeSelectHistoryForUri(uri), (history) => Boolean(history));
export const makeSelectNextUnplayedRecommended = (uri: string) =>
createSelector(
makeSelectRecommendedContentForUri(uri),
selectHistory,
selectClaimsByUri,
selectAllCostInfoByUri,
selectMutedChannels,
(
recommendedForUri: Array<string>,
history: Array<{ uri: string }>,
claimsByUri: { [string]: ?Claim },
costInfoByUri: { [string]: { cost: 0 | string } },
blockedChannels: Array<string>
) => {
if (recommendedForUri) {
// Make sure we don't autoplay paid content, channels, or content from blocked channels
for (let i = 0; i < recommendedForUri.length; i++) {
const recommendedUri = recommendedForUri[i];
const claim = claimsByUri[recommendedUri];
if (!claim) {
continue;
}
const { isChannel } = parseURI(recommendedUri);
if (isChannel) {
continue;
}
const costInfo = costInfoByUri[recommendedUri];
if (!costInfo || costInfo.cost !== 0) {
continue;
}
// We already check if it's a channel above
// $FlowFixMe
const isVideo = claim.value && claim.value.stream_type === 'video';
// $FlowFixMe
const isAudio = claim.value && claim.value.stream_type === 'audio';
if (!isVideo && !isAudio) {
continue;
}
const channel = claim && claim.signing_channel;
if (channel && blockedChannels.some((blockedUri) => blockedUri === channel.permanent_url)) {
continue;
}
const recommendedUriInfo = parseURI(recommendedUri);
const recommendedUriShort = recommendedUriInfo.claimName + '#' + recommendedUriInfo.claimId.substring(0, 1);
if (claimsByUri[uri] && claimsByUri[uri].claim_id === recommendedUriInfo.claimId) {
// Skip myself (same claim ID)
continue;
}
if (
!history.some((h) => {
const directMatch = h.uri === recommendedForUri[i];
const shortUriMatch = h.uri.includes(recommendedUriShort);
const idMatch = claimsByUri[h.uri] && claimsByUri[h.uri].claim_id === recommendedUriInfo.claimId;
return directMatch || shortUriMatch || idMatch;
})
) {
return recommendedForUri[i];
}
}
}
}
);
export const selectRecentHistory = createSelector(selectHistory, (history) => {
return history.slice(0, RECENT_HISTORY_AMOUNT);
});
+30 -90
View File
@@ -1,23 +1,18 @@
// @flow
import { getSearchQueryString } from 'util/query-params';
import { selectShowMatureContent } from 'redux/selectors/settings';
import { SEARCH_OPTIONS } from 'constants/search';
import {
parseURI,
selectClaimsByUri,
makeSelectClaimForUri,
makeSelectClaimForClaimId,
makeSelectClaimIsNsfw,
buildURI,
isClaimNsfw,
makeSelectPendingClaimForUri,
makeSelectIsUriResolving,
} from 'lbry-redux';
import { createSelector } from 'reselect';
import { createNormalizedSearchKey } from 'util/search';
import { selectMutedChannels } from 'redux/selectors/blocked';
import { selectHistory } from 'redux/selectors/content';
import { selectAllCostInfoByUri } from 'lbryinc';
import { SIMPLE_SITE } from 'config';
type State = { search: SearchState };
@@ -43,12 +38,14 @@ export const selectHasReachedMaxResultsLength: (state: State) => { [boolean]: Ar
);
export const makeSelectSearchUrisForQuery = (query: string): ((state: State) => Array<string>) =>
// replace statement below is kind of ugly, and repeated in doSearch action
createSelector(selectSearchResultByQuery, (byQuery) => {
if (!query) return;
// replace statement below is kind of ugly, and repeated in doSearch action
query = query.replace(/^lbry:\/\//i, '').replace(/\//, ' ');
const normalizedQuery = createNormalizedSearchKey(query);
return byQuery[normalizedQuery] && byQuery[normalizedQuery]['uris'];
if (query) {
query = query.replace(/^lbry:\/\//i, '').replace(/\//, ' ');
const normalizedQuery = createNormalizedSearchKey(query);
return byQuery[normalizedQuery] && byQuery[normalizedQuery]['uris'];
}
return byQuery[query] && byQuery[query]['uris'];
});
export const makeSelectHasReachedMaxResultsLength = (query: string): ((state: State) => boolean) =>
@@ -63,91 +60,34 @@ export const makeSelectHasReachedMaxResultsLength = (query: string): ((state: St
export const makeSelectRecommendedContentForUri = (uri: string) =>
createSelector(
selectHistory,
selectClaimsByUri,
selectShowMatureContent,
selectMutedChannels,
selectAllCostInfoByUri,
makeSelectClaimForUri(uri),
selectSearchResultByQuery,
makeSelectClaimIsNsfw(uri),
(history, claimsByUri, matureEnabled, blockedChannels, costInfoByUri, searchUrisByQuery, isMature) => {
const claim = claimsByUri[uri];
if (!claim) return;
(claim, searchUrisByQuery, isMature) => {
let recommendedContent;
// always grab the claimId - this value won't change for filtering
const currentClaimId = claim.claim_id;
if (claim) {
// always grab full URL - this can change once search returns canonical
const currentUri = buildURI({ streamClaimId: claim.claim_id, streamName: claim.name });
const { title } = claim.value;
const { title } = claim.value;
if (!title) return;
if (!title) {
return;
}
const options: {
size: number,
nsfw?: boolean,
isBackgroundSearch?: boolean,
} = { size: 20, nsfw: matureEnabled, isBackgroundSearch: true };
const options: {
related_to?: string,
nsfw?: boolean,
isBackgroundSearch?: boolean,
} = { related_to: claim.claim_id, isBackgroundSearch: true };
if (SIMPLE_SITE) {
options[SEARCH_OPTIONS.CLAIM_TYPE] = SEARCH_OPTIONS.INCLUDE_FILES;
options[SEARCH_OPTIONS.MEDIA_VIDEO] = true;
options[SEARCH_OPTIONS.PRICE_FILTER_FREE] = true;
}
if (matureEnabled || (!matureEnabled && !isMature)) {
options[SEARCH_OPTIONS.RELATED_TO] = claim.claim_id;
}
options['nsfw'] = isMature;
const searchQuery = getSearchQueryString(title.replace(/\//, ' '), options);
const normalizedSearchQuery = createNormalizedSearchKey(searchQuery);
const searchQuery = getSearchQueryString(title.replace(/\//, ' '), options);
const normalizedSearchQuery = createNormalizedSearchKey(searchQuery);
let searchResult = searchUrisByQuery[normalizedSearchQuery];
if (searchResult) {
// Filter from recommended: The same claim and blocked channels
recommendedContent = searchResult['uris'].filter((searchUri) => {
const searchClaim = claimsByUri[searchUri];
if (!searchClaim) return;
const signingChannel = searchClaim && searchClaim.signing_channel;
const channelUri = signingChannel && signingChannel.canonical_url;
const blockedMatch = blockedChannels.some((blockedUri) => blockedUri.includes(channelUri));
let isEqualUri;
try {
const { claimId: searchId } = parseURI(searchUri);
isEqualUri = searchId === currentClaimId;
} catch (e) {}
return !isEqualUri && !blockedMatch;
});
// Claim to play next: playable and free claims not played before in history
const nextUriToPlay = recommendedContent.filter((nextRecommendedUri) => {
const costInfo = costInfoByUri[nextRecommendedUri] && costInfoByUri[nextRecommendedUri].cost;
const recommendedClaim = claimsByUri[nextRecommendedUri];
const isVideo = recommendedClaim && recommendedClaim.value && recommendedClaim.value.stream_type === 'video';
const isAudio = recommendedClaim && recommendedClaim.value && recommendedClaim.value.stream_type === 'audio';
let historyMatch = false;
try {
const { claimId: nextRecommendedId } = parseURI(nextRecommendedUri);
historyMatch = history.some(
(historyItem) =>
(claimsByUri[historyItem.uri] && claimsByUri[historyItem.uri].claim_id) === nextRecommendedId
);
} catch (e) {}
return !historyMatch && costInfo === 0 && (isVideo || isAudio);
})[0];
const index = recommendedContent.indexOf(nextUriToPlay);
if (index > 0) {
const a = recommendedContent[0];
recommendedContent[0] = nextUriToPlay;
recommendedContent[index] = a;
let searchResult = searchUrisByQuery[normalizedSearchQuery];
if (searchResult) {
recommendedContent = searchResult['uris'].filter((searchUri) => searchUri !== currentUri);
}
}
return recommendedContent;
@@ -266,6 +206,6 @@ export const makeSelectIsResolvingWinningUri = (query: string = '') => {
};
export const makeSelectUrlForClaimId = (claimId: string) =>
createSelector(makeSelectClaimForClaimId(claimId), (claim) =>
claim ? claim.canonical_url || claim.permanent_url : null
createSelector(
makeSelectClaimForClaimId(claimId), (claim) => claim ? claim.canonical_url || claim.permanent_url : null
);
+2 -2
View File
@@ -62,6 +62,6 @@
}
.embed__overlay-logo {
max-height: 2rem;
max-width: 7rem;
max-height: 3.5rem;
max-width: 12rem;
}
-4
View File
@@ -301,10 +301,6 @@
.file-viewer__embedded-title {
max-width: 75%;
z-index: 2;
display: flex;
align-items: center;
padding-left: var(--spacing-s);
color: white;
}
.file-viewer__embedded-info {
+2 -7
View File
@@ -190,18 +190,13 @@
.file-page__recommended {
width: 25rem;
@media (max-width: $breakpoint-medium) {
width: 100%;
}
}
.file-page__secondary-content {
padding: 0 var(--spacing-s);
flex-direction: row;
@media (max-width: $breakpoint-medium) {
flex-direction: column;
@media (min-width: $breakpoint-medium) {
flex-direction: row;
}
}
}
+9 -7
View File
@@ -11,7 +11,7 @@ import { routerMiddleware } from 'connected-react-router';
import createRootReducer from './reducers';
import { Lbry, buildSharedStateMiddleware, ACTIONS as LBRY_REDUX_ACTIONS } from 'lbry-redux';
import { doSyncLoop } from 'redux/actions/sync';
import { getAuthToken } from 'util/saved-passwords';
import { getTokens } from 'util/saved-passwords';
import { generateInitialUrl } from 'util/url';
import { X_LBRY_AUTH_TOKEN } from 'constants/token';
@@ -189,12 +189,14 @@ const sharedStateCb = ({ dispatch, getState }) => {
const populateAuthTokenHeader = () => {
return (next) => (action) => {
if (
(action.type === ACTIONS.USER_FETCH_SUCCESS || action.type === ACTIONS.AUTHENTICATION_SUCCESS) &&
action.data.user.has_verified_email === true
) {
const authToken = getAuthToken();
Lbry.setApiHeader(X_LBRY_AUTH_TOKEN, authToken);
if (action.type === ACTIONS.USER_FETCH_SUCCESS || action.type === ACTIONS.AUTHENTICATION_SUCCESS) {
if (action.data) {
}
const tokens = getTokens();
// if (tokens.access_token) {
// Lbry.setApiHeader('Authorization', 'Bearer ' + tokens.access_token);
// }
Lbry.setApiHeader(X_LBRY_AUTH_TOKEN, tokens.auth_token);
}
return next(action);
+12 -4
View File
@@ -1,5 +1,6 @@
// @flow
import { SEARCH_OPTIONS } from 'constants/search';
import { SIMPLE_SITE } from 'config';
const DEFAULT_SEARCH_RESULT_FROM = 0;
const DEFAULT_SEARCH_SIZE = 20;
@@ -32,6 +33,7 @@ export function updateQueryParam(uri: string, key: string, value: string) {
}
export const getSearchQueryString = (query: string, options: any = {}) => {
const FORCE_FREE_ONLY = SIMPLE_SITE;
const isSurroundedByQuotes = (str) => str[0] === '"' && str[str.length - 1] === '"';
const encodedQuery = encodeURIComponent(query);
const queryParams = [
@@ -79,11 +81,9 @@ export const getSearchQueryString = (query: string, options: any = {}) => {
const additionalOptions = {};
const { related_to } = options;
const { nsfw } = options;
const { free_only } = options;
if (related_to) additionalOptions[SEARCH_OPTIONS.RELATED_TO] = related_to;
if (free_only) additionalOptions[SEARCH_OPTIONS.PRICE_FILTER_FREE] = true;
if (nsfw === false) additionalOptions[SEARCH_OPTIONS.INCLUDE_MATURE] = false;
if (related_to) additionalOptions['related_to'] = related_to;
if (nsfw === false) additionalOptions['nsfw'] = false;
if (additionalOptions) {
Object.keys(additionalOptions).forEach((key) => {
@@ -92,5 +92,13 @@ export const getSearchQueryString = (query: string, options: any = {}) => {
});
}
if (FORCE_FREE_ONLY) {
const index = queryParams.findIndex((q) => q.startsWith('free_only'));
if (index > -1) {
queryParams.splice(index, 1);
}
queryParams.push(`free_only=true`);
}
return queryParams.join('&');
};
+16 -10
View File
@@ -1,4 +1,4 @@
const { DOMAIN } = require('../../config.js');
const { DOMAIN } = require('config.js');
const AUTH_TOKEN = 'auth_token';
const SAVED_PASSWORD = 'saved_password';
const DEPRECATED_SAVED_PASSWORD = 'saved-password';
@@ -59,7 +59,7 @@ function deleteCookie(name) {
}
function setSavedPassword(value, saveToDisk) {
return new Promise(resolve => {
return new Promise((resolve) => {
const password = value === undefined || value === null ? '' : value;
sessionPassword = password;
@@ -74,17 +74,17 @@ function setSavedPassword(value, saveToDisk) {
}
function getSavedPassword() {
return new Promise(resolve => {
return new Promise((resolve) => {
if (sessionPassword) {
resolve(sessionPassword);
}
return getPasswordFromCookie().then(p => resolve(p));
return getPasswordFromCookie().then((p) => resolve(p));
});
}
function getPasswordFromCookie() {
return new Promise(resolve => {
return new Promise((resolve) => {
let password;
password = getCookie(SAVED_PASSWORD);
resolve(password);
@@ -92,7 +92,7 @@ function getPasswordFromCookie() {
}
function deleteSavedPassword() {
return new Promise(resolve => {
return new Promise((resolve) => {
deleteCookie(SAVED_PASSWORD);
resolve();
});
@@ -102,19 +102,24 @@ function getAuthToken() {
return getCookie(AUTH_TOKEN);
}
// will take oidc token getter
function getTokens() {
return { auth_token: getAuthToken(), access_token: null };
}
function setAuthToken(value) {
return setCookie(AUTH_TOKEN, value, 365);
}
function deleteAuthToken() {
return new Promise(resolve => {
return new Promise((resolve) => {
deleteCookie(AUTH_TOKEN);
resolve();
});
}
function doSignOutCleanup() {
return new Promise(resolve => {
return new Promise((resolve) => {
deleteAuthToken();
deleteSavedPassword();
resolve();
@@ -122,10 +127,10 @@ function doSignOutCleanup() {
}
function doAuthTokenRefresh() {
const authToken = getAuthToken();
const { auth_token: authToken } = getAuthToken();
if (authToken) {
deleteAuthToken();
setAuthToken(authToken);
setCookie(AUTH_TOKEN, authToken, 365);
}
}
@@ -147,6 +152,7 @@ module.exports = {
deleteSavedPassword,
getAuthToken,
setAuthToken,
getTokens,
deleteAuthToken,
doSignOutCleanup,
doAuthTokenRefresh,
@@ -1,10 +1,7 @@
import { connect } from 'react-redux';
import fileViewerEmbeddedEnded from './view';
import { selectUserVerifiedEmail } from 'redux/selectors/user';
import { makeSelectTagInClaimOrChannelForUri } from 'lbry-redux';
import { PREFERENCE_EMBED } from 'constants/tags';
export default connect((state, props) => ({
export default connect(state => ({
isAuthenticated: selectUserVerifiedEmail(state),
preferEmbed: makeSelectTagInClaimOrChannelForUri(props.uri, PREFERENCE_EMBED)(state),
}))(fileViewerEmbeddedEnded);
+13 -21
View File
@@ -9,11 +9,10 @@ import Logo from 'component/logo';
type Props = {
uri: string,
isAuthenticated: boolean,
preferEmbed: boolean,
};
function FileViewerEmbeddedEnded(props: Props) {
const { uri, isAuthenticated, preferEmbed } = props;
const { uri, isAuthenticated } = props;
const prompts = isAuthenticated
? {
@@ -38,28 +37,21 @@ function FileViewerEmbeddedEnded(props: Props) {
return (
<div className="file-viewer__overlay">
<div className="file-viewer__overlay-secondary">
<Button className="file-viewer__overlay-logo" href={URL} disabled={preferEmbed}>
<Button className="file-viewer__overlay-logo" href={URL}>
<Logo type={'embed'} />
</Button>
</div>
{!preferEmbed && (
<>
<div className="file-viewer__overlay-title file-viewer_embed-ended-title">{prompt}</div>
<div className="file-viewer__overlay-actions">
{ /* add button to replay? */ }
<>
<Button label={__('Rewatch or Discuss')} button="primary" href={lbrytvLink} />
{!isAuthenticated && (
<Button
label={__('Join %SITE_NAME%', { SITE_NAME })}
button="secondary"
href={`${URL}/$/signup?src=embed_signup`}
/>
)}
</>
</div>
</>
)}
<div className="file-viewer__overlay-title file-viewer_embed-ended-title">{prompt}</div>
<div className="file-viewer__overlay-actions">
<Button label={__('Rewatch or Discuss')} button="primary" href={lbrytvLink} />
{!isAuthenticated && (
<Button
label={__('Join %SITE_NAME%', { SITE_NAME })}
button="secondary"
href={`${URL}/$/signup?src=embed_signup`}
/>
)}
</div>
</div>
);
}
@@ -230,8 +230,7 @@
}
.file-viewer__overlay-logo {
height: 2rem;
max-height: 2rem; //embed logo height?
height: 3.5rem;
width: 12rem;
display: flex;
align-items: center;
@@ -314,7 +313,6 @@
}
.file-viewer__embedded-title {
color: white;
max-width: 75%;
z-index: 2;
}
-12
View File
@@ -1,12 +0,0 @@
const fs = require('fs');
const path = require('path');
let robots;
async function getRobots(ctx) {
if (!robots) {
robots = fs.readFileSync(path.join(__dirname, '/../dist/public/robots.txt'), 'utf8');
}
return robots;
}
module.exports = { getRobots };
+2 -2
View File
@@ -10148,9 +10148,9 @@ lbry-redux@lbryio/lbry-redux#32b578707116d45f5b51b7ab523d200e75668676:
reselect "^3.0.0"
uuid "^8.3.1"
lbryinc@lbryio/lbryinc#0b4e41ef90d6347819dd3453f2f9398a5c1b4f36:
lbryinc@lbryio/lbryinc#c9ced4f226e06f4f188cb8dc31b561e1c27c5266:
version "0.0.1"
resolved "https://codeload.github.com/lbryio/lbryinc/tar.gz/0b4e41ef90d6347819dd3453f2f9398a5c1b4f36"
resolved "https://codeload.github.com/lbryio/lbryinc/tar.gz/c9ced4f226e06f4f188cb8dc31b561e1c27c5266"
dependencies:
reselect "^3.0.0"