1 download per channel; do download/notify on subscribe
This commit is contained in:
parent
02c20d090e
commit
a6393aaf17
2 changed files with 21 additions and 23 deletions
|
@ -5,7 +5,7 @@ import * as SETTINGS from 'constants/settings';
|
||||||
import rewards from 'rewards';
|
import rewards from 'rewards';
|
||||||
import type { Dispatch, SubscriptionNotifications } from 'redux/reducers/subscriptions';
|
import type { Dispatch, SubscriptionNotifications } from 'redux/reducers/subscriptions';
|
||||||
import type { Subscription } from 'types/subscription';
|
import type { Subscription } from 'types/subscription';
|
||||||
import { selectSubscriptions, selectDownloadingCount } from 'redux/selectors/subscriptions';
|
import { selectSubscriptions } from 'redux/selectors/subscriptions';
|
||||||
import { makeSelectClientSetting } from 'redux/selectors/settings';
|
import { makeSelectClientSetting } from 'redux/selectors/settings';
|
||||||
import { Lbry, buildURI, parseURI } from 'lbry-redux';
|
import { Lbry, buildURI, parseURI } from 'lbry-redux';
|
||||||
import { doPurchaseUri } from 'redux/actions/content';
|
import { doPurchaseUri } from 'redux/actions/content';
|
||||||
|
@ -14,7 +14,7 @@ import Promise from 'bluebird';
|
||||||
import Lbryio from 'lbryio';
|
import Lbryio from 'lbryio';
|
||||||
|
|
||||||
const CHECK_SUBSCRIPTIONS_INTERVAL = 15 * 60 * 1000;
|
const CHECK_SUBSCRIPTIONS_INTERVAL = 15 * 60 * 1000;
|
||||||
const SUBSCRIPTION_DOWNLOAD_LIMIT = 3;
|
const SUBSCRIPTION_DOWNLOAD_LIMIT = 1;
|
||||||
|
|
||||||
export const doFetchMySubscriptions = () => (dispatch: Dispatch, getState: () => any) => {
|
export const doFetchMySubscriptions = () => (dispatch: Dispatch, getState: () => any) => {
|
||||||
const {
|
const {
|
||||||
|
@ -124,11 +124,10 @@ export const setSubscriptionNotification = (
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const doCheckSubscription = (
|
export const doCheckSubscription = (subscription: Subscription, notify?: boolean) => (
|
||||||
subscription: Subscription,
|
dispatch: Dispatch,
|
||||||
notify?: boolean,
|
getState: () => {}
|
||||||
preventDownload?: boolean
|
) => {
|
||||||
) => (dispatch: Dispatch, getState: () => {}) => {
|
|
||||||
// no dispatching FETCH_CHANNEL_CLAIMS_STARTED; causes loading issues on <SubscriptionsPage>
|
// no dispatching FETCH_CHANNEL_CLAIMS_STARTED; causes loading issues on <SubscriptionsPage>
|
||||||
|
|
||||||
Lbry.claim_list_by_channel({ uri: subscription.uri, page: 1 }).then(result => {
|
Lbry.claim_list_by_channel({ uri: subscription.uri, page: 1 }).then(result => {
|
||||||
|
@ -140,12 +139,11 @@ export const doCheckSubscription = (
|
||||||
);
|
);
|
||||||
|
|
||||||
if (claimsInChannel.length && latestIndex !== 0) {
|
if (claimsInChannel.length && latestIndex !== 0) {
|
||||||
|
let downloadCount = 0;
|
||||||
claimsInChannel.slice(0, latestIndex === -1 ? 10 : latestIndex).forEach(claim => {
|
claimsInChannel.slice(0, latestIndex === -1 ? 10 : latestIndex).forEach(claim => {
|
||||||
const uri = buildURI({ contentName: claim.name, claimId: claim.claim_id }, false);
|
const uri = buildURI({ contentName: claim.name, claimId: claim.claim_id }, false);
|
||||||
const state = getState();
|
const state = getState();
|
||||||
const downloadCount = selectDownloadingCount(state);
|
|
||||||
const shouldDownload = Boolean(
|
const shouldDownload = Boolean(
|
||||||
!preventDownload &&
|
|
||||||
downloadCount < SUBSCRIPTION_DOWNLOAD_LIMIT &&
|
downloadCount < SUBSCRIPTION_DOWNLOAD_LIMIT &&
|
||||||
!claim.value.stream.metadata.fee &&
|
!claim.value.stream.metadata.fee &&
|
||||||
makeSelectClientSetting(SETTINGS.AUTO_DOWNLOAD)(state)
|
makeSelectClientSetting(SETTINGS.AUTO_DOWNLOAD)(state)
|
||||||
|
@ -160,6 +158,7 @@ export const doCheckSubscription = (
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (shouldDownload) {
|
if (shouldDownload) {
|
||||||
|
downloadCount += 1;
|
||||||
dispatch(doPurchaseUri(uri, { cost: 0 }));
|
dispatch(doPurchaseUri(uri, { cost: 0 }));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -233,7 +232,7 @@ export const doChannelSubscribe = (subscription: Subscription) => (
|
||||||
dispatch(doClaimRewardType(rewards.SUBSCRIPTION, { failSilently: true }));
|
dispatch(doClaimRewardType(rewards.SUBSCRIPTION, { failSilently: true }));
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch(doCheckSubscription(subscription, false, true));
|
dispatch(doCheckSubscription(subscription, true));
|
||||||
};
|
};
|
||||||
|
|
||||||
export const doChannelUnsubscribe = (subscription: Subscription) => (
|
export const doChannelUnsubscribe = (subscription: Subscription) => (
|
||||||
|
@ -267,7 +266,10 @@ export const doCheckSubscriptions = () => (dispatch: Dispatch, getState: () => a
|
||||||
};
|
};
|
||||||
|
|
||||||
export const doCheckSubscriptionsInit = () => (dispatch: Dispatch) => {
|
export const doCheckSubscriptionsInit = () => (dispatch: Dispatch) => {
|
||||||
setTimeout(() => dispatch(doCheckSubscriptions()), 5000); // bad fix for not getting subs on load
|
// doCheckSubscriptionsInit is called by doDaemonReady
|
||||||
|
// setTimeout below is a hack to ensure redux is hydrated when subscriptions are checked
|
||||||
|
// this will be replaced with <PersistGate> which reqiures a package upgrade
|
||||||
|
setTimeout(() => dispatch(doCheckSubscriptions()), 5000);
|
||||||
const checkSubscriptionsTimer = setInterval(
|
const checkSubscriptionsTimer = setInterval(
|
||||||
() => dispatch(doCheckSubscriptions()),
|
() => dispatch(doCheckSubscriptions()),
|
||||||
CHECK_SUBSCRIPTIONS_INTERVAL
|
CHECK_SUBSCRIPTIONS_INTERVAL
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import * as NOTIFICATION_TYPES from 'constants/notification_types';
|
|
||||||
import { createSelector } from 'reselect';
|
import { createSelector } from 'reselect';
|
||||||
import {
|
import {
|
||||||
selectAllClaimsByChannel,
|
selectAllClaimsByChannel,
|
||||||
|
@ -44,11 +43,13 @@ export const selectSubscriptionClaims = createSelector(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchedSubscriptions = fetchedSubscriptions.concat([{
|
fetchedSubscriptions = fetchedSubscriptions.concat([
|
||||||
|
{
|
||||||
claims: [...channelClaims],
|
claims: [...channelClaims],
|
||||||
channelName: subscription.channelName,
|
channelName: subscription.channelName,
|
||||||
uri: subscription.uri,
|
uri: subscription.uri,
|
||||||
}]);
|
},
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
return [...fetchedSubscriptions];
|
return [...fetchedSubscriptions];
|
||||||
|
@ -70,8 +71,3 @@ export const selectSubscriptionsBeingFetched = createSelector(
|
||||||
return fetchingSubscriptionMap;
|
return fetchingSubscriptionMap;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
export const selectDownloadingCount = createSelector(
|
|
||||||
selectNotifications,
|
|
||||||
notifs => Object.values(notifs).reduce((acc, notif) => notif.type === NOTIFICATION_TYPES.DOWNLOADING ? acc + 1 : acc, 0)
|
|
||||||
);
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue