fix subscription notification and download glitches
This commit is contained in:
parent
10d66aeece
commit
69c285025c
1 changed files with 39 additions and 33 deletions
|
@ -13,7 +13,7 @@ import { doPurchaseUri } from 'redux/actions/content';
|
||||||
import Promise from 'bluebird';
|
import Promise from 'bluebird';
|
||||||
import Lbryio from 'lbryio';
|
import Lbryio from 'lbryio';
|
||||||
|
|
||||||
const CHECK_SUBSCRIPTIONS_INTERVAL = 60 * 60 * 1000;
|
const CHECK_SUBSCRIPTIONS_INTERVAL = 15 * 60 * 1000;
|
||||||
const SUBSCRIPTION_DOWNLOAD_LIMIT = 1;
|
const SUBSCRIPTION_DOWNLOAD_LIMIT = 1;
|
||||||
|
|
||||||
export const doFetchMySubscriptions = () => (dispatch: Dispatch, getState: () => any) => {
|
export const doFetchMySubscriptions = () => (dispatch: Dispatch, getState: () => any) => {
|
||||||
|
@ -127,6 +127,7 @@ export const setSubscriptionNotification = (
|
||||||
export const doCheckSubscription = (subscription: Subscription, notify?: boolean) => (
|
export const doCheckSubscription = (subscription: Subscription, notify?: boolean) => (
|
||||||
dispatch: Dispatch
|
dispatch: Dispatch
|
||||||
) => {
|
) => {
|
||||||
|
// this action is not implemented
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.CHECK_SUBSCRIPTION_STARTED,
|
type: ACTIONS.CHECK_SUBSCRIPTION_STARTED,
|
||||||
data: subscription,
|
data: subscription,
|
||||||
|
@ -136,28 +137,31 @@ export const doCheckSubscription = (subscription: Subscription, notify?: boolean
|
||||||
const claimResult = result[subscription.uri] || {};
|
const claimResult = result[subscription.uri] || {};
|
||||||
const { claims_in_channel: claimsInChannel } = claimResult;
|
const { claims_in_channel: claimsInChannel } = claimResult;
|
||||||
|
|
||||||
if (claimsInChannel) {
|
const autodownload = true; // temp
|
||||||
if (notify) {
|
|
||||||
claimsInChannel.reduce((prev, cur, index) => {
|
|
||||||
const uri = buildURI({ contentName: cur.name, claimId: cur.claim_id }, false);
|
|
||||||
if (prev === -1 && uri !== subscription.latest) {
|
|
||||||
dispatch(
|
|
||||||
setSubscriptionNotification(
|
|
||||||
subscription,
|
|
||||||
uri,
|
|
||||||
index < SUBSCRIPTION_DOWNLOAD_LIMIT && !cur.value.stream.metadata.fee
|
|
||||||
? NOTIFICATION_TYPES.DOWNLOADING
|
|
||||||
: NOTIFICATION_TYPES.NOTIFY_ONLY
|
|
||||||
)
|
|
||||||
);
|
|
||||||
if (index < SUBSCRIPTION_DOWNLOAD_LIMIT && !cur.value.stream.metadata.fee) {
|
|
||||||
dispatch(doPurchaseUri(uri, { cost: 0 }));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return uri === subscription.latest || !subscription.latest ? index : prev;
|
|
||||||
}, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
const latestIndex = claimsInChannel.findIndex(
|
||||||
|
claim => `${claim.name}#${claim.claim_id}` === subscription.latest
|
||||||
|
);
|
||||||
|
|
||||||
|
if (claimsInChannel.length && latestIndex !== 0) {
|
||||||
|
claimsInChannel.slice(0, latestIndex === -1 ? 10 : latestIndex).forEach((claim, index) => {
|
||||||
|
const uri = buildURI({ contentName: claim.name, claimId: claim.claim_id }, false);
|
||||||
|
const shouldDownload = Boolean(
|
||||||
|
index < SUBSCRIPTION_DOWNLOAD_LIMIT && !claim.value.stream.metadata.fee
|
||||||
|
);
|
||||||
|
if (notify) {
|
||||||
|
dispatch(
|
||||||
|
setSubscriptionNotification(
|
||||||
|
subscription,
|
||||||
|
uri,
|
||||||
|
shouldDownload ? NOTIFICATION_TYPES.DOWNLOADING : NOTIFICATION_TYPES.NOTIFY_ONLY
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (autodownload && shouldDownload) {
|
||||||
|
dispatch(doPurchaseUri(uri, { cost: 0 }));
|
||||||
|
}
|
||||||
|
});
|
||||||
dispatch(
|
dispatch(
|
||||||
setSubscriptionLatest(
|
setSubscriptionLatest(
|
||||||
{
|
{
|
||||||
|
@ -177,11 +181,12 @@ export const doCheckSubscription = (subscription: Subscription, notify?: boolean
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
dispatch({
|
// this action is not implemented
|
||||||
type: ACTIONS.CHECK_SUBSCRIPTION_COMPLETED,
|
dispatch({
|
||||||
data: subscription,
|
type: ACTIONS.CHECK_SUBSCRIPTION_COMPLETED,
|
||||||
});
|
data: subscription,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -248,13 +253,14 @@ export const doCheckSubscriptions = () => (
|
||||||
dispatch: Dispatch,
|
dispatch: Dispatch,
|
||||||
getState: () => SubscriptionState
|
getState: () => SubscriptionState
|
||||||
) => {
|
) => {
|
||||||
const checkSubscriptionsTimer = setInterval(
|
function doCheck() {
|
||||||
() =>
|
const subscriptions = selectSubscriptions(getState());
|
||||||
selectSubscriptions(getState()).map((subscription: Subscription) =>
|
subscriptions.forEach((sub: Subscription) => {
|
||||||
dispatch(doCheckSubscription(subscription, true))
|
dispatch(doCheckSubscription(sub, true));
|
||||||
),
|
});
|
||||||
CHECK_SUBSCRIPTIONS_INTERVAL
|
}
|
||||||
);
|
setTimeout(doCheck, 2000); // bad fix for not getting subs on load
|
||||||
|
const checkSubscriptionsTimer = setInterval(doCheck, 1000 * 20); // temporary; 20 seconds for testing
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.CHECK_SUBSCRIPTIONS_SUBSCRIBE,
|
type: ACTIONS.CHECK_SUBSCRIPTIONS_SUBSCRIBE,
|
||||||
data: { checkSubscriptionsTimer },
|
data: { checkSubscriptionsTimer },
|
||||||
|
|
Loading…
Reference in a new issue