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

Commit

Permalink
Add new state for locationInfo
Browse files Browse the repository at this point in the history
Fix #7435
  • Loading branch information
mrose17 authored and cezaraugusto committed Mar 2, 2017
1 parent e01a2a9 commit 34e6239
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 10 deletions.
59 changes: 49 additions & 10 deletions app/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,6 @@ var quit = () => {
visit('NOOP', underscore.now(), null)
clearInterval(doneTimer)
doneWriter()
if (v2RulesetDB) {
v2RulesetDB.close()
v2RulesetDB = null
}
if (v2PublishersDB) {
v2PublishersDB.close()
v2PublishersDB = null
}
}

var boot = () => {
Expand Down Expand Up @@ -578,7 +570,11 @@ eventStore.addChangeListener(() => {
var entry, faviconURL, pattern, publisher
var location = page.url

if ((location.match(/^about/)) || ((locations[location]) && (locations[location].publisher))) return
if (location.match(/^about/)) return

location = urlFormat(underscore.pick(urlParse(location), [ 'protocol', 'host', 'hostname', 'port', 'pathname' ]))
publisher = locations[location] && locations[location].publisher
if (publisher) return updateLocation(location, publisher)

if (!page.publisher) {
try {
Expand All @@ -589,7 +585,7 @@ eventStore.addChangeListener(() => {
console.log('getPublisher error for ' + location + ': ' + ex.toString())
}
}
locations[location] = underscore.omit(page, [ 'url' ])
locations[location] = underscore.omit(page, [ 'url', 'protocol', 'faviconURL' ])
if (!page.publisher) return

publisher = page.publisher
Expand All @@ -602,6 +598,7 @@ eventStore.addChangeListener(() => {
updatePublisherInfo()
})
}
updateLocation(location, publisher)
entry = synopsis.publishers[publisher]
if ((page.protocol) && (!entry.protocol)) entry.protocol = page.protocol

Expand Down Expand Up @@ -866,6 +863,7 @@ var enable = (paymentsEnabled) => {
entries.forEach((entry) => {
locations[entry.location] = entry
publishers[publisher][entry.location] = { timestamp: entry.when, tabIds: [] }
updateLocation(entry.location, publisher)
})
})
} catch (ex) {
Expand All @@ -875,6 +873,47 @@ var enable = (paymentsEnabled) => {
})
}

/*
* update location information
*/

var updateLocationInfo = (location) => {
appActions.updateLocationInfo(locations)
}

var updateLocation = (location, publisher) => {
var updateP

if (typeof locations[location].stickyP === 'undefined') locations[location].stickyP = stickyP(publisher)
if (typeof locations[location].verified !== 'undefined') return

if (synopsis && synopsis.publishers[publisher] && (typeof synopsis.publishers[publisher].options.verified !== 'undefined')) {
locations[location].verified = synopsis.publishers[publisher].options.verified || false
updateP = true
} else {
verifiedP(publisher, (err, result) => {
if ((err) && (!err.notFound)) return

locations[location].verified = (result && result.verified) || false
updateLocationInfo(location)
})
}

if (synopsis && synopsis.publishers[publisher] && (typeof synopsis.publishers[publisher].options.exclude !== 'undefined')) {
locations[location].exclude = synopsis.publishers[publisher].options.exclude || false
updateP = true
} else {
excludeP(publisher, (err, result) => {
if ((err) && (!err.notFound)) return

locations[location].exclude = (result && result.exclude) || false
updateLocationInfo(location)
})
}

if (updateP) updateLocationInfo(location)
}

/*
* update publisher information
*/
Expand Down
10 changes: 10 additions & 0 deletions docs/appActions.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,16 @@ Updates ledger information for the payments pane



### updateLocationInfo(locationInfo)

Updates location information for the URL bar

**Parameters**

**locationInfo**: `object`, the current location synopsis



### updatePublisherInfo(publisherInfo)

Updates publisher information for the payments pane
Expand Down
9 changes: 9 additions & 0 deletions docs/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,15 @@ WindowStore
top: number // the top position of the popup window
},
previewFrameKey: number,
locationInfo: {
[url]: {
publisher: string, // url of the publisher in question
verified: boolean, // wheter or not site is a verified publisher
exclude: boolean, // wheter or not site is in the excluded list
stickyP: boolean, // wheter or not site was added using addFunds urlbar toggle
timestamp: number // timestamp in milliseconds
}
},
publisherInfo: {
synopsis: [{
daysSpent: number, // e.g., 1
Expand Down
11 changes: 11 additions & 0 deletions js/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,17 @@ const appActions = {
})
},

/**
* Updates location information for the URL bar
* @param {object} locationInfo - the current location synopsis
*/
updateLocationInfo: function (locationInfo) {
AppDispatcher.dispatch({
actionType: appConstants.APP_UPDATE_LOCATION_INFO,
locationInfo
})
},

/**
* Updates publisher information for the payments pane
* @param {object} publisherInfo - the current publisher synopsis
Expand Down
1 change: 1 addition & 0 deletions js/constants/appConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const appConstants = {
APP_IMPORT_BROWSER_DATA: _,
APP_UPDATE_LEDGER_INFO: _,
APP_LEDGER_RECOVERY_STATUS_CHANGED: _,
APP_UPDATE_LOCATION_INFO: _,
APP_UPDATE_PUBLISHER_INFO: _,
APP_SHOW_NOTIFICATION: _, /** @param {Object} detail */
APP_HIDE_NOTIFICATION: _, /** @param {string} message */
Expand Down
3 changes: 3 additions & 0 deletions js/stores/appStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,9 @@ const handleAppAction = (action) => {
case appConstants.APP_UPDATE_LEDGER_INFO:
appState = appState.set('ledgerInfo', Immutable.fromJS(action.ledgerInfo))
break
case appConstants.APP_UPDATE_LOCATION_INFO:
appState = appState.set('locationInfo', Immutable.fromJS(action.locationInfo))
break
case appConstants.APP_UPDATE_PUBLISHER_INFO:
appState = appState.set('publisherInfo', Immutable.fromJS(action.publisherInfo))
break
Expand Down

0 comments on commit 34e6239

Please sign in to comment.