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

Commit

Permalink
Merge pull request #13285 from NejcZdovc/hotfix/#13281-image
Browse files Browse the repository at this point in the history
Fixes favicons fetch
  • Loading branch information
bsclifton committed Feb 26, 2018
1 parent 6188286 commit 7401f4e
Show file tree
Hide file tree
Showing 7 changed files with 439 additions and 283 deletions.
76 changes: 63 additions & 13 deletions app/browser/api/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,17 @@ const addNewLocation = (state, location, tabId = tabState.TAB_ID_NONE, keepInfo
return state
}

const onFavIconReceived = (state, publisherKey, blob) => {
if (publisherKey == null) {
return state
}

state = ledgerState.setPublishersProp(state, publisherKey, 'faviconURL', blob)
module.exports.savePublisherData(publisherKey, 'faviconURL', blob)

return state
}

const getFavIcon = (state, publisherKey, page) => {
let publisher = ledgerState.getPublisher(state, publisherKey)
const protocol = page.get('protocol')
Expand Down Expand Up @@ -921,7 +932,7 @@ const fetchFavIcon = (publisherKey, url, redirects) => {
underscore.keys(fileTypes).forEach((fileType) => {
if (matchP) return
if (
prefix.length >= fileTypes[fileType].length ||
prefix.length < fileTypes[fileType].length ||
fileTypes[fileType].compare(prefix, 0, fileTypes[fileType].length) !== 0
) {
return
Expand All @@ -936,10 +947,6 @@ const fetchFavIcon = (publisherKey, url, redirects) => {
} else if (tail > 0 && (tail + 8 >= blob.length)) return

appActions.onFavIconReceived(publisherKey, blob)

if (synopsis.publishers && synopsis.publishers[publisherKey]) {
synopsis.publishers[publisherKey].faviconURL = blob
}
})
}

Expand Down Expand Up @@ -2363,6 +2370,31 @@ const migration = (state) => {
return state
}

const setPublishersOptions = (state, publishersArray) => {
if (!publishersArray || publishersArray.size === 0) {
return state
}

publishersArray.forEach(publisherData => {
const publisherKey = publisherData.get('publisherKey')

if (publisherKey == null) {
return state
}

for (const data of publisherData) {
const prop = data[0]
const value = data[1]
if (prop !== 'publisherKey') {
state = ledgerState.setPublisherOption(state, publisherKey, prop, value)
module.exports.savePublisherOption(publisherKey, prop, value)
}
}
})

return state
}

// for synopsis variable handling only
const deleteSynopsisPublisher = (publisherKey) => {
delete synopsis.publishers[publisherKey]
Expand All @@ -2373,15 +2405,31 @@ const saveOptionSynopsis = (prop, value) => {
}

const savePublisherOption = (publisherKey, prop, value) => {
if (synopsis && synopsis.publishers && synopsis.publishers[publisherKey] && synopsis.publishers[publisherKey].options) {
synopsis.publishers[publisherKey].options[prop] = value
if (!synopsis || !synopsis.publishers || !publisherKey) {
return
}

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

if (!synopsis.publishers[publisherKey].options) {
synopsis.publishers[publisherKey].options = {}
}

synopsis.publishers[publisherKey].options[prop] = value
}

const savePublisherData = (publisherKey, prop, value) => {
if (synopsis && synopsis.publishers && synopsis.publishers[publisherKey]) {
synopsis.publishers[publisherKey][prop] = value
if (!synopsis || !synopsis.publishers || !publisherKey) {
return
}

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

synopsis.publishers[publisherKey][prop] = value
}

const deleteSynopsis = () => {
Expand Down Expand Up @@ -2507,10 +2555,10 @@ const onMediaPublisher = (state, mediaKey, response, duration, revisited) => {
}
}

synopsis.publishers[publisherKey].faviconName = faviconName
synopsis.publishers[publisherKey].faviconURL = faviconURL
synopsis.publishers[publisherKey].publisherURL = publisherURL
synopsis.publishers[publisherKey].providerName = providerName
savePublisherData(publisherKey, 'faviconName', faviconName)
savePublisherData(publisherKey, 'faviconURL', faviconURL)
savePublisherData(publisherKey, 'publisherURL', publisherURL)
savePublisherData(publisherKey, 'providerName', providerName)
state = ledgerState.setPublishersProp(state, publisherKey, 'faviconName', faviconName)
state = ledgerState.setPublishersProp(state, publisherKey, 'faviconURL', faviconURL)
state = ledgerState.setPublishersProp(state, publisherKey, 'publisherURL', publisherURL)
Expand Down Expand Up @@ -2742,6 +2790,7 @@ const getMethods = () => {
deleteSynopsis,
normalizePinned,
roundToTarget,
onFavIconReceived,
savePublisherData,
pruneSynopsis,
onMediaRequest,
Expand All @@ -2755,6 +2804,7 @@ const getMethods = () => {
onPublisherTimestamp,
checkVerifiedStatus,
checkReferralActivity,
setPublishersOptions,
referralCheck,
roundtrip
}
Expand Down
4 changes: 2 additions & 2 deletions app/browser/reducers/ledgerReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ const ledgerReducer = (state, action, immutableAction) => {
}
case appConstants.APP_ON_FAVICON_RECEIVED:
{
state = ledgerState.setPublishersProp(state, action.get('publisherKey'), 'faviconURL', action.get('blob'))
state = ledgerApi.onFavIconReceived(state, action.get('publisherKey'), action.get('blob'))
state = ledgerApi.updatePublisherInfo(state)
break
}
Expand All @@ -223,7 +223,7 @@ const ledgerReducer = (state, action, immutableAction) => {
}
case appConstants.APP_ON_PUBLISHERS_OPTION_UPDATE:
{
state = ledgerState.setPublishersOption(state, action.get('publishersArray'))
state = ledgerApi.setPublishersOptions(state, action.get('publishersArray'))
break
}
case appConstants.APP_ON_LEDGER_WALLET_CREATE:
Expand Down
26 changes: 0 additions & 26 deletions app/common/state/ledgerState.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,32 +192,6 @@ const ledgerState = {
return state.setIn(['ledger', 'synopsis', 'publishers', key, 'options', prop], value)
},

setPublishersOption: (state, publishersArray) => {
state = validateState(state)

if (!publishersArray || publishersArray.size === 0) {
return state
}

publishersArray.forEach(publisherData => {
const publisherKey = publisherData.get('publisherKey')

if (publisherKey == null) {
return
}

for (const data of publisherData) {
const prop = data[0]
const value = data[1]
if (prop !== 'publisherKey') {
state = ledgerState.setPublisherOption(state, publisherKey, prop, value)
}
}
})

return state
},

getPublisherOption: (state, key, prop) => {
state = validateState(state)

Expand Down
Loading

0 comments on commit 7401f4e

Please sign in to comment.