Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
If auto-suggest is off, then always show included publishers
Browse files Browse the repository at this point in the history
Addresses #6592 …
intended for the master branch…
  • Loading branch information
mrose17 committed Jan 11, 2017
1 parent bf09ddd commit 6f5acce
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
48 changes: 34 additions & 14 deletions app/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,23 +170,29 @@ const doAction = (action) => {
break

case appConstants.APP_CHANGE_SITE_SETTING:
i = action.hostPattern.indexOf('://')
if (i === -1) break

publisher = action.hostPattern.substr(i + 3)
if (action.key === 'ledgerPaymentsShown') {
if (action.value === false) {
i = action.hostPattern.indexOf('://')
if (i !== -1) {
publisher = action.hostPattern.substr(i + 3)
if (publisherInfo._internal.verboseP) console.log('\npurging ' + publisher)
delete synopsis.publishers[publisher]
delete publishers[publisher]
updatePublisherInfo()
}
if (publisherInfo._internal.verboseP) console.log('\npurging ' + publisher)
delete synopsis.publishers[publisher]
delete publishers[publisher]
updatePublisherInfo()
}
} else if (action.key === 'ledgerPayments') {
if (!synopsis.publishers[publisher]) break

if (publisherInfo._internal.verboseP) console.log('\nupdating ' + publisher + ' stickyP=' + action.value)
synopsis.publishers[publisher].options.stickyP = action.value
updatePublisherInfo()
}
break

case appConstants.APP_REMOVE_SITE_SETTING:
if (action.key === 'ledgerPaymentsShown') {
// TODO
// nothing to do!
}
break

Expand Down Expand Up @@ -710,7 +716,8 @@ var enable = (paymentsEnabled) => {
synopsis = new (ledgerPublisher.Synopsis)()
fs.readFile(pathName(synopsisPath), (err, data) => {
var initSynopsis = () => {
var value
var updateP, value
var siteSettings = appStore.getState().get('siteSettings')

// cf., the `Synopsis` constructor, https://github.com/brave/ledger-publisher/blob/master/index.js#L167
value = getSetting(settings.MINIMUM_VISIT_TIME)
Expand Down Expand Up @@ -743,6 +750,18 @@ var enable = (paymentsEnabled) => {
synopsis.options.minPublisherVisits = ledgerClient.prototype.numbion(process.env.LEDGER_PUBLISHER_MIN_VISITS)
}
}

underscore.keys(synopsis.publishers).forEach((publisher) => {
var siteSetting

if (typeof synopsis.publishers[publisher].options.stickyP !== 'undefined') return

updateP = true
siteSetting = siteSettings.get(`https?://${publisher}`)
synopsis.publishers[publisher].options.stickyP = siteSetting && siteSetting.get('ledgerPayments')
})

if (updateP) updatePublisherInfo()
}

if (publisherInfo._internal.verboseP) console.log('\nstarting up ledger publisher integration')
Expand Down Expand Up @@ -849,10 +868,11 @@ var synopsisNormalizer = () => {

results = []
underscore.keys(synopsis.publishers).forEach((publisher) => {
if (synopsis.publishers[publisher].scores[scorekeeper] <= 0) return

if ((synopsis.options.minPublisherDuration > synopsis.publishers[publisher].duration) ||
(synopsis.options.minPublisherVisits > synopsis.publishers[publisher].visits)) return
if ((getSetting(settings.AUTO_SUGGEST_SITES)) && (!synopsis.publishers[publisher].options.stickyP)) {
if ((synopsis.publishers[publisher].scores[scorekeeper] <= 0) ||
(synopsis.options.minPublisherDuration > synopsis.publishers[publisher].duration) ||
(synopsis.options.minPublisherVisits > synopsis.publishers[publisher].visits)) return
}

results.push(underscore.extend({ publisher: publisher }, underscore.omit(synopsis.publishers[publisher], 'window')))
}, synopsis)
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@
"immutablepatch": "brave/immutable-js-patch",
"keytar": "^3.0.0",
"l20n": "^3.5.1",
"ledger-balance": "^0.8.63",
"ledger-client": "^0.8.97",
"ledger-geoip": "^0.8.73",
"ledger-publisher": "^0.8.97",
"ledger-balance": "^0.8.64",
"ledger-client": "^0.8.100",
"ledger-geoip": "^0.8.75",
"ledger-publisher": "^0.8.101",
"lru_cache": "^1.0.0",
"moment": "^2.15.1",
"normalize-url": "^1.7.0",
Expand Down

0 comments on commit 6f5acce

Please sign in to comment.