From 69c285025cb881a9d9a995e1b1612feb890da499 Mon Sep 17 00:00:00 2001 From: Travis Eden Date: Wed, 8 Aug 2018 14:23:26 -0400 Subject: [PATCH 01/13] fix subscription notification and download glitches --- src/renderer/redux/actions/subscriptions.js | 72 +++++++++++---------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/src/renderer/redux/actions/subscriptions.js b/src/renderer/redux/actions/subscriptions.js index b98e7b7a5..8e875a08a 100644 --- a/src/renderer/redux/actions/subscriptions.js +++ b/src/renderer/redux/actions/subscriptions.js @@ -13,7 +13,7 @@ import { doPurchaseUri } from 'redux/actions/content'; import Promise from 'bluebird'; import Lbryio from 'lbryio'; -const CHECK_SUBSCRIPTIONS_INTERVAL = 60 * 60 * 1000; +const CHECK_SUBSCRIPTIONS_INTERVAL = 15 * 60 * 1000; const SUBSCRIPTION_DOWNLOAD_LIMIT = 1; export const doFetchMySubscriptions = () => (dispatch: Dispatch, getState: () => any) => { @@ -127,6 +127,7 @@ export const setSubscriptionNotification = ( export const doCheckSubscription = (subscription: Subscription, notify?: boolean) => ( dispatch: Dispatch ) => { + // this action is not implemented dispatch({ type: ACTIONS.CHECK_SUBSCRIPTION_STARTED, data: subscription, @@ -136,28 +137,31 @@ export const doCheckSubscription = (subscription: Subscription, notify?: boolean const claimResult = result[subscription.uri] || {}; const { claims_in_channel: claimsInChannel } = claimResult; - if (claimsInChannel) { - 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 autodownload = true; // temp + 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( setSubscriptionLatest( { @@ -177,11 +181,12 @@ export const doCheckSubscription = (subscription: Subscription, notify?: boolean ) ); } + }); - dispatch({ - type: ACTIONS.CHECK_SUBSCRIPTION_COMPLETED, - data: subscription, - }); + // this action is not implemented + dispatch({ + type: ACTIONS.CHECK_SUBSCRIPTION_COMPLETED, + data: subscription, }); }; @@ -248,13 +253,14 @@ export const doCheckSubscriptions = () => ( dispatch: Dispatch, getState: () => SubscriptionState ) => { - const checkSubscriptionsTimer = setInterval( - () => - selectSubscriptions(getState()).map((subscription: Subscription) => - dispatch(doCheckSubscription(subscription, true)) - ), - CHECK_SUBSCRIPTIONS_INTERVAL - ); + function doCheck() { + const subscriptions = selectSubscriptions(getState()); + subscriptions.forEach((sub: Subscription) => { + dispatch(doCheckSubscription(sub, true)); + }); + } + setTimeout(doCheck, 2000); // bad fix for not getting subs on load + const checkSubscriptionsTimer = setInterval(doCheck, 1000 * 20); // temporary; 20 seconds for testing dispatch({ type: ACTIONS.CHECK_SUBSCRIPTIONS_SUBSCRIBE, data: { checkSubscriptionsTimer }, From cedafdbe145c6d6215f51b1fbcb2ca024894011b Mon Sep 17 00:00:00 2001 From: Travis Eden Date: Thu, 9 Aug 2018 07:45:07 -0400 Subject: [PATCH 02/13] attempt to claim subscription reward when subscribing to a channel; fail silently --- src/renderer/redux/actions/subscriptions.js | 4 ++++ src/renderer/rewards.js | 1 + 2 files changed, 5 insertions(+) diff --git a/src/renderer/redux/actions/subscriptions.js b/src/renderer/redux/actions/subscriptions.js index 8e875a08a..b2e751e26 100644 --- a/src/renderer/redux/actions/subscriptions.js +++ b/src/renderer/redux/actions/subscriptions.js @@ -1,6 +1,7 @@ // @flow import * as ACTIONS from 'constants/action_types'; import * as NOTIFICATION_TYPES from 'constants/notification_types'; +import rewards from 'rewards'; import type { Dispatch, SubscriptionState, @@ -10,6 +11,7 @@ import type { Subscription } from 'types/subscription'; import { selectSubscriptions } from 'redux/selectors/subscriptions'; import { Lbry, buildURI, parseURI } from 'lbry-redux'; import { doPurchaseUri } from 'redux/actions/content'; +import { doClaimRewardType } from 'redux/actions/rewards'; import Promise from 'bluebird'; import Lbryio from 'lbryio'; @@ -222,6 +224,8 @@ export const doChannelSubscribe = (subscription: Subscription) => ( channel_name: subscription.channelName, claim_id: claimId, }); + + dispatch(doClaimRewardType(rewards.SUBSCRIPTION, { failSilently: true })); } dispatch(doCheckSubscription(subscription, true)); diff --git a/src/renderer/rewards.js b/src/renderer/rewards.js index 9da3727a9..da3833e7b 100644 --- a/src/renderer/rewards.js +++ b/src/renderer/rewards.js @@ -13,6 +13,7 @@ rewards.TYPE_FIRST_PUBLISH = 'first_publish'; rewards.TYPE_FEATURED_DOWNLOAD = 'featured_download'; rewards.TYPE_REFERRAL = 'referral'; rewards.YOUTUBE_CREATOR = 'youtube_creator'; +rewards.SUBSCRIPTION = 'subscription'; rewards.claimReward = type => { function requestReward(resolve, reject, params) { From 386e9271ffc8c8e5706fcdd5f9ddec9f3538d407 Mon Sep 17 00:00:00 2001 From: Travis Eden Date: Fri, 10 Aug 2018 10:51:51 -0400 Subject: [PATCH 03/13] when file download completes, notify through snackbar if on subscriptions page; formatting --- src/renderer/constants/settings.js | 1 + src/renderer/page/settings/index.js | 1 + src/renderer/page/settings/view.jsx | 14 ++++ src/renderer/redux/actions/app.js | 4 +- src/renderer/redux/actions/content.js | 16 +++- src/renderer/redux/actions/subscriptions.js | 77 ++++++++++--------- src/renderer/redux/reducers/settings.js | 1 + src/renderer/redux/selectors/subscriptions.js | 18 +++-- 8 files changed, 84 insertions(+), 48 deletions(-) diff --git a/src/renderer/constants/settings.js b/src/renderer/constants/settings.js index d5ab15a83..f63368105 100644 --- a/src/renderer/constants/settings.js +++ b/src/renderer/constants/settings.js @@ -15,3 +15,4 @@ export const AUTOMATIC_DARK_MODE_ENABLED = 'automaticDarkModeEnabled'; export const AUTOPLAY = 'autoplay'; export const RESULT_COUNT = 'resultCount'; export const OS_NOTIFICATIONS_ENABLED = 'osNotificationsEnabled'; +export const AUTO_DOWNLOAD = 'autoDownload'; diff --git a/src/renderer/page/settings/index.js b/src/renderer/page/settings/index.js index 2eeb42c25..6d178b368 100644 --- a/src/renderer/page/settings/index.js +++ b/src/renderer/page/settings/index.js @@ -30,6 +30,7 @@ const select = state => ({ autoplay: makeSelectClientSetting(settings.AUTOPLAY)(state), walletEncrypted: selectWalletIsEncrypted(state), osNotificationsEnabled: selectosNotificationsEnabled(state), + autoDownload: makeSelectClientSetting(settings.AUTO_DOWNLOAD)(state), }); const perform = dispatch => ({ diff --git a/src/renderer/page/settings/view.jsx b/src/renderer/page/settings/view.jsx index 1a79f1ece..8f0fb0556 100644 --- a/src/renderer/page/settings/view.jsx +++ b/src/renderer/page/settings/view.jsx @@ -31,6 +31,7 @@ type Props = { themes: Array, automaticDarkModeEnabled: boolean, autoplay: boolean, + autoDownload: boolean, encryptWallet: () => void, decryptWallet: () => void, walletEncrypted: boolean, @@ -59,6 +60,7 @@ class SettingsPage extends React.PureComponent { (this: any).onAutoplayChange = this.onAutoplayChange.bind(this); (this: any).clearCache = this.clearCache.bind(this); (this: any).onDesktopNotificationsChange = this.onDesktopNotificationsChange.bind(this); + (this: any).onAutoDownloadChange = this.onAutoDownloadChange.bind(this); // (this: any).onLanguageChange = this.onLanguageChange.bind(this) } @@ -119,6 +121,10 @@ class SettingsPage extends React.PureComponent { this.props.setClientSetting(settings.SHOW_NSFW, event.target.checked); } + onAutoDownloadChange(event: SyntheticInputEvent<*>) { + this.props.setClientSetting(settings.AUTO_DOWNLOAD, event.target.checked); + } + onChangeEncryptWallet() { const { props } = this; props.walletEncrypted ? props.decryptWallet() : props.encryptWallet(); @@ -157,6 +163,7 @@ class SettingsPage extends React.PureComponent { autoplay, walletEncrypted, osNotificationsEnabled, + autoDownload, } = this.props; const noDaemonSettings = !daemonSettings || Object.keys(daemonSettings).length === 0; @@ -265,6 +272,13 @@ class SettingsPage extends React.PureComponent { checked={autoplay} postfix={__('Autoplay media files')} /> + @@ -138,7 +139,14 @@ export function doUpdateLoadStatus(uri, outpoint) { 0 ); - if (selectosNotificationsEnabled(getState())) { + if (state.navigation.currentPath === '/subscriptions') { + dispatch( + doNotify({ + message: `'${fileInfo.metadata.title}' has been downloaded`, + displayType: ['snackbar'], + }) + ); + } else if (selectosNotificationsEnabled(state)) { const notif = new window.Notification(notifications[uri].subscription.channelName, { body: `Posted ${fileInfo.metadata.title}${ count > 1 && count < 10 ? ` and ${count - 1} other new items` : '' diff --git a/src/renderer/redux/actions/subscriptions.js b/src/renderer/redux/actions/subscriptions.js index b2e751e26..02fd76df6 100644 --- a/src/renderer/redux/actions/subscriptions.js +++ b/src/renderer/redux/actions/subscriptions.js @@ -1,14 +1,12 @@ // @flow import * as ACTIONS from 'constants/action_types'; import * as NOTIFICATION_TYPES from 'constants/notification_types'; +import * as SETTINGS from 'constants/settings'; import rewards from 'rewards'; -import type { - Dispatch, - SubscriptionState, - SubscriptionNotifications, -} from 'redux/reducers/subscriptions'; +import type { Dispatch, SubscriptionNotifications } from 'redux/reducers/subscriptions'; import type { Subscription } from 'types/subscription'; -import { selectSubscriptions } from 'redux/selectors/subscriptions'; +import { selectSubscriptions, selectDownloadingCount } from 'redux/selectors/subscriptions'; +import { makeSelectClientSetting } from 'redux/selectors/settings'; import { Lbry, buildURI, parseURI } from 'lbry-redux'; import { doPurchaseUri } from 'redux/actions/content'; import { doClaimRewardType } from 'redux/actions/rewards'; @@ -16,7 +14,7 @@ import Promise from 'bluebird'; import Lbryio from 'lbryio'; const CHECK_SUBSCRIPTIONS_INTERVAL = 15 * 60 * 1000; -const SUBSCRIPTION_DOWNLOAD_LIMIT = 1; +const SUBSCRIPTION_DOWNLOAD_LIMIT = 3; export const doFetchMySubscriptions = () => (dispatch: Dispatch, getState: () => any) => { const { @@ -127,29 +125,28 @@ export const setSubscriptionNotification = ( }); export const doCheckSubscription = (subscription: Subscription, notify?: boolean) => ( - dispatch: Dispatch + dispatch: Dispatch, + getState: () => {} ) => { - // this action is not implemented - dispatch({ - type: ACTIONS.CHECK_SUBSCRIPTION_STARTED, - data: subscription, - }); + // no dispatching FETCH_CHANNEL_CLAIMS_STARTED; causes loading issues on Lbry.claim_list_by_channel({ uri: subscription.uri, page: 1 }).then(result => { const claimResult = result[subscription.uri] || {}; const { claims_in_channel: claimsInChannel } = claimResult; - const autodownload = true; // temp - 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) => { + claimsInChannel.slice(0, latestIndex === -1 ? 10 : latestIndex).forEach(claim => { const uri = buildURI({ contentName: claim.name, claimId: claim.claim_id }, false); + const state = getState(); + const downloadCount = selectDownloadingCount(state); const shouldDownload = Boolean( - index < SUBSCRIPTION_DOWNLOAD_LIMIT && !claim.value.stream.metadata.fee + downloadCount < SUBSCRIPTION_DOWNLOAD_LIMIT && + !claim.value.stream.metadata.fee && + makeSelectClientSetting(SETTINGS.AUTO_DOWNLOAD)(state) ); if (notify) { dispatch( @@ -160,10 +157,11 @@ export const doCheckSubscription = (subscription: Subscription, notify?: boolean ) ); } - if (autodownload && shouldDownload) { + if (shouldDownload) { dispatch(doPurchaseUri(uri, { cost: 0 })); } }); + dispatch( setSubscriptionLatest( { @@ -182,13 +180,18 @@ export const doCheckSubscription = (subscription: Subscription, notify?: boolean ) ) ); - } - }); - // this action is not implemented - dispatch({ - type: ACTIONS.CHECK_SUBSCRIPTION_COMPLETED, - data: subscription, + // calling FETCH_CHANNEL_CLAIMS_COMPLETED after not calling STARTED + // means it will delete a non-existant fetchingChannelClaims[uri] + dispatch({ + type: ACTIONS.FETCH_CHANNEL_CLAIMS_COMPLETED, + data: { + uri: subscription.uri, + claims: claimsInChannel || [], + page: 1, + }, + }); + } }); }; @@ -253,18 +256,20 @@ export const doChannelUnsubscribe = (subscription: Subscription) => ( } }; -export const doCheckSubscriptions = () => ( - dispatch: Dispatch, - getState: () => SubscriptionState -) => { - function doCheck() { - const subscriptions = selectSubscriptions(getState()); - subscriptions.forEach((sub: Subscription) => { - dispatch(doCheckSubscription(sub, true)); - }); - } - setTimeout(doCheck, 2000); // bad fix for not getting subs on load - const checkSubscriptionsTimer = setInterval(doCheck, 1000 * 20); // temporary; 20 seconds for testing +export const doCheckSubscriptions = () => (dispatch: Dispatch, getState: () => any) => { + const state = getState(); + const subscriptions = selectSubscriptions(state); + subscriptions.forEach((sub: Subscription) => { + dispatch(doCheckSubscription(sub, true)); + }); +}; + +export const doCheckSubscriptionsInit = () => (dispatch: Dispatch) => { + setTimeout(() => dispatch(doCheckSubscriptions()), 5000); // bad fix for not getting subs on load + const checkSubscriptionsTimer = setInterval( + () => dispatch(doCheckSubscriptions()), + CHECK_SUBSCRIPTIONS_INTERVAL + ); dispatch({ type: ACTIONS.CHECK_SUBSCRIPTIONS_SUBSCRIBE, data: { checkSubscriptionsTimer }, diff --git a/src/renderer/redux/reducers/settings.js b/src/renderer/redux/reducers/settings.js index 215032c8b..43336c9b9 100644 --- a/src/renderer/redux/reducers/settings.js +++ b/src/renderer/redux/reducers/settings.js @@ -26,6 +26,7 @@ const defaultState = { automaticDarkModeEnabled: getLocalStorageSetting(SETTINGS.AUTOMATIC_DARK_MODE_ENABLED, false), autoplay: getLocalStorageSetting(SETTINGS.AUTOPLAY, false), resultCount: Number(getLocalStorageSetting(SETTINGS.RESULT_COUNT, 50)), + autoDownload: getLocalStorageSetting(SETTINGS.AUTO_DOWNLOAD, false), osNotificationsEnabled: Boolean( getLocalStorageSetting(SETTINGS.OS_NOTIFICATIONS_ENABLED, true) ), diff --git a/src/renderer/redux/selectors/subscriptions.js b/src/renderer/redux/selectors/subscriptions.js index 1e9ca71cd..7b95604d0 100644 --- a/src/renderer/redux/selectors/subscriptions.js +++ b/src/renderer/redux/selectors/subscriptions.js @@ -1,3 +1,4 @@ +import * as NOTIFICATION_TYPES from 'constants/notification_types'; import { createSelector } from 'reselect'; import { selectAllClaimsByChannel, @@ -25,7 +26,7 @@ export const selectSubscriptionClaims = createSelector( return []; } - const fetchedSubscriptions = []; + let fetchedSubscriptions = []; savedSubscriptions.forEach(subscription => { let channelClaims = []; @@ -39,18 +40,18 @@ export const selectSubscriptionClaims = createSelector( // loop over the list of ids and grab the claim pageOneChannelIds.forEach(id => { const grabbedClaim = allClaims[id]; - channelClaims.push(grabbedClaim); + channelClaims = channelClaims.concat([grabbedClaim]); }); } - fetchedSubscriptions.push({ - claims: channelClaims, + fetchedSubscriptions = fetchedSubscriptions.concat([{ + claims: [...channelClaims], channelName: subscription.channelName, uri: subscription.uri, - }); + }]); }); - return fetchedSubscriptions; + return [...fetchedSubscriptions]; } ); @@ -69,3 +70,8 @@ export const selectSubscriptionsBeingFetched = createSelector( return fetchingSubscriptionMap; } ); + +export const selectDownloadingCount = createSelector( + selectNotifications, + notifs => Object.values(notifs).reduce((acc, notif) => notif.type === NOTIFICATION_TYPES.DOWNLOADING ? acc + 1 : acc, 0) +); From 02c20d090ebeb6b59b18a945c73f16d1b7745fe8 Mon Sep 17 00:00:00 2001 From: Travis Eden Date: Mon, 13 Aug 2018 12:14:53 -0400 Subject: [PATCH 04/13] do not download newest content on channel subscription; do still set latest --- src/renderer/redux/actions/subscriptions.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/renderer/redux/actions/subscriptions.js b/src/renderer/redux/actions/subscriptions.js index 02fd76df6..3d7edb87f 100644 --- a/src/renderer/redux/actions/subscriptions.js +++ b/src/renderer/redux/actions/subscriptions.js @@ -124,10 +124,11 @@ export const setSubscriptionNotification = ( }, }); -export const doCheckSubscription = (subscription: Subscription, notify?: boolean) => ( - dispatch: Dispatch, - getState: () => {} -) => { +export const doCheckSubscription = ( + subscription: Subscription, + notify?: boolean, + preventDownload?: boolean +) => (dispatch: Dispatch, getState: () => {}) => { // no dispatching FETCH_CHANNEL_CLAIMS_STARTED; causes loading issues on Lbry.claim_list_by_channel({ uri: subscription.uri, page: 1 }).then(result => { @@ -144,7 +145,8 @@ export const doCheckSubscription = (subscription: Subscription, notify?: boolean const state = getState(); const downloadCount = selectDownloadingCount(state); const shouldDownload = Boolean( - downloadCount < SUBSCRIPTION_DOWNLOAD_LIMIT && + !preventDownload && + downloadCount < SUBSCRIPTION_DOWNLOAD_LIMIT && !claim.value.stream.metadata.fee && makeSelectClientSetting(SETTINGS.AUTO_DOWNLOAD)(state) ); @@ -231,7 +233,7 @@ export const doChannelSubscribe = (subscription: Subscription) => ( dispatch(doClaimRewardType(rewards.SUBSCRIPTION, { failSilently: true })); } - dispatch(doCheckSubscription(subscription, true)); + dispatch(doCheckSubscription(subscription, false, true)); }; export const doChannelUnsubscribe = (subscription: Subscription) => ( From a6393aaf17b269015c74c6e0c56409d72647f06f Mon Sep 17 00:00:00 2001 From: Travis Eden Date: Mon, 13 Aug 2018 18:04:49 -0400 Subject: [PATCH 05/13] 1 download per channel; do download/notify on subscribe --- src/renderer/redux/actions/subscriptions.js | 26 ++++++++++--------- src/renderer/redux/selectors/subscriptions.js | 18 +++++-------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/renderer/redux/actions/subscriptions.js b/src/renderer/redux/actions/subscriptions.js index 3d7edb87f..5fd208924 100644 --- a/src/renderer/redux/actions/subscriptions.js +++ b/src/renderer/redux/actions/subscriptions.js @@ -5,7 +5,7 @@ import * as SETTINGS from 'constants/settings'; import rewards from 'rewards'; import type { Dispatch, SubscriptionNotifications } from 'redux/reducers/subscriptions'; 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 { Lbry, buildURI, parseURI } from 'lbry-redux'; import { doPurchaseUri } from 'redux/actions/content'; @@ -14,7 +14,7 @@ import Promise from 'bluebird'; import Lbryio from 'lbryio'; const CHECK_SUBSCRIPTIONS_INTERVAL = 15 * 60 * 1000; -const SUBSCRIPTION_DOWNLOAD_LIMIT = 3; +const SUBSCRIPTION_DOWNLOAD_LIMIT = 1; export const doFetchMySubscriptions = () => (dispatch: Dispatch, getState: () => any) => { const { @@ -124,11 +124,10 @@ export const setSubscriptionNotification = ( }, }); -export const doCheckSubscription = ( - subscription: Subscription, - notify?: boolean, - preventDownload?: boolean -) => (dispatch: Dispatch, getState: () => {}) => { +export const doCheckSubscription = (subscription: Subscription, notify?: boolean) => ( + dispatch: Dispatch, + getState: () => {} +) => { // no dispatching FETCH_CHANNEL_CLAIMS_STARTED; causes loading issues on Lbry.claim_list_by_channel({ uri: subscription.uri, page: 1 }).then(result => { @@ -140,13 +139,12 @@ export const doCheckSubscription = ( ); if (claimsInChannel.length && latestIndex !== 0) { + let downloadCount = 0; claimsInChannel.slice(0, latestIndex === -1 ? 10 : latestIndex).forEach(claim => { const uri = buildURI({ contentName: claim.name, claimId: claim.claim_id }, false); const state = getState(); - const downloadCount = selectDownloadingCount(state); const shouldDownload = Boolean( - !preventDownload && - downloadCount < SUBSCRIPTION_DOWNLOAD_LIMIT && + downloadCount < SUBSCRIPTION_DOWNLOAD_LIMIT && !claim.value.stream.metadata.fee && makeSelectClientSetting(SETTINGS.AUTO_DOWNLOAD)(state) ); @@ -160,6 +158,7 @@ export const doCheckSubscription = ( ); } if (shouldDownload) { + downloadCount += 1; dispatch(doPurchaseUri(uri, { cost: 0 })); } }); @@ -233,7 +232,7 @@ export const doChannelSubscribe = (subscription: Subscription) => ( dispatch(doClaimRewardType(rewards.SUBSCRIPTION, { failSilently: true })); } - dispatch(doCheckSubscription(subscription, false, true)); + dispatch(doCheckSubscription(subscription, true)); }; export const doChannelUnsubscribe = (subscription: Subscription) => ( @@ -267,7 +266,10 @@ export const doCheckSubscriptions = () => (dispatch: Dispatch, getState: () => a }; 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 which reqiures a package upgrade + setTimeout(() => dispatch(doCheckSubscriptions()), 5000); const checkSubscriptionsTimer = setInterval( () => dispatch(doCheckSubscriptions()), CHECK_SUBSCRIPTIONS_INTERVAL diff --git a/src/renderer/redux/selectors/subscriptions.js b/src/renderer/redux/selectors/subscriptions.js index 7b95604d0..12c35ae74 100644 --- a/src/renderer/redux/selectors/subscriptions.js +++ b/src/renderer/redux/selectors/subscriptions.js @@ -1,4 +1,3 @@ -import * as NOTIFICATION_TYPES from 'constants/notification_types'; import { createSelector } from 'reselect'; import { selectAllClaimsByChannel, @@ -44,11 +43,13 @@ export const selectSubscriptionClaims = createSelector( }); } - fetchedSubscriptions = fetchedSubscriptions.concat([{ - claims: [...channelClaims], - channelName: subscription.channelName, - uri: subscription.uri, - }]); + fetchedSubscriptions = fetchedSubscriptions.concat([ + { + claims: [...channelClaims], + channelName: subscription.channelName, + uri: subscription.uri, + }, + ]); }); return [...fetchedSubscriptions]; @@ -70,8 +71,3 @@ export const selectSubscriptionsBeingFetched = createSelector( return fetchingSubscriptionMap; } ); - -export const selectDownloadingCount = createSelector( - selectNotifications, - notifs => Object.values(notifs).reduce((acc, notif) => notif.type === NOTIFICATION_TYPES.DOWNLOADING ? acc + 1 : acc, 0) -); From fa0e9fcb0c150ffc1fa1d1ff361ae77429c8f5f9 Mon Sep 17 00:00:00 2001 From: Travis Eden Date: Tue, 14 Aug 2018 09:22:27 -0400 Subject: [PATCH 06/13] set autoDownload default true --- src/renderer/redux/reducers/settings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/redux/reducers/settings.js b/src/renderer/redux/reducers/settings.js index 43336c9b9..fd9c8c12d 100644 --- a/src/renderer/redux/reducers/settings.js +++ b/src/renderer/redux/reducers/settings.js @@ -26,7 +26,7 @@ const defaultState = { automaticDarkModeEnabled: getLocalStorageSetting(SETTINGS.AUTOMATIC_DARK_MODE_ENABLED, false), autoplay: getLocalStorageSetting(SETTINGS.AUTOPLAY, false), resultCount: Number(getLocalStorageSetting(SETTINGS.RESULT_COUNT, 50)), - autoDownload: getLocalStorageSetting(SETTINGS.AUTO_DOWNLOAD, false), + autoDownload: getLocalStorageSetting(SETTINGS.AUTO_DOWNLOAD, true), osNotificationsEnabled: Boolean( getLocalStorageSetting(SETTINGS.OS_NOTIFICATIONS_ENABLED, true) ), From 3d66610d699672b74f03c89a00a9a3ecc0ce083e Mon Sep 17 00:00:00 2001 From: Travis Eden Date: Tue, 14 Aug 2018 09:24:43 -0400 Subject: [PATCH 07/13] reword autoDownload postfix --- src/renderer/page/settings/view.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/page/settings/view.jsx b/src/renderer/page/settings/view.jsx index 8f0fb0556..729ba7059 100644 --- a/src/renderer/page/settings/view.jsx +++ b/src/renderer/page/settings/view.jsx @@ -277,7 +277,7 @@ class SettingsPage extends React.PureComponent { name="auto_download" onChange={this.onAutoDownloadChange} checked={autoDownload} - postfix={__('Automatically download new content')} + postfix={__('Automatically download new content from your subscriptions')} /> Date: Tue, 14 Aug 2018 09:27:29 -0400 Subject: [PATCH 08/13] remove snackbar when download complete --- src/renderer/redux/actions/content.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/renderer/redux/actions/content.js b/src/renderer/redux/actions/content.js index 445158522..021d2dc60 100644 --- a/src/renderer/redux/actions/content.js +++ b/src/renderer/redux/actions/content.js @@ -139,14 +139,7 @@ export function doUpdateLoadStatus(uri, outpoint) { 0 ); - if (state.navigation.currentPath === '/subscriptions') { - dispatch( - doNotify({ - message: `'${fileInfo.metadata.title}' has been downloaded`, - displayType: ['snackbar'], - }) - ); - } else if (selectosNotificationsEnabled(state)) { + if (selectosNotificationsEnabled(state)) { const notif = new window.Notification(notifications[uri].subscription.channelName, { body: `Posted ${fileInfo.metadata.title}${ count > 1 && count < 10 ? ` and ${count - 1} other new items` : '' From 30e0ff309a22826b0abba5726ec224529d021bc0 Mon Sep 17 00:00:00 2001 From: Travis Eden Date: Tue, 14 Aug 2018 15:30:36 -0400 Subject: [PATCH 09/13] prevent subscription notification when viewing subscriptions page --- src/renderer/redux/actions/content.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/renderer/redux/actions/content.js b/src/renderer/redux/actions/content.js index 021d2dc60..fa3ac9afa 100644 --- a/src/renderer/redux/actions/content.js +++ b/src/renderer/redux/actions/content.js @@ -154,13 +154,15 @@ export function doUpdateLoadStatus(uri, outpoint) { ); }; } - dispatch( - setSubscriptionNotification( - notifications[uri].subscription, - uri, - NOTIFICATION_TYPES.DOWNLOADED - ) - ); + if (state.navigation.currentPath !== '/subscriptions') { + dispatch( + setSubscriptionNotification( + notifications[uri].subscription, + uri, + NOTIFICATION_TYPES.DOWNLOADED + ) + ); + } } else { // If notifications are disabled(false) just return if (!selectosNotificationsEnabled(getState())) return; From 6b375965f986c91429a05d4d89d28e5cd87ee9c9 Mon Sep 17 00:00:00 2001 From: Travis Eden Date: Tue, 14 Aug 2018 15:42:08 -0400 Subject: [PATCH 10/13] implement silent failing on reward claims when user is not reward approved --- src/renderer/redux/actions/rewards.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/renderer/redux/actions/rewards.js b/src/renderer/redux/actions/rewards.js index d98d4a9b6..18823dcf3 100644 --- a/src/renderer/redux/actions/rewards.js +++ b/src/renderer/redux/actions/rewards.js @@ -40,11 +40,13 @@ export function doClaimRewardType(rewardType, options) { } if (!userIsRewardApproved && rewardType !== rewards.TYPE_CONFIRM_EMAIL) { - const action = doNotify({ - id: MODALS.REWARD_APPROVAL_REQUIRED, - isError: false, - }); - dispatch(action); + if (!options || !options.failSilently) { + const action = doNotify({ + id: MODALS.REWARD_APPROVAL_REQUIRED, + isError: false, + }); + dispatch(action); + } return; } From 5e270c129cd13b2e5f859ba50de9cf4c83b5bf0c Mon Sep 17 00:00:00 2001 From: Travis Eden Date: Thu, 16 Aug 2018 12:41:50 -0400 Subject: [PATCH 11/13] doCheckSubs only takes uri; do not clear notifications on doFetchClaimsByChan; doFetchMySubs on startup; always set latest on checkSub; do not download or notify when latest is undefined --- src/renderer/component/sideBar/view.jsx | 5 +- src/renderer/page/file/index.js | 2 +- src/renderer/page/file/view.jsx | 18 ++--- src/renderer/page/subscriptions/view.jsx | 3 + src/renderer/redux/actions/content.js | 23 +++--- src/renderer/redux/actions/subscriptions.js | 86 ++++++++++++--------- 6 files changed, 72 insertions(+), 65 deletions(-) diff --git a/src/renderer/component/sideBar/view.jsx b/src/renderer/component/sideBar/view.jsx index d50d21491..becc2d3ed 100644 --- a/src/renderer/component/sideBar/view.jsx +++ b/src/renderer/component/sideBar/view.jsx @@ -25,10 +25,7 @@ type Props = { const SideBar = (props: Props) => { const { navLinks, notifications } = props; - const badges = Object.keys(notifications).reduce( - (acc, cur) => (notifications[cur].type === NOTIFICATION_TYPES.DOWNLOADING ? acc : acc + 1), - 0 - ); + const badges = Object.keys(notifications).length; return (