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

Add default lastAccessTime for history entries only #5349

Merged
merged 1 commit into from
Nov 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions app/importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ const getParentFolderId = (path, pathMap, sites, topLevelFolderId, nextFolderIdO
customTitle: parentFolder,
folderId: parentFolderId,
parentFolderId: getParentFolderId(path, pathMap, sites, topLevelFolderId, nextFolderIdObject),
lastAccessedTime: (new Date()).getTime(),
lastAccessedTime: 0,
creationTime: (new Date()).getTime(),
tags: [siteTags.BOOKMARK_FOLDER]
}
sites.push(folder)
Expand All @@ -126,7 +127,8 @@ importer.on('add-bookmarks', (e, bookmarks, topLevelFolder) => {
customTitle: topLevelFolder,
folderId: topLevelFolderId,
parentFolderId: 0,
lastAccessedTime: (new Date()).getTime(),
lastAccessedTime: 0,
creationTime: (new Date()).getTime(),
tags: [siteTags.BOOKMARK_FOLDER]
})
} else {
Expand All @@ -150,7 +152,8 @@ importer.on('add-bookmarks', (e, bookmarks, topLevelFolder) => {
customTitle: bookmarks[i].title,
folderId: folderId,
parentFolderId: parentFolderId,
lastAccessedTime: bookmarks[i].creation_time * 1000,
lastAccessedTime: 0,
creationTime: bookmarks[i].creation_time * 1000,
tags: [siteTags.BOOKMARK_FOLDER]
}
sites.push(folder)
Expand All @@ -160,7 +163,8 @@ importer.on('add-bookmarks', (e, bookmarks, topLevelFolder) => {
customTitle: bookmarks[i].title,
location: bookmarks[i].url,
parentFolderId: parentFolderId,
lastAccessedTime: bookmarks[i].creation_time * 1000,
lastAccessedTime: 0,
creationTime: bookmarks[i].creation_time * 1000,
tags: [siteTags.BOOKMARK]
}
sites.push(site)
Expand Down
1 change: 1 addition & 0 deletions docs/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ AppStore
favicon: string, // URL of the favicon
themeColor: string, // css compatible color string
lastAccessedTime: number, // datetime.getTime()
creationTime: number, //creation time of bookmark
partitionNumber: number, // Optionally specifies a specific session
folderId: number, // Set for bookmark folders only
parentFolderId: number // Set for bookmarks and bookmark folders only
Expand Down
9 changes: 8 additions & 1 deletion js/state/siteUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,15 @@ const mergeSiteDetails = (oldSiteDetail, newSiteDetail, tag, folderId) => {
? newSiteDetail.get('customTitle')
: (newSiteDetail.get('customTitle') || oldSiteDetail && oldSiteDetail.get('customTitle'))

let lastAccessedTime
if (isBookmark(tag) || isBookmarkFolder(tag)) {
lastAccessedTime = newSiteDetail.get('lastAccessedTime') || 0
} else {
lastAccessedTime = newSiteDetail.get('lastAccessedTime') || new Date().getTime()
}

let site = Immutable.fromJS({
lastAccessedTime: newSiteDetail.get('lastAccessedTime') || new Date().getTime(),
lastAccessedTime: lastAccessedTime,
tags,
title: newSiteDetail.get('title')
})
Expand Down
11 changes: 9 additions & 2 deletions test/unit/state/siteUtilTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ describe('siteUtil', function () {
const expectedSites = Immutable.fromJS([bookmarkAllFields])
assert.deepEqual(processedSites.toJS(), expectedSites.toJS())
})
it('sets default values for lastAccessedTime and tag when they are missing', function () {
it('sets 0 for lastAccessedTime if not specified', function () {
const processedSites = siteUtil.addSite(emptySites, bookmarkMinFields, siteTags.BOOKMARK)
assert.equal(!!processedSites.getIn([0, 'lastAccessedTime']), true)
assert.equal(processedSites.getIn([0, 'lastAccessedTime']), 0)
assert.deepEqual(processedSites.getIn([0, 'tags']).toJS(), [siteTags.BOOKMARK])
})
})
Expand Down Expand Up @@ -279,6 +279,13 @@ describe('siteUtil', function () {
assert.deepEqual(processedSites.toJS(), expectedSites.toJS())
})
})
describe('when adding history', function () {
it('sets default values for lastAccessedTime and tag when they are missing', function () {
const processedSites = siteUtil.addSite(emptySites, bookmarkMinFields)
assert.equal(!!processedSites.getIn([0, 'lastAccessedTime']), true)
assert.deepEqual(processedSites.getIn([0, 'tags']).toJS(), [])
})
})
})

describe('for existing entries (oldSite is an existing siteDetail)', function () {
Expand Down