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

Commit

Permalink
do not delete objectIds when sync is reset
Browse files Browse the repository at this point in the history
save the original seed for bookmarks, so they can be synced to a profile with
a different seed if needed. fix #7405.
  • Loading branch information
diracdeltas committed Feb 28, 2017
1 parent 0dc505a commit 754c29d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 3 additions & 1 deletion app/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ module.exports.onSyncReady = (isFirstRun, e) => {
}
const appState = AppStore.getState()
const sites = appState.get('sites') || new Immutable.List()
const seed = appState.get('seed') || new Immutable.List()

/**
* Sync a bookmark that has not been synced yet, first syncing the parent
Expand All @@ -187,7 +188,8 @@ module.exports.onSyncReady = (isFirstRun, e) => {
*/
const folderToObjectId = {}
const syncBookmark = (site) => {
if (!site || site.get('objectId') || folderToObjectId[site.get('folderId')] || !syncUtil.isSyncable('bookmark', site)) {
if (!site || (site.get('objectId') && seed.equals(site.get('originalSeed'))) ||
folderToObjectId[site.get('folderId')] || !syncUtil.isSyncable('bookmark', site)) {
return
}

Expand Down
1 change: 1 addition & 0 deletions docs/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ AppStore
lastAccessedTime: number, // datetime.getTime()
location: string,
objectId: Array.<number>,
originalSeed: Array.<number>, // only set for bookmarks that have been synced before a sync profile reset
parentFolderId: number, // set for bookmarks and bookmark folders only
partitionNumber: number, // optionally specifies a specific session
tags: [string], // empty, 'bookmark', 'bookmark-folder', 'pinned', or 'reader'
Expand Down
14 changes: 8 additions & 6 deletions js/stores/appStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -941,14 +941,16 @@ const handleAppAction = (action) => {
case appConstants.APP_RESET_SYNC_DATA:
const sessionStore = require('../../app/sessionStore')
const syncDefault = Immutable.fromJS(sessionStore.defaultAppState().sync)
const originalSeed = appState.getIn(['sync', 'seed'])
appState = appState.set('sync', syncDefault)
appState.get('sites').forEach((site, key) => {
if (!site.has('objectId')) { return }
appState = appState.setIn(['sites', key], site.delete('objectId'))
})
appState.get('siteSettings').forEach((site, key) => {
if (!site.has('objectId')) { return }
appState = appState.setIn(['siteSettings', key], site.delete('objectId'))
if (site.has('objectId') && syncUtil.isSyncable('bookmark', site)) {
// Remember which profile this bookmark was originally synced to.
// Since old bookmarks should be synced when a new profile is created,
// we have to keep track of which profile already has these bookmarks
// or else the old profile may have these bookmarks duplicated. #7405
appState = appState.setIn(['sites', key, 'originalSeed'], originalSeed)
}
})
break
case appConstants.APP_SHOW_DOWNLOAD_DELETE_CONFIRMATION:
Expand Down

0 comments on commit 754c29d

Please sign in to comment.