auto-convert removed stock list into an imported list

This commit is contained in:
gorhill 2017-07-03 09:08:46 -04:00
parent 07ef347734
commit 20346ef0ed
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 31 additions and 1 deletions

View File

@ -467,7 +467,7 @@
listKey = importedListKeys[i];
entry = {
content: 'filters',
contentURL: importedListKeys[i],
contentURL: listKey,
external: true,
group: 'custom',
submitter: 'user',
@ -477,6 +477,31 @@
this.assets.registerAssetSource(listKey, entry);
}
// Convert a no longer existing stock list into an imported list.
var customListFromStockList = function(assetKey) {
var oldEntry = oldAvailableLists[assetKey];
if ( oldEntry === undefined || oldEntry.off === true ) { return; }
var listURL = oldEntry.contentURL;
if ( Array.isArray(listURL) ) {
listURL = listURL[0];
}
var newEntry = {
content: 'filters',
contentURL: listURL,
external: true,
group: 'custom',
submitter: 'user',
title: oldEntry.title || ''
};
newAvailableLists[listURL] = newEntry;
µb.assets.registerAssetSource(listURL, newEntry);
importedListKeys.push(listURL);
µb.userSettings.externalLists += '\n' + listURL;
µb.userSettings.externalLists = µb.userSettings.externalLists.trim();
vAPI.storage.set({ externalLists: µb.userSettings.externalLists });
µb.saveSelectedFilterLists([ listURL ], true);
};
// Final steps:
// - reuse existing list metadata if any;
// - unregister unreferenced imported filter lists if any.
@ -487,8 +512,13 @@
for ( assetKey in oldAvailableLists ) {
oldEntry = oldAvailableLists[assetKey];
newEntry = newAvailableLists[assetKey];
// List no longer exists. If a stock list, try to convert to
// imported list if it was selected.
if ( newEntry === undefined ) {
µb.removeFilterList(assetKey);
if ( assetKey.indexOf('://') === -1 ) {
customListFromStockList(assetKey);
}
continue;
}
if ( oldEntry.entryCount !== undefined ) {