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

Commit 6955ca1

Browse files
ayumiNejcZdovc
authored andcommitted
More Sync sites refactor fixes and remove siteUtil.js (#10222)
1 parent b081d3e commit 6955ca1

11 files changed

+305
-273
lines changed

app/common/lib/historyUtil.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,15 @@ const prepareHistoryEntry = (siteDetail) => {
7575

7676
return makeImmutable({
7777
lastAccessedTime: time,
78-
objectId: undefined,
78+
objectId: siteDetail.get('objectId', null),
7979
title: siteDetail.get('title'),
8080
location: siteDetail.get('location'),
8181
partitionNumber: ~~siteDetail.get('partitionNumber', 0),
8282
count: 1,
8383
themeColor: siteDetail.get('themeColor'),
8484
favicon: siteDetail.get('favicon', siteDetail.get('icon')),
85-
key: getKey(siteDetail)
85+
key: getKey(siteDetail),
86+
skipSync: siteDetail.get('skipSync', null)
8687
})
8788
}
8889

app/common/state/bookmarkFoldersState.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ const bookmarkFoldersState = {
6363
key: key.toString(),
6464
parentFolderId: ~~folderDetails.get('parentFolderId', 0),
6565
partitionNumber: ~~folderDetails.get('partitionNumber', 0),
66-
objectId: null,
67-
type: siteTags.BOOKMARK_FOLDER
66+
objectId: folderDetails.get('objectId', null),
67+
type: siteTags.BOOKMARK_FOLDER,
68+
skipSync: folderDetails.get('skipSync', null)
6869
})
6970

7071
state = state.setIn([STATE_SITES.BOOKMARK_FOLDERS, key.toString()], newFolder)

app/common/state/bookmarksState.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,12 @@ const bookmarksState = {
117117
location: bookmarkDetail.get('location'),
118118
parentFolderId: ~~bookmarkDetail.get('parentFolderId', 0),
119119
partitionNumber: ~~dataItem.get('partitionNumber', 0),
120-
objectId: null,
120+
objectId: bookmarkDetail.get('objectId', null),
121121
favicon: dataItem.get('favicon'),
122122
themeColor: dataItem.get('themeColor'),
123123
type: siteTags.BOOKMARK,
124-
key: key
124+
key: key,
125+
skipSync: bookmarkDetail.get('skipSync', null)
125126
})
126127

127128
if (key === null) {
@@ -204,8 +205,17 @@ const bookmarksState = {
204205
return state
205206
}
206207

208+
const syncEnabled = getSetting(settings.SYNC_ENABLED) === true
207209
const bookmarks = bookmarksState.getBookmarks(state)
208-
.filter(bookmark => bookmark.get('parentFolderId') !== ~~parentFolderId)
210+
.filter(bookmark => {
211+
if (bookmark.get('parentFolderId') !== ~~parentFolderId) {
212+
return true
213+
}
214+
if (syncEnabled) {
215+
syncActions.removeSite(bookmark)
216+
}
217+
return false
218+
})
209219

210220
return state.set(STATE_SITES.BOOKMARKS, bookmarks)
211221
},

app/sync.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,15 @@ const appStoreChangeCallback = function (diffs) {
125125
const entryJS = entry.toJS()
126126
entryJS.objectId = entryJS.objectId || syncUtil.newObjectId(statePath)
127127

128-
sendSyncRecords(backgroundSender, action,
129-
[isSite ? syncUtil.createSiteData(entryJS) : syncUtil.createSiteSettingsData(statePath[1], entryJS)])
128+
let record = null
129+
if (type === STATE_SITES.BOOKMARKS || type === STATE_SITES.BOOKMARK_FOLDERS) {
130+
record = syncUtil.createBookmarkData(entryJS)
131+
} else if (type === STATE_SITES.HISTORY_SITES) {
132+
record = syncUtil.createHistorySiteData(entryJS)
133+
} else {
134+
record = syncUtil.createSiteSettingsData(statePath[1], entryJS)
135+
}
136+
sendSyncRecords(backgroundSender, action, [record])
130137
}
131138
}
132139
})
@@ -212,9 +219,10 @@ const dispatcherCallback = (action) => {
212219
return
213220
}
214221
switch (action.actionType) {
222+
// Currently triggered only by bookmarksState and bookmarkFoldersState.
215223
case syncConstants.SYNC_REMOVE_SITE:
216224
sendSyncRecords(backgroundSender, writeActions.DELETE,
217-
[syncUtil.createSiteData(action.item.toJS())])
225+
[syncUtil.createBookmarkData(action.item.toJS())])
218226
break
219227
case syncConstants.SYNC_CLEAR_HISTORY:
220228
backgroundSender.send(syncMessages.DELETE_SYNC_CATEGORY, CATEGORY_MAP.historySite.categoryName)
@@ -273,7 +281,7 @@ module.exports.onSyncReady = (isFirstRun, e) => {
273281
* Sync a bookmark that has not been synced yet, first syncing the parent
274282
* folder if needed. For folders, set and memoize folderId to ensure
275283
* consistent parentFolderObjectIds.
276-
* Otherwise siteUtil.createSiteData() will generate new objectIds every
284+
* Otherwise syncUtil.createBookmarkData() will generate new objectIds every
277285
* call; there's not enough time to dispatch id updates to appStore.sites.
278286
* @param {Immutable.Map} site
279287
*/
@@ -300,13 +308,13 @@ module.exports.onSyncReady = (isFirstRun, e) => {
300308
if (!folderToObjectId[parentFolderId]) {
301309
const folderResult = bookmarkFoldersState.getFolder(appState, parentFolderId)
302310
if (!folderResult.isEmpty()) {
303-
syncBookmark(folderResult[1], appState)
311+
syncBookmark(folderResult, appState)
304312
}
305313
}
306314
bookmarkJS.parentFolderObjectId = folderToObjectId[parentFolderId]
307315
}
308316

309-
const record = syncUtil.createSiteData(bookmarkJS, appState)
317+
const record = syncUtil.createBookmarkData(bookmarkJS, appState)
310318
const folderId = bookmark.get('folderId')
311319
if (typeof folderId === 'number') {
312320
folderToObjectId[folderId] = record.objectId
@@ -338,7 +346,7 @@ module.exports.onSyncReady = (isFirstRun, e) => {
338346
// might not be synced.
339347
const siteSettings =
340348
appState.get('siteSettings').filter((value, key) => {
341-
return !value.get('objectId') && syncUtil.isSyncable('siteSetting', value)
349+
return !value.get('objectId') && syncUtil.isSyncableSiteSetting(value)
342350
}).toJS()
343351
if (siteSettings) {
344352
const siteSettingsData = Object.keys(siteSettings).map((item) => {

js/state/siteUtil.js

-14
This file was deleted.

0 commit comments

Comments
 (0)