From 5dfc63248d8878c0dcec5aedba5f96b9aeee3b3c Mon Sep 17 00:00:00 2001 From: yan Date: Tue, 28 Feb 2017 22:36:30 +0000 Subject: [PATCH] do not delete objectIds when sync is reset save the original seed for bookmarks, so they can be synced to a profile with a different seed if needed. fix #7405. --- app/sync.js | 4 +++- docs/state.md | 1 + js/stores/appStore.js | 14 ++++++++------ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/sync.js b/app/sync.js index 026fd61137d..69496417c71 100644 --- a/app/sync.js +++ b/app/sync.js @@ -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 @@ -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 } diff --git a/docs/state.md b/docs/state.md index c56db050cdd..5c0caf1f89b 100644 --- a/docs/state.md +++ b/docs/state.md @@ -224,6 +224,7 @@ AppStore lastAccessedTime: number, // datetime.getTime() location: string, objectId: Array., + originalSeed: Array., // 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' diff --git a/js/stores/appStore.js b/js/stores/appStore.js index 4e6af56a2b7..8f43d0e9988 100644 --- a/js/stores/appStore.js +++ b/js/stores/appStore.js @@ -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 (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: