Skip to content

Commit

Permalink
Fixes undefined synopsis for media publishers
Browse files Browse the repository at this point in the history
Resolves brave#12591

Auditors:

Test Plan:
  • Loading branch information
NejcZdovc committed Jan 18, 2018
1 parent 6cb4303 commit d0d74d2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
32 changes: 15 additions & 17 deletions app/browser/api/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -2400,7 +2400,7 @@ const onMediaRequest = (state, xhr, type, tabId) => {
if (!cache.isEmpty()) {
const publisherKey = cache.get('publisher')
const publisher = ledgerState.getPublisher(state, publisherKey)
if (!publisher.isEmpty()) {
if (!publisher.isEmpty() && publisher.has('providerName')) {
return module.exports.saveVisit(state, publisherKey, {
duration,
revisited,
Expand Down Expand Up @@ -2449,19 +2449,13 @@ const onMediaPublisher = (state, mediaKey, response, duration, revisited) => {
const publisherURL = response.get('publisherURL')
const providerName = response.get('providerName')

if (publisher.isEmpty()) {
revisited = false
if (!synopsis.publishers[publisherKey] || publisher.isEmpty()) {
synopsis.initPublisher(publisherKey)

if (!synopsis.publishers[publisherKey]) {
return state
}

synopsis.publishers[publisherKey].faviconName = faviconName
synopsis.publishers[publisherKey].faviconURL = faviconURL
synopsis.publishers[publisherKey].publisherURL = publisherURL
synopsis.publishers[publisherKey].providerName = providerName

state = ledgerState.setPublisher(state, publisherKey, synopsis.publishers[publisherKey])

if (!getSetting(settings.PAYMENTS_SITES_AUTO_SUGGEST)) {
Expand All @@ -2473,15 +2467,19 @@ const onMediaPublisher = (state, mediaKey, response, duration, revisited) => {
savePublisherOption(publisherKey, 'exclude', exclude)
})
}
} else {
synopsis.publishers[publisherKey].faviconName = faviconName
synopsis.publishers[publisherKey].faviconURL = faviconURL
synopsis.publishers[publisherKey].publisherURL = publisherURL
synopsis.publishers[publisherKey].providerName = providerName
state = ledgerState.setPublishersProp(state, publisherKey, 'faviconName', faviconName)
state = ledgerState.setPublishersProp(state, publisherKey, 'faviconURL', faviconURL)
state = ledgerState.setPublishersProp(state, publisherKey, 'publisherURL', publisherURL)
state = ledgerState.setPublishersProp(state, publisherKey, 'providerName', providerName)
}

synopsis.publishers[publisherKey].faviconName = faviconName
synopsis.publishers[publisherKey].faviconURL = faviconURL
synopsis.publishers[publisherKey].publisherURL = publisherURL
synopsis.publishers[publisherKey].providerName = providerName
state = ledgerState.setPublishersProp(state, publisherKey, 'faviconName', faviconName)
state = ledgerState.setPublishersProp(state, publisherKey, 'faviconURL', faviconURL)
state = ledgerState.setPublishersProp(state, publisherKey, 'publisherURL', publisherURL)
state = ledgerState.setPublishersProp(state, publisherKey, 'providerName', providerName)

if (publisher.isEmpty()) {
revisited = false
}

const cacheObject = Immutable.Map()
Expand Down
3 changes: 2 additions & 1 deletion test/unit/app/browser/api/ledgerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,8 @@ describe('ledger api unit tests', function () {
}))
.setIn(['ledger', 'synopsis', 'publishers', publisherKey], Immutable.fromJS({
visits: 1,
duration: 1000
duration: 1000,
providerName: 'YouTube'
}))

beforeEach(function () {
Expand Down

0 comments on commit d0d74d2

Please sign in to comment.