From 52d0410b769f33b465a5bb9a56f869d550d64262 Mon Sep 17 00:00:00 2001 From: NejcZdovc Date: Mon, 13 Mar 2017 10:40:15 +0100 Subject: [PATCH] Auto-include propagates correctly Resolves #7451 Auditors: @mrose17 Test Plan: - Enable payments in settings - Disable auto-include switch - Visit brianbondy.com in a new tab, site is added in the list and is not included --- app/ledger.js | 19 ++++++++++++++++--- .../preferences/payment/ledgerTable.js | 6 +++--- docs/appActions.md | 8 ++++++++ js/actions/appActions.js | 11 +++++++++++ js/constants/appConstants.js | 3 ++- js/stores/appStore.js | 15 +++++++++++++++ 6 files changed, 55 insertions(+), 7 deletions(-) diff --git a/app/ledger.js b/app/ledger.js index 0fede6932c3..fc4774f11ca 100644 --- a/app/ledger.js +++ b/app/ledger.js @@ -594,9 +594,14 @@ eventStore.addChangeListener(() => { pattern = `https?://${publisher}` initP = !synopsis.publishers[publisher] synopsis.initPublisher(publisher) - if ((initP) && (getSetting(settings.AUTO_SUGGEST_SITES))) { + if (initP) { excludeP(publisher, (unused, exclude) => { - appActions.changeSiteSetting(pattern, 'ledgerPayments', !exclude) + if (!getSetting(settings.AUTO_SUGGEST_SITES)) { + exclude = false + } else { + exclude = !exclude + } + appActions.changeSiteSetting(pattern, 'ledgerPayments', exclude) updatePublisherInfo() }) } @@ -849,6 +854,9 @@ var enable = (paymentsEnabled) => { }) updatePublisherInfo() + // change undefined include publishers to include publishers + appActions.enableUndefinedPublishers(synopsis.publishers) + fs.readFile(pathName(publisherPath), (err, data) => { if (err) { if (err.code !== 'ENOENT') console.log('publisherPath read error: ' + err.toString()) @@ -985,7 +993,12 @@ var stickyP = (publisher) => { result = synopsis.publishers[publisher].options.stickyP appActions.changeSiteSetting(pattern, 'ledgerPayments', result) } - delete synopsis.publishers[publisher].options.stickyP + + if (synopsis.publishers[publisher] && + synopsis.publishers[publisher].options && + synopsis.publishers[publisher].options.stickyP) { + delete synopsis.publishers[publisher].options.stickyP + } return (result || false) } diff --git a/app/renderer/components/preferences/payment/ledgerTable.js b/app/renderer/components/preferences/payment/ledgerTable.js index b235ae97b85..82f8f494194 100644 --- a/app/renderer/components/preferences/payment/ledgerTable.js +++ b/app/renderer/components/preferences/payment/ledgerTable.js @@ -59,7 +59,7 @@ class LedgerTable extends ImmutableComponent { return result } } - return true + return getSetting(settings.AUTO_SUGGEST_SITES, this.props.settings) } shouldShow (synopsis) { @@ -101,7 +101,7 @@ class LedgerTable extends ImmutableComponent { const publisherURL = synopsis.get('publisherURL') const percentage = synopsis.get('percentage') const site = synopsis.get('site') - const defaultSiteSetting = true + const defaultAutoInclude = this.enabledForSite(synopsis) return [ { @@ -131,7 +131,7 @@ class LedgerTable extends ImmutableComponent { { html: , diff --git a/docs/appActions.md b/docs/appActions.md index 1db6bd31460..dfb0c321d48 100644 --- a/docs/appActions.md +++ b/docs/appActions.md @@ -792,6 +792,14 @@ Action triggered by un-registering navigation handler +### enableUndefinedPublishers(publishers) + +**Parameters** + +**publishers**: `Object`, publishers from synopsis + + + * * * diff --git a/js/actions/appActions.js b/js/actions/appActions.js index 2a442bc5edf..0b144bf0ca5 100644 --- a/js/actions/appActions.js +++ b/js/actions/appActions.js @@ -970,6 +970,17 @@ const appActions = { protocol, location }) + }, + + /** + * + * @param publishers {Object} publishers from synopsis + */ + enableUndefinedPublishers: function (publishers) { + AppDispatcher.dispatch({ + actionType: appConstants.APP_ENABLE_UNDEFINED_PUBLISHERS, + publishers + }) } } diff --git a/js/constants/appConstants.js b/js/constants/appConstants.js index 05f99bdc4de..eee96c900ee 100644 --- a/js/constants/appConstants.js +++ b/js/constants/appConstants.js @@ -97,7 +97,8 @@ const appConstants = { APP_TAB_MESSAGE_BOX_DISMISSED: _, APP_TAB_MESSAGE_BOX_UPDATED: _, APP_NAVIGATOR_HANDLER_REGISTERED: _, - APP_NAVIGATOR_HANDLER_UNREGISTERED: _ + APP_NAVIGATOR_HANDLER_UNREGISTERED: _, + APP_ENABLE_UNDEFINED_PUBLISHERS: _ } module.exports = mapValuesByKeys(appConstants) diff --git a/js/stores/appStore.js b/js/stores/appStore.js index 8767a6d9435..ea2df2122fc 100644 --- a/js/stores/appStore.js +++ b/js/stores/appStore.js @@ -908,6 +908,21 @@ const handleAppAction = (action) => { case appConstants.APP_HIDE_DOWNLOAD_DELETE_CONFIRMATION: appState = appState.set('deleteConfirmationVisible', false) break + case appConstants.APP_ENABLE_UNDEFINED_PUBLISHERS: + const sitesObject = appState.get('siteSettings') + Object.keys(action.publishers).map((item) => { + const pattern = `https?://${item}` + const siteSetting = sitesObject.get(pattern) + const result = (siteSetting) && (siteSetting.get('ledgerPayments')) + + if (result === undefined) { + let newSiteSettings = siteSettings.mergeSiteSetting(appState.get('siteSettings'), pattern, 'ledgerPayments', true) + let syncObject = siteUtil.setObjectId(newSiteSettings.get(pattern)) + newSiteSettings = newSiteSettings.set(pattern, syncObject) + appState = appState.set('siteSettings', newSiteSettings) + } + }) + break default: }