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

Commit

Permalink
More Sync sites refactor fixes and remove siteUtil.js (#10222)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayumi authored and NejcZdovc committed Aug 2, 2017
1 parent c7d84ec commit 6ba8e96
Show file tree
Hide file tree
Showing 8 changed files with 278 additions and 259 deletions.
5 changes: 3 additions & 2 deletions app/common/lib/historyUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,15 @@ const prepareHistoryEntry = (siteDetail) => {

return makeImmutable({
lastAccessedTime: time,
objectId: undefined,
objectId: siteDetail.get('objectId', null),
title: siteDetail.get('title'),
location: siteDetail.get('location'),
partitionNumber: ~~siteDetail.get('partitionNumber', 0),
count: 1,
themeColor: siteDetail.get('themeColor'),
favicon: siteDetail.get('favicon', siteDetail.get('icon')),
key: getKey(siteDetail)
key: getKey(siteDetail),
skipSync: siteDetail.get('skipSync', null)
})
}

Expand Down
5 changes: 3 additions & 2 deletions app/common/state/bookmarkFoldersState.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ const bookmarkFoldersState = {
key: key.toString(),
parentFolderId: ~~folderDetails.get('parentFolderId', 0),
partitionNumber: ~~folderDetails.get('partitionNumber', 0),
objectId: null,
type: siteTags.BOOKMARK_FOLDER
objectId: folderDetails.get('objectId', null),
type: siteTags.BOOKMARK_FOLDER,
skipSync: folderDetails.get('skipSync', null)
})

state = state.setIn([STATE_SITES.BOOKMARK_FOLDERS, key.toString()], newFolder)
Expand Down
16 changes: 13 additions & 3 deletions app/common/state/bookmarksState.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,12 @@ const bookmarksState = {
location: bookmarkDetail.get('location'),
parentFolderId: ~~bookmarkDetail.get('parentFolderId', 0),
partitionNumber: ~~dataItem.get('partitionNumber', 0),
objectId: null,
objectId: bookmarkDetail.get('objectId', null),
favicon: dataItem.get('favicon'),
themeColor: dataItem.get('themeColor'),
type: siteTags.BOOKMARK,
key: key
key: key,
skipSync: bookmarkDetail.get('skipSync', null)
})

if (key === null) {
Expand Down Expand Up @@ -204,8 +205,17 @@ const bookmarksState = {
return state
}

const syncEnabled = getSetting(settings.SYNC_ENABLED) === true
const bookmarks = bookmarksState.getBookmarks(state)
.filter(bookmark => bookmark.get('parentFolderId') !== ~~parentFolderId)
.filter(bookmark => {
if (bookmark.get('parentFolderId') !== ~~parentFolderId) {
return true
}
if (syncEnabled) {
syncActions.removeSite(bookmark)
}
return false
})

return state.set(STATE_SITES.BOOKMARKS, bookmarks)
},
Expand Down
22 changes: 15 additions & 7 deletions app/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,15 @@ const appStoreChangeCallback = function (diffs) {
const entryJS = entry.toJS()
entryJS.objectId = entryJS.objectId || syncUtil.newObjectId(statePath)

sendSyncRecords(backgroundSender, action,
[isSite ? syncUtil.createSiteData(entryJS) : syncUtil.createSiteSettingsData(statePath[1], entryJS)])
let record = null
if (type === STATE_SITES.BOOKMARKS || type === STATE_SITES.BOOKMARK_FOLDERS) {
record = syncUtil.createBookmarkData(entryJS)
} else if (type === STATE_SITES.HISTORY_SITES) {
record = syncUtil.createHistorySiteData(entryJS)
} else {
record = syncUtil.createSiteSettingsData(statePath[1], entryJS)
}
sendSyncRecords(backgroundSender, action, [record])
}
}
})
Expand Down Expand Up @@ -212,9 +219,10 @@ const dispatcherCallback = (action) => {
return
}
switch (action.actionType) {
// Currently triggered only by bookmarksState and bookmarkFoldersState.
case syncConstants.SYNC_REMOVE_SITE:
sendSyncRecords(backgroundSender, writeActions.DELETE,
[syncUtil.createSiteData(action.item.toJS())])
[syncUtil.createBookmarkData(action.item.toJS())])
break
case syncConstants.SYNC_CLEAR_HISTORY:
backgroundSender.send(syncMessages.DELETE_SYNC_CATEGORY, CATEGORY_MAP.historySite.categoryName)
Expand Down Expand Up @@ -273,7 +281,7 @@ module.exports.onSyncReady = (isFirstRun, e) => {
* Sync a bookmark that has not been synced yet, first syncing the parent
* folder if needed. For folders, set and memoize folderId to ensure
* consistent parentFolderObjectIds.
* Otherwise siteUtil.createSiteData() will generate new objectIds every
* Otherwise syncUtil.createBookmarkData() will generate new objectIds every
* call; there's not enough time to dispatch id updates to appStore.sites.
* @param {Immutable.Map} site
*/
Expand All @@ -300,13 +308,13 @@ module.exports.onSyncReady = (isFirstRun, e) => {
if (!folderToObjectId[parentFolderId]) {
const folderResult = bookmarkFoldersState.getFolder(appState, parentFolderId)
if (!folderResult.isEmpty()) {
syncBookmark(folderResult[1], appState)
syncBookmark(folderResult, appState)
}
}
bookmarkJS.parentFolderObjectId = folderToObjectId[parentFolderId]
}

const record = syncUtil.createSiteData(bookmarkJS, appState)
const record = syncUtil.createBookmarkData(bookmarkJS, appState)
const folderId = bookmark.get('folderId')
if (typeof folderId === 'number') {
folderToObjectId[folderId] = record.objectId
Expand Down Expand Up @@ -338,7 +346,7 @@ module.exports.onSyncReady = (isFirstRun, e) => {
// might not be synced.
const siteSettings =
appState.get('siteSettings').filter((value, key) => {
return !value.get('objectId') && syncUtil.isSyncable('siteSetting', value)
return !value.get('objectId') && syncUtil.isSyncableSiteSetting(value)
}).toJS()
if (siteSettings) {
const siteSettingsData = Object.keys(siteSettings).map((item) => {
Expand Down
14 changes: 0 additions & 14 deletions js/state/siteUtil.js

This file was deleted.

Loading

0 comments on commit 6ba8e96

Please sign in to comment.