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

Commit

Permalink
Merge pull request #9187 from brave/fix/sync-hierarchy
Browse files Browse the repository at this point in the history
fix sync duplicating folders
  • Loading branch information
bsclifton committed Jun 5, 2017
1 parent 42d8967 commit 9f7c3b7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 26 deletions.
24 changes: 14 additions & 10 deletions app/browser/reducers/sitesReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,32 @@ const sitesReducer = (state, action, immutableAction) => {
}
break
case appConstants.APP_ADD_SITE:
const isSyncEnabled = syncEnabled()
if (Immutable.List.isList(action.siteDetail)) {
action.siteDetail.forEach((s) => {
state = siteUtil.addSite(state, s, action.tag, undefined, action.skipSync)
if (isSyncEnabled) {
state = syncUtil.updateSiteCache(state, s)
}
})
} else {
let sites = state.get('sites')
if (!action.siteDetail.get('folderId') && siteUtil.isFolder(action.siteDetail)) {
action.siteDetail = action.siteDetail.set('folderId', siteUtil.getNextFolderId(sites))
}
state = siteUtil.addSite(state, action.siteDetail, action.tag, action.originalSiteDetail, action.skipSync)
}
if (action.destinationDetail) {
const sourceKey = siteUtil.getSiteKey(action.siteDetail)
const destinationKey = siteUtil.getSiteKey(action.destinationDetail)
if (action.destinationDetail) {
const sourceKey = siteUtil.getSiteKey(action.siteDetail)
const destinationKey = siteUtil.getSiteKey(action.destinationDetail)

if (sourceKey != null) {
state = siteUtil.moveSite(state,
sourceKey, destinationKey, false, false, true)
if (sourceKey != null) {
state = siteUtil.moveSite(state,
sourceKey, destinationKey, false, false, true)
}
}
if (isSyncEnabled) {
state = syncUtil.updateSiteCache(state, action.destinationDetail || action.siteDetail)
}
}
if (syncEnabled()) {
state = syncUtil.updateSiteCache(state, action.destinationDetail || action.siteDetail)
}
state = updateActiveTabBookmarked(state)
break
Expand Down
16 changes: 0 additions & 16 deletions js/state/siteUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -853,19 +853,3 @@ module.exports.getOrigin = function (location) {
return null
}
}

/**
* Sets object id on a state entry.
* @param {Immutable.Map} item
* @returns {Immutable.map}
*/
module.exports.setObjectId = (item) => {
if (!item || !item.toJS) {
return
}
if (item.get('objectId')) {
return item
}
const crypto = require('crypto')
return item.set('objectId', new Immutable.List(crypto.randomBytes(16)))
}
4 changes: 4 additions & 0 deletions js/stores/appStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,10 @@ const handleAppAction = (action) => {
if (obj && obj.constructor === Immutable.Map) {
appState = appState.setIn(action.objectPath.concat(['objectId']),
action.objectId)
// Update the site cache if this is a site
if (action.objectPath[0] === 'sites') {
appState = syncUtil.updateSiteCache(appState, obj)
}
}
break
case appConstants.APP_SAVE_SYNC_DEVICES:
Expand Down

0 comments on commit 9f7c3b7

Please sign in to comment.