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

Commit

Permalink
Removes history and bookmarks when they are removed from suggestions
Browse files Browse the repository at this point in the history
Resolves #9736

Auditors:

Test Plan:
  • Loading branch information
NejcZdovc committed Sep 5, 2017
1 parent 862b896 commit d799cf1
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
3 changes: 3 additions & 0 deletions app/browser/reducers/historyReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const messages = require('../../../js/constants/messages')

// Utils
const {makeImmutable} = require('../../common/state/immutableUtil')
const {remove} = require('../../common/lib/siteSuggestions')
const syncUtil = require('../../../js/state/syncUtil')
const filtering = require('../../filtering')
const {calculateTopSites} = require('../api/topSites')
Expand Down Expand Up @@ -43,6 +44,8 @@ const historyReducer = (state, action, immutableAction) => {
const temp = state.get('tempClearBrowsingData', Immutable.Map())
const clearData = defaults ? defaults.merge(temp) : temp
if (clearData.get('browserHistory')) {
const historySites = historyState.getSites(state).toList()
remove(historySites)
state = historyState.clearSites(state)
state = aboutHistoryState.clearHistory(state)
filtering.clearHistory()
Expand Down
41 changes: 40 additions & 1 deletion app/browser/reducers/urlBarSuggestionsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
const Immutable = require('immutable')
const appConstants = require('../../../js/constants/appConstants')
const {generateNewSuggestionsList, generateNewSearchXHRResults} = require('../../common/lib/suggestion')
const {init, add} = require('../../common/lib/siteSuggestions')
const {init, add, remove} = require('../../common/lib/siteSuggestions')
const {makeImmutable} = require('../../common/state/immutableUtil')
const tabState = require('../../common/state/tabState')
const historyState = require('../../common/state/historyState')
Expand All @@ -26,6 +26,45 @@ const urlBarSuggestionsReducer = (state, action) => {
add(makeImmutable(action.siteDetail))
}
break
case appConstants.APP_REMOVE_BOOKMARK:
{
const bookmarkKey = action.bookmarkKey
if (bookmarkKey == null) {
break
}

let data = null
if (Immutable.List.isList(bookmarkKey)) {
data = bookmarkKey.map((key) => bookmarksState.getBookmark(state, key)).toList()
} else {
data = bookmarksState.getBookmark(state, bookmarkKey)
}

if (data != null) {
remove(data)
}
break
}

case appConstants.APP_REMOVE_HISTORY_SITE:
{
const historyKey = action.historyKey
if (historyKey == null) {
break
}

let data = null
if (Immutable.List.isList(historyKey)) {
data = historyKey.map((key) => historyState.getSite(state, key)).toList()
} else {
data = historyState.getSite(state, historyKey)
}

if (data != null) {
remove(data)
}
break
}
case appConstants.APP_SET_STATE:
const bookmarks = bookmarksState.getBookmarks(action.appState)
const history = historyState.getSites(action.appState)
Expand Down
10 changes: 9 additions & 1 deletion app/common/lib/siteSuggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ const add = (data) => {
engine.add(data.toJS ? data : Immutable.fromJS(data))
}

const remove = (data) => {
if (!initialized) {
return
}
engine.remove(data.toJS ? data : Immutable.fromJS(data))
}

const query = (input, options = {}) => {
if (!initialized) {
return Promise.resolve([])
Expand Down Expand Up @@ -163,5 +170,6 @@ module.exports = {
init,
add,
tokenizeInput,
query
query,
remove
}
2 changes: 1 addition & 1 deletion js/stores/appStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,14 @@ const handleAppAction = (action) => {
// until we have a better way to manage dependencies.
// tabsReducer must be above dragDropReducer.
require('../../app/browser/reducers/tabsReducer'),
require('../../app/browser/reducers/urlBarSuggestionsReducer'),
require('../../app/browser/reducers/bookmarksReducer'),
require('../../app/browser/reducers/bookmarkFoldersReducer'),
require('../../app/browser/reducers/historyReducer'),
require('../../app/browser/reducers/pinnedSitesReducer'),
require('../../app/browser/reducers/windowsReducer'),
require('../../app/browser/reducers/syncReducer'),
require('../../app/browser/reducers/clipboardReducer'),
require('../../app/browser/reducers/urlBarSuggestionsReducer'),
require('../../app/browser/reducers/passwordManagerReducer'),
require('../../app/browser/reducers/spellCheckerReducer'),
require('../../app/browser/reducers/tabMessageBoxReducer'),
Expand Down

0 comments on commit d799cf1

Please sign in to comment.