Skip to content

Commit

Permalink
Auto-include propagates correctly
Browse files Browse the repository at this point in the history
Resolves brave#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
  • Loading branch information
NejcZdovc committed Mar 18, 2017
1 parent 8b8cf36 commit ca19a06
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 7 deletions.
19 changes: 16 additions & 3 deletions app/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
}
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions app/renderer/components/preferences/payment/ledgerTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class LedgerTable extends ImmutableComponent {
return result
}
}
return true
return getSetting(settings.AUTO_SUGGEST_SITES, this.props.settings)
}

shouldShow (synopsis) {
Expand Down Expand Up @@ -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 [
{
Expand Down Expand Up @@ -131,7 +131,7 @@ class LedgerTable extends ImmutableComponent {
{
html: <SiteSettingCheckbox small
hostPattern={this.getHostPattern(synopsis)}
defaultValue={defaultSiteSetting}
defaultValue={defaultAutoInclude}
prefKey='ledgerPayments'
siteSettings={this.props.siteSettings}
checked={this.enabledForSite(synopsis)} />,
Expand Down
8 changes: 8 additions & 0 deletions docs/appActions.md
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,14 @@ Open dialog for default download path setting



### enableUndefinedPublishers(publishers)

**Parameters**

**publishers**: `Object`, publishers from synopsis




* * *

Expand Down
11 changes: 11 additions & 0 deletions js/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,17 @@ const appActions = {
AppDispatcher.dispatch({
actionType: appConstants.APP_DOWNLOAD_DEFAULT_PATH
})
},

/**
*
* @param publishers {Object} publishers from synopsis
*/
enableUndefinedPublishers: function (publishers) {
AppDispatcher.dispatch({
actionType: appConstants.APP_ENABLE_UNDEFINED_PUBLISHERS,
publishers
})
}
}

Expand Down
3 changes: 2 additions & 1 deletion js/constants/appConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,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)
15 changes: 15 additions & 0 deletions js/stores/appStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,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:
}

Expand Down

0 comments on commit ca19a06

Please sign in to comment.