fixes: canonical url + sub downloads

Sub downloads is just missing the last step - need to check why it's not being resolved/saved.
This commit is contained in:
Thomas Zarebczan 2019-08-29 19:18:06 -04:00 committed by Sean Yesmunt
parent 4e3bd44f4e
commit 3d4e35e32f
11 changed files with 37 additions and 42 deletions

View file

@ -129,7 +129,7 @@
"jsmediatags": "^3.8.1", "jsmediatags": "^3.8.1",
"json-loader": "^0.5.4", "json-loader": "^0.5.4",
"lbry-format": "https://github.com/lbryio/lbry-format.git", "lbry-format": "https://github.com/lbryio/lbry-format.git",
"lbry-redux": "lbryio/lbry-redux#a9e2cc91838af340d4566b384b20d7b0af8e68df", "lbry-redux": "lbryio/lbry-redux#48dd46a9a837d81cff8700b7a571baa8081bf3aa",
"lbryinc": "lbryio/lbryinc#1ce266b3c52654190b955e9c869b8e302aa5c585", "lbryinc": "lbryio/lbryinc#1ce266b3c52654190b955e9c869b8e302aa5c585",
"lint-staged": "^7.0.2", "lint-staged": "^7.0.2",
"localforage": "^1.7.1", "localforage": "^1.7.1",

View file

@ -82,7 +82,7 @@ const ClaimPreview = forwardRef<any, {}>((props: Props, ref: any) => {
let isValid = false; let isValid = false;
if (uri) { if (uri) {
try { try {
({ claimName: name } = parseURI(uri)); ({ streamName: name } = parseURI(uri));
isValid = true; isValid = true;
} catch (e) { } catch (e) {
isValid = false; isValid = false;

View file

@ -102,13 +102,13 @@ function PublishForm(props: Props) {
// We are only going to store the full uri, but we need to resolve the uri with and without the channel name // We are only going to store the full uri, but we need to resolve the uri with and without the channel name
let uri; let uri;
try { try {
uri = buildURI({ contentName: name, channelName }); uri = buildURI({ streamName: name, channelName });
} catch (e) {} } catch (e) {}
if (channelName) { if (channelName) {
// resolve without the channel name so we know the winning bid for it // resolve without the channel name so we know the winning bid for it
try { try {
const uriLessChannel = buildURI({ contentName: name }); const uriLessChannel = buildURI({ streamName: name });
resolveUri(uriLessChannel); resolveUri(uriLessChannel);
} catch (e) {} } catch (e) {}
} }

View file

@ -19,8 +19,8 @@ function NameHelpText(props: Props) {
nameHelpText = __('You are currently editing this claim. If you change the URL, you will need to reselect a file.'); nameHelpText = __('You are currently editing this claim. If you change the URL, you will need to reselect a file.');
} else if (uri && myClaimForUri) { } else if (uri && myClaimForUri) {
const editUri = buildURI({ const editUri = buildURI({
contentName: myClaimForUri.name, streamName: myClaimForUri.name,
claimId: myClaimForUri.claim_id, streamClaimId: myClaimForUri.claim_id,
}); });
nameHelpText = ( nameHelpText = (

View file

@ -68,7 +68,7 @@ function AppRouter(props: Props) {
<Route path={`/$/${PAGES.BLOCKED}`} exact component={ListBlocked} /> <Route path={`/$/${PAGES.BLOCKED}`} exact component={ListBlocked} />
{/* Below need to go at the end to make sure we don't match any of our pages first */} {/* Below need to go at the end to make sure we don't match any of our pages first */}
<Route path="/:claimName" exact component={ShowPage} /> <Route path="/:claimName" exact component={ShowPage} />
<Route path="/:claimName/:contentName" exact component={ShowPage} /> <Route path="/:claimName/:streamName" exact component={ShowPage} />
{/* Route not found. Mostly for people typing crazy urls into the url */} {/* Route not found. Mostly for people typing crazy urls into the url */}
<Route render={() => <Redirect to="/" />} /> <Route render={() => <Redirect to="/" />} />

View file

@ -35,7 +35,8 @@ export default function SubscribeButton(props: Props) {
} = props; } = props;
const buttonRef = useRef(); const buttonRef = useRef();
const isHovering = useHover(buttonRef); const isHovering = useHover(buttonRef);
const { claimName } = parseURI(uri); const { channelName } = parseURI(uri);
const claimName = '@' + channelName;
const subscriptionHandler = isSubscribed ? doChannelUnsubscribe : doChannelSubscribe; const subscriptionHandler = isSubscribed ? doChannelUnsubscribe : doChannelSubscribe;
const subscriptionLabel = isSubscribed ? __('Following') : __('Follow'); const subscriptionLabel = isSubscribed ? __('Following') : __('Follow');
const unfollowOverride = isSubscribed && isHovering && __('Unfollow'); const unfollowOverride = isSubscribed && isHovering && __('Unfollow');

View file

@ -45,10 +45,10 @@ class TransactionListItem extends React.PureComponent<Props> {
// Ensure the claim name exists and is valid // Ensure the claim name exists and is valid
let uri; let uri;
let claimName = name; let streamName = name;
try { try {
({ claimName } = parseURI(name)); ({ streamName } = parseURI(name));
uri = buildURI({ claimName: claimName, claimId }); uri = buildURI({ streamName, streamClaimId: claimId });
} catch (e) {} } catch (e) {}
const dateFormat = { const dateFormat = {
@ -74,7 +74,7 @@ class TransactionListItem extends React.PureComponent<Props> {
</td> </td>
<td> <td>
{reward && <span>{reward.reward_title}</span>} {reward && <span>{reward.reward_title}</span>}
{name && claimId && <Button button="link" navigate={uri} label={claimName} />} {name && claimId && <Button button="link" navigate={uri} label={streamName} />}
</td> </td>
<td> <td>

View file

@ -111,7 +111,7 @@ function ChannelPage(props: Props) {
/> />
)} )}
<h1 className="channel__title"> <h1 className="channel__title">
{title || channelName} {title || '@' + channelName}
{channelIsMine && !editing && ( {channelIsMine && !editing && (
<Button title={__('Edit')} onClick={() => setEditing(!editing)} icon={ICONS.EDIT} iconSize={49} /> <Button title={__('Edit')} onClick={() => setEditing(!editing)} icon={ICONS.EDIT} iconSize={49} />
)} )}

View file

@ -14,7 +14,6 @@ import {
SETTINGS, SETTINGS,
Lbry, Lbry,
Lbryapi, Lbryapi,
buildURI,
makeSelectFileInfoForUri, makeSelectFileInfoForUri,
selectFileInfosByOutpoint, selectFileInfosByOutpoint,
makeSelectChannelForClaimUri, makeSelectChannelForClaimUri,
@ -67,14 +66,15 @@ export function doUpdateLoadStatus(uri: string, outpoint: string) {
}); });
const channelUri = makeSelectChannelForClaimUri(uri, true)(state); const channelUri = makeSelectChannelForClaimUri(uri, true)(state);
const { claimName: channelName } = parseURI(channelUri); const { channelName } = parseURI(channelUri);
const claimName = '@' + channelName;
const unreadForChannel = makeSelectUnreadByChannel(channelUri)(state); const unreadForChannel = makeSelectUnreadByChannel(channelUri)(state);
if (unreadForChannel && unreadForChannel.type === NOTIFICATION_TYPES.DOWNLOADING) { if (unreadForChannel && unreadForChannel.type === NOTIFICATION_TYPES.DOWNLOADING) {
const count = unreadForChannel.uris.length; const count = unreadForChannel.uris.length;
if (selectosNotificationsEnabled(state)) { if (selectosNotificationsEnabled(state)) {
const notif = new window.Notification(channelName, { const notif = new window.Notification(claimName, {
body: `Posted ${fileInfo.metadata.title}${ body: `Posted ${fileInfo.metadata.title}${
count > 1 && count < 10 ? ` and ${count - 1} other new items` : '' count > 1 && count < 10 ? ` and ${count - 1} other new items` : ''
}${count > 9 ? ' and 9+ other new items' : ''}`, }${count > 9 ? ' and 9+ other new items' : ''}`,
@ -154,10 +154,10 @@ export function doFetchClaimsByChannel(uri: string, page: number = 1, pageSize:
dispatch( dispatch(
setSubscriptionLatest( setSubscriptionLatest(
{ {
channelName: latest.channel_name, channelName: latest.signing_channel.name,
uri: latest.signing_channel.canonical_url, uri: latest.signing_channel.permanent_url,
}, },
buildURI({ streamName: latest.name, streamClaimId: latest.claim_id }, false) latest.permanent_url
) )
); );
} }
@ -201,7 +201,7 @@ export function doPlayUri(uri: string, skipCostCheck: boolean = false, saveFileO
const daemonSettings = selectDaemonSettings(state); const daemonSettings = selectDaemonSettings(state);
const costInfo = makeSelectCostInfoForUri(uri)(state); const costInfo = makeSelectCostInfoForUri(uri)(state);
const cost = Number(costInfo.cost); const cost = (costInfo && Number(costInfo.cost)) || 0;
const saveFile = !uriIsStreamable ? true : daemonSettings.save_files || saveFileOverride || cost > 0; const saveFile = !uriIsStreamable ? true : daemonSettings.save_files || saveFileOverride || cost > 0;
const instantPurchaseEnabled = makeSelectClientSetting(SETTINGS.INSTANT_PURCHASE_ENABLED)(state); const instantPurchaseEnabled = makeSelectClientSetting(SETTINGS.INSTANT_PURCHASE_ENABLED)(state);
const instantPurchaseMax = makeSelectClientSetting(SETTINGS.INSTANT_PURCHASE_MAX)(state); const instantPurchaseMax = makeSelectClientSetting(SETTINGS.INSTANT_PURCHASE_MAX)(state);

View file

@ -6,7 +6,8 @@ import * as NOTIFICATION_TYPES from 'constants/subscriptions';
import { Lbryio, rewards, doClaimRewardType } from 'lbryinc'; import { Lbryio, rewards, doClaimRewardType } from 'lbryinc';
import { selectSubscriptions, selectUnreadByChannel } from 'redux/selectors/subscriptions'; import { selectSubscriptions, selectUnreadByChannel } from 'redux/selectors/subscriptions';
import { makeSelectClientSetting } from 'redux/selectors/settings'; import { makeSelectClientSetting } from 'redux/selectors/settings';
import { Lbry, buildURI, parseURI, doResolveUris, doPurchaseUri } from 'lbry-redux'; import { Lbry, parseURI, doResolveUris } from 'lbry-redux';
import { doPlayUri } from 'redux/actions/content';
const CHECK_SUBSCRIPTIONS_INTERVAL = 15 * 60 * 1000; const CHECK_SUBSCRIPTIONS_INTERVAL = 15 * 60 * 1000;
const SUBSCRIPTION_DOWNLOAD_LIMIT = 1; const SUBSCRIPTION_DOWNLOAD_LIMIT = 1;
@ -47,8 +48,8 @@ export const doFetchMySubscriptions = () => (dispatch: Dispatch, getState: GetSt
const subscriptionsToReturn = reduxSubscriptions.slice(); const subscriptionsToReturn = reduxSubscriptions.slice();
reduxSubscriptions.forEach(sub => { reduxSubscriptions.forEach(sub => {
const { claimId } = parseURI(sub.uri); const { channelClaimId } = parseURI(sub.uri);
reduxSubMap[claimId] = 1; reduxSubMap[channelClaimId] = 1;
}); });
storedSubscriptions.forEach(sub => { storedSubscriptions.forEach(sub => {
@ -218,9 +219,7 @@ export const doCheckSubscription = (subscriptionUri: string, shouldNotify?: bool
} }
// Determine if the latest subscription currently saved is actually the latest subscription // Determine if the latest subscription currently saved is actually the latest subscription
const latestIndex = claimsInChannel.findIndex( const latestIndex = claimsInChannel.findIndex(claim => claim.permanent_url === savedSubscription.latest);
claim => `${claim.name}#${claim.claim_id}` === savedSubscription.latest
);
// If latest is -1, it is a newly subscribed channel or there have been 10+ claims published since last viewed // If latest is -1, it is a newly subscribed channel or there have been 10+ claims published since last viewed
const latestIndexToNotify = latestIndex === -1 ? 10 : latestIndex; const latestIndexToNotify = latestIndex === -1 ? 10 : latestIndex;
@ -232,7 +231,7 @@ export const doCheckSubscription = (subscriptionUri: string, shouldNotify?: bool
const newUnread = []; const newUnread = [];
claimsInChannel.slice(0, latestIndexToNotify).forEach(claim => { claimsInChannel.slice(0, latestIndexToNotify).forEach(claim => {
const uri = buildURI({ contentName: claim.name, claimId: claim.claim_id }, true); const uri = claim.permanent_url;
const shouldDownload = const shouldDownload =
shouldAutoDownload && Boolean(downloadCount < SUBSCRIPTION_DOWNLOAD_LIMIT && !claim.value.fee); shouldAutoDownload && Boolean(downloadCount < SUBSCRIPTION_DOWNLOAD_LIMIT && !claim.value.fee);
@ -243,7 +242,8 @@ export const doCheckSubscription = (subscriptionUri: string, shouldNotify?: bool
if (shouldDownload) { if (shouldDownload) {
downloadCount += 1; downloadCount += 1;
dispatch(doPurchaseUri(uri, { cost: 0 }, true)); // this fails since something is not resolved/saved somewhere...
dispatch(doPlayUri(uri, true, true));
} }
}); });
@ -262,10 +262,10 @@ export const doCheckSubscription = (subscriptionUri: string, shouldNotify?: bool
dispatch( dispatch(
setSubscriptionLatest( setSubscriptionLatest(
{ {
channelName: latest.channel_name, channelName: latest.signing_channel.name,
uri: latest.signing_channel.canonical_url, uri: latest.signing_channel.permanent_url,
}, },
buildURI({ streamName: latest.name, streamClaimId: latest.claim_id }, false) latest.permanent_url
) )
); );
@ -300,11 +300,11 @@ export const doChannelSubscribe = (subscription: Subscription) => (dispatch: Dis
// if the user isn't sharing data, keep the subscriptions entirely in the app // if the user isn't sharing data, keep the subscriptions entirely in the app
if (isSharingData) { if (isSharingData) {
const { claimId } = parseURI(subscription.uri); const { channelClaimId } = parseURI(subscription.uri);
// They are sharing data, we can store their subscriptions in our internal database // They are sharing data, we can store their subscriptions in our internal database
Lbryio.call('subscription', 'new', { Lbryio.call('subscription', 'new', {
channel_name: subscription.channelName, channel_name: subscription.channelName,
claim_id: claimId, claim_id: channelClaimId,
}); });
dispatch(doClaimRewardType(rewards.TYPE_SUBSCRIPTION, { failSilently: true })); dispatch(doClaimRewardType(rewards.TYPE_SUBSCRIPTION, { failSilently: true }));
@ -325,9 +325,9 @@ export const doChannelUnsubscribe = (subscription: Subscription) => (dispatch: D
}); });
if (isSharingData) { if (isSharingData) {
const { claimId } = parseURI(subscription.uri); const { channelClaimId } = parseURI(subscription.uri);
Lbryio.call('subscription', 'delete', { Lbryio.call('subscription', 'delete', {
claim_id: claimId, claim_id: channelClaimId,
}); });
} }
}; };

View file

@ -1,10 +1,4 @@
import { import { selectClaimsByUri, selectIsFetchingClaimListMine, selectMyClaims, selectClaimsById } from 'lbry-redux';
selectClaimsByUri,
selectIsFetchingClaimListMine,
selectMyClaims,
selectClaimsById,
buildURI,
} from 'lbry-redux';
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
export const selectState = state => state.fileInfo || {}; export const selectState = state => state.fileInfo || {};