Skip to content

Commit

Permalink
fix paid content - thanks tom
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Yesmunt committed Aug 2, 2019
1 parent 0eb409c commit 0b897c3
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 103 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
"jsmediatags": "^3.8.1",
"json-loader": "^0.5.4",
"lbry-format": "https://github.com/lbryio/lbry-format.git",
"lbry-redux": "lbryio/lbry-redux#1b7bb1cc9f2cb6a8efcce1869031d4da8ddbf4ca",
"lbry-redux": "lbryio/lbry-redux#66f70c7745d23e79f9e8ec9ca32ef9d3a576688e",
"lbryinc": "lbryio/lbryinc#a93596c51c8fb0a226cb84df04c26a6bb60a45fb",
"lint-staged": "^7.0.2",
"localforage": "^1.7.1",
Expand Down
28 changes: 3 additions & 25 deletions src/ui/component/fileActions/view.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// @flow
import type { ElementRef } from 'react';
import * as MODALS from 'constants/modal_types';
import * as ICONS from 'constants/icons';
import React from 'react';
import Button from 'component/button';
import Tooltip from 'component/common/tooltip';
import { requestFullscreen, fullscreenElement } from 'util/full-screen';

type FileInfo = {
claim_id: string,
Expand All @@ -17,37 +15,17 @@ type Props = {
openModal: (id: string, { uri: string }) => void,
claimIsMine: boolean,
fileInfo: FileInfo,
viewerContainer: { current: ElementRef<any> },
showFullscreen: boolean,
};

class FileActions extends React.PureComponent<Props> {
maximizeViewer = () => {
const { viewerContainer } = this.props;
const isFullscreen = fullscreenElement();
// Request fullscreen if viewer is ready
// And if there is no fullscreen element active
if (!isFullscreen && viewerContainer && viewerContainer.current !== null) {
requestFullscreen(viewerContainer.current);
}
};

render() {
const { fileInfo, uri, openModal, claimIsMine, claimId, showFullscreen } = this.props;
const { fileInfo, uri, openModal, claimIsMine, claimId } = this.props;
const showDelete = claimIsMine || (fileInfo && Object.keys(fileInfo).length > 0);
// fix me
// const showDelete = claimIsMine || (fileInfo && fileInfo.writtenBytes > 0 || fileInfo.blobs_completed;

return (
<React.Fragment>
{showFullscreen && (
<Tooltip label={__('Full screen (f)')}>
<Button
button="link"
description={__('Fullscreen')}
icon={ICONS.FULLSCREEN}
onClick={this.maximizeViewer}
/>
</Tooltip>
)}
{showDelete && (
<Tooltip label={__('Remove from your library')}>
<Button
Expand Down
2 changes: 1 addition & 1 deletion src/ui/component/fileViewer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const select = (state, props) => ({
});

const perform = dispatch => ({
play: (uri, saveFile) => dispatch(doPlayUri(uri, saveFile)),
play: uri => dispatch(doPlayUri(uri)),
});

export default connect(
Expand Down
1 change: 0 additions & 1 deletion src/ui/constants/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ export const OS_NOTIFICATIONS_ENABLED = 'osNotificationsEnabled';
export const AUTO_DOWNLOAD = 'autoDownload';
export const SUPPORT_OPTION = 'supportOption';
export const HIDE_BALANCE = 'hideBalance';
export const MAX_CONNECTIONS = 'maxConnections';
6 changes: 2 additions & 4 deletions src/ui/modal/modalAffirmPurchase/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { connect } from 'react-redux';
import { doSetPlayingUri } from 'redux/actions/content';
import { doSetPlayingUri, doPlayUri } from 'redux/actions/content';
import { doHideModal } from 'redux/actions/app';
import { makeSelectMetadataForUri } from 'lbry-redux';
import ModalAffirmPurchase from './view';
Expand All @@ -14,9 +14,7 @@ const perform = dispatch => ({
dispatch(doHideModal());
},
closeModal: () => dispatch(doHideModal()),
loadVideo: uri => {
throw Error('sean you need to fix this');
},
loadVideo: uri => dispatch(doPlayUri(uri, true)),
});

export default connect(
Expand Down
27 changes: 4 additions & 23 deletions src/ui/page/file/view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import * as MODALS from 'constants/modal_types';
import * as icons from 'constants/icons';
import * as React from 'react';
import { Lbry, buildURI, normalizeURI } from 'lbry-redux';
import { buildURI, normalizeURI } from 'lbry-redux';
import FileViewer from 'component/fileViewer';
import FilePrice from 'component/filePrice';
import FileDetails from 'component/fileDetails';
Expand Down Expand Up @@ -35,7 +35,7 @@ type Props = {
channelUri: string,
viewCount: number,
prepareEdit: ({}, string, {}) => void,
openModal: (id: string, { uri: string, claimIsMine: boolean, isSupport: boolean }) => void,
openModal: (id: string, { uri: string, claimIsMine?: boolean, isSupport?: boolean }) => void,
markSubscriptionRead: (string, string) => void,
fetchViewCount: string => void,
balance: number,
Expand All @@ -45,15 +45,6 @@ type Props = {
};

class FilePage extends React.Component<Props> {
static PREVIEW_MEDIA_TYPES = ['text', 'model', 'image', 'script', 'document', '3D-file', 'comic-book'];

constructor(props: Props) {
super(props);
(this: any).viewerContainer = React.createRef();
}

viewerContainer: { current: React.ElementRef<any> };

componentDidMount() {
const {
uri,
Expand Down Expand Up @@ -135,12 +126,7 @@ class FilePage extends React.Component<Props> {
// File info
const { signing_channel: signingChannel } = claim;
const channelName = signingChannel && signingChannel.name;
const { PREVIEW_MEDIA_TYPES } = FilePage;
const isRewardContent = (rewardedContentClaimIds || []).includes(claim.claim_id);
const fileName = fileInfo ? fileInfo.file_name : null;
const mediaType = Lbry.getMediaType(contentType, fileName);
const isPreviewType = PREVIEW_MEDIA_TYPES.includes(mediaType);

const speechShareable =
costInfo && costInfo.cost === 0 && contentType && ['video', 'image', 'audio'].includes(contentType.split('/')[0]);
// We want to use the short form uri for editing
Expand Down Expand Up @@ -173,7 +159,7 @@ class FilePage extends React.Component<Props> {
{__('or send more LBC to your wallet.')}
</div>
)}
<FileViewer uri={uri} viewerContainer={this.viewerContainer} insufficientCredits={insufficientCredits} />
<FileViewer uri={uri} insufficientCredits={insufficientCredits} />
</div>

<div className="columns">
Expand Down Expand Up @@ -231,12 +217,7 @@ class FilePage extends React.Component<Props> {

<div className="media__action-group--large">
<FileDownloadLink uri={uri} />
<FileActions
uri={uri}
claimId={claim.claim_id}
showFullscreen={isPreviewType}
viewerContainer={this.viewerContainer}
/>
<FileActions uri={uri} claimId={claim.claim_id} />
</div>
</div>
</div>
Expand Down
1 change: 0 additions & 1 deletion src/ui/page/settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const select = state => ({
autoDownload: makeSelectClientSetting(settings.AUTO_DOWNLOAD)(state),
supportOption: makeSelectClientSetting(settings.SUPPORT_OPTION)(state),
hideBalance: makeSelectClientSetting(settings.HIDE_BALANCE)(state),
maxConnections: makeSelectClientSetting(settings.MAX_CONNECTIONS)(state),
});

const perform = dispatch => ({
Expand Down
9 changes: 2 additions & 7 deletions src/ui/page/settings/view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ class SettingsPage extends React.PureComponent<Props, State> {
componentDidMount() {
this.props.getThemes();
this.props.updateWalletStatus();

const { daemonSettings } = this.props;
this.props.setClientSetting(SETTINGS.MAX_CONNECTIONS, daemonSettings.max_connections_per_download);
}

onKeyFeeChange(newValue: Price) {
Expand All @@ -88,7 +85,6 @@ class SettingsPage extends React.PureComponent<Props, State> {
onMaxConnectionsChange(event: SyntheticInputEvent<*>) {
const { value } = event.target;
this.setDaemonSetting('max_connections_per_download', value);
this.props.setClientSetting(SETTINGS.MAX_CONNECTIONS, value);
}

onKeyFeeDisableChange(isDisabled: boolean) {
Expand Down Expand Up @@ -167,7 +163,6 @@ class SettingsPage extends React.PureComponent<Props, State> {
setClientSetting,
supportOption,
hideBalance,
maxConnections,
} = this.props;

const noDaemonSettings = !daemonSettings || Object.keys(daemonSettings).length === 0;
Expand Down Expand Up @@ -211,7 +206,7 @@ class SettingsPage extends React.PureComponent<Props, State> {
onChange={() => setDaemonSetting('save_files', !daemonSettings.save_files)}
checked={daemonSettings.save_files}
label={__(
'Enables saving of all viewed content to your downloads directory. Some file types are saved by default.'
'Enables saving of all viewed content to your downloads directory. Paid content and some file types are saved by default.'
)}
helper={__('This is not retroactive, only works from the time it was changed.')}
/>
Expand Down Expand Up @@ -240,7 +235,7 @@ class SettingsPage extends React.PureComponent<Props, State> {
min={1}
max={100}
onChange={this.onMaxConnectionsChange}
value={maxConnections}
value={daemonSettings.max_connections_per_download}
>
{connectionOptions.map(connectionOption => (
<option key={connectionOption} value={connectionOption}>
Expand Down
77 changes: 40 additions & 37 deletions src/ui/redux/actions/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import {
parseURI,
doPurchaseUri,
makeSelectUriIsStreamable,
selectDownloadingByOutpoint,
} from 'lbry-redux';
import { makeSelectCostInfoForUri } from 'lbryinc';
import { makeSelectClientSetting, selectosNotificationsEnabled } from 'redux/selectors/settings';
import { makeSelectClientSetting, selectosNotificationsEnabled, selectDaemonSettings } from 'redux/selectors/settings';
import { formatLbryUriForWeb } from 'util/uri';

const DOWNLOAD_POLL_INTERVAL = 250;
Expand Down Expand Up @@ -179,63 +180,65 @@ export function doFetchClaimsByChannel(uri: string, page: number = 1, pageSize:
};
}

export function doPurchaseUriWrapper(uri: string, costInfo: {}, saveFile: boolean) {
export function doPurchaseUriWrapper(uri: string, cost: number, saveFile: boolean) {
return (dispatch: Dispatch, getState: () => any) => {
const state = getState();
const isUriStreamable = makeSelectUriIsStreamable(uri)(state);

function onSuccess(fileInfo) {
dispatch(doUpdateLoadStatus(uri, fileInfo.outpoint));
}

// Only pass the sucess callback for non streamable files because we don't show the download percentage while streaming
const successCallBack = isUriStreamable ? undefined : onSuccess;
dispatch(doPurchaseUri(uri, costInfo, saveFile, successCallBack));
// Only pass the sucess callback if we are saving the file, otherwise we don't show the download percentage
const successCallBack = saveFile ? onSuccess : undefined;
dispatch(doPurchaseUri(uri, { costInfo: cost }, saveFile, successCallBack));
};
}

export function doPlayUri(uri: string, saveFile: boolean) {
export function doPlayUri(uri: string, skipCostCheck: boolean = false, saveFileOverride: boolean = false) {
return (dispatch: Dispatch, getState: () => any) => {
function attemptPlay(cost, instantPurchaseMax = null) {
// If you have a file entry with correct manifest, you won't pay for the key fee again
if (cost > 0 && (!instantPurchaseMax || cost > instantPurchaseMax) && !fileInfo) {
dispatch(doOpenModal(MODALS.AFFIRM_PURCHASE, { uri }));
} else {
dispatch(doPurchaseUriWrapper(uri, { costInfo: cost }, saveFile));
}
}

// Set the active playing uri so we can avoid showing error notifications if a previously started download fails
dispatch(doSetPlayingUri(uri));

const state = getState();
const fileInfo = makeSelectFileInfoForUri(uri)(state);
const { cost } = makeSelectCostInfoForUri(uri)(state);
const uriIsStreamable = makeSelectUriIsStreamable(uri)(state);
const downloadingByOutpoint = selectDownloadingByOutpoint(state);
const alreadyDownloaded = fileInfo && (fileInfo.completed || (fileInfo.blobs_remaining === 0 && uriIsStreamable));
const alreadyDownloading = fileInfo && !!downloadingByOutpoint[fileInfo.outpoint];
if (alreadyDownloading || alreadyDownloaded) {
return;
}

const daemonSettings = selectDaemonSettings(state);
const costInfo = makeSelectCostInfoForUri(uri)(state);
const cost = Number(costInfo.cost);
const saveFile = !uriIsStreamable ? true : daemonSettings.save_files || saveFileOverride || cost > 0;
const instantPurchaseEnabled = makeSelectClientSetting(SETTINGS.INSTANT_PURCHASE_ENABLED)(state);
const instantPurchaseMax = makeSelectClientSetting(SETTINGS.INSTANT_PURCHASE_MAX)(state);

// we already fully downloaded the file.
if (fileInfo && fileInfo.completed && (fileInfo.status === 'stopped' || fileInfo.status === 'finished')) {
// If path is null or bytes written is 0 means the user has deleted/moved the
// file manually on their file system, so we need to dispatch a
// doPurchaseUri action to reconstruct the file from the blobs
if (!fileInfo.download_path || !fileInfo.written_bytes) {
dispatch(doPurchaseUriWrapper(uri, { costInfo: cost }, saveFile));
function beginGetFile() {
dispatch(doPurchaseUriWrapper(uri, cost, saveFile));
}

function attemptPlay(instantPurchaseMax = null) {
// If you have a file_list entry, you have already purchased the file
if (!fileInfo && (!instantPurchaseMax || cost > instantPurchaseMax)) {
dispatch(doOpenModal(MODALS.AFFIRM_PURCHASE, { uri }));
} else {
beginGetFile();
}
}

if (cost === 0 || skipCostCheck) {
beginGetFile();
return;
}

if (cost === 0 || !makeSelectClientSetting(SETTINGS.INSTANT_PURCHASE_ENABLED)(state)) {
attemptPlay(cost);
if (instantPurchaseEnabled || instantPurchaseMax.currency === 'LBC') {
attemptPlay(instantPurchaseMax.amount);
} else {
const instantPurchaseMax = makeSelectClientSetting(SETTINGS.INSTANT_PURCHASE_MAX)(state);
if (instantPurchaseMax.currency === 'LBC') {
attemptPlay(cost, instantPurchaseMax.amount);
} else {
// Need to convert currency of instant purchase maximum before trying to play
Lbryapi.getExchangeRates().then(({ LBC_USD }) => {
attemptPlay(cost, instantPurchaseMax.amount / LBC_USD);
});
}
// Need to convert currency of instant purchase maximum before trying to play
Lbryapi.getExchangeRates().then(({ LBC_USD }) => {
attemptPlay(instantPurchaseMax.amount / LBC_USD);
});
}
};
}
Expand Down
1 change: 0 additions & 1 deletion src/ui/redux/reducers/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const defaultState = {
[SETTINGS.AUTO_DOWNLOAD]: getLocalStorageSetting(SETTINGS.AUTO_DOWNLOAD, true),
[SETTINGS.OS_NOTIFICATIONS_ENABLED]: Boolean(getLocalStorageSetting(SETTINGS.OS_NOTIFICATIONS_ENABLED, true)),
[SETTINGS.HIDE_BALANCE]: Boolean(getLocalStorageSetting(SETTINGS.HIDE_BALANCE, false)),
[SETTINGS.MAX_CONNECTIONS]: Number(getLocalStorageSetting(SETTINGS.MAX_CONNECTIONS, 4)),
},
isNight: false,
languages: { en: 'English', pl: 'Polish', id: 'Bahasa Indonesia' }, // temporarily hard code these so we can advance i18n testing
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6643,9 +6643,9 @@ lazy-val@^1.0.3, lazy-val@^1.0.4:
yargs "^13.2.2"
zstd-codec "^0.1.1"

lbry-redux@lbryio/lbry-redux#1b7bb1cc9f2cb6a8efcce1869031d4da8ddbf4ca:
lbry-redux@lbryio/lbry-redux#66f70c7745d23e79f9e8ec9ca32ef9d3a576688e:
version "0.0.1"
resolved "https://codeload.github.com/lbryio/lbry-redux/tar.gz/1b7bb1cc9f2cb6a8efcce1869031d4da8ddbf4ca"
resolved "https://codeload.github.com/lbryio/lbry-redux/tar.gz/66f70c7745d23e79f9e8ec9ca32ef9d3a576688e"
dependencies:
mime "^2.4.4"
proxy-polyfill "0.1.6"
Expand Down

0 comments on commit 0b897c3

Please sign in to comment.