mirror of
https://github.com/Ximi1970/systray-x.git
synced 2025-11-10 23:36:08 +01:00
Cleanup
This commit is contained in:
@@ -92,39 +92,58 @@ function checkFilters(filters) {
|
|||||||
|
|
||||||
if (filters === undefined) {
|
if (filters === undefined) {
|
||||||
// Create base filters
|
// Create base filters
|
||||||
|
newFilters = [];
|
||||||
|
for (const account of SysTrayX.Messaging.accounts) {
|
||||||
|
const inbox = account.folders.filter((folder) => folder.type == "inbox");
|
||||||
|
|
||||||
|
if (inbox.length > 0) {
|
||||||
|
let folder = { ...inbox[0], accountName: account.name };
|
||||||
|
delete folder.type;
|
||||||
|
delete folder.subFolders;
|
||||||
|
|
||||||
|
newFilters.push({
|
||||||
|
unread: true,
|
||||||
|
folder: folder,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Store the converted filters
|
||||||
|
//
|
||||||
|
browser.storage.sync.set({
|
||||||
|
filters: newFilters,
|
||||||
|
});
|
||||||
} else if (filters.length > 0) {
|
} else if (filters.length > 0) {
|
||||||
// Check the format
|
// Check the format
|
||||||
if (filters[0].folder.accountName === undefined) {
|
if (filters[0].folder.accountName === undefined) {
|
||||||
// Old format, convert
|
// Old format, convert
|
||||||
console.debug("Converting filters....");
|
|
||||||
console.debug("Old filters: " + JSON.stringify(filters));
|
console.log("Converting old filters");
|
||||||
console.debug("Accounts: " + JSON.stringify(SysTrayX.Messaging.accounts));
|
|
||||||
|
|
||||||
accountNames = {};
|
accountNames = {};
|
||||||
for (const account of SysTrayX.Messaging.accounts) {
|
for (const account of SysTrayX.Messaging.accounts) {
|
||||||
accountNames[account.id] = account.name;
|
accountNames[account.id] = account.name;
|
||||||
}
|
}
|
||||||
console.debug("AccountNames: " + JSON.stringify(accountNames));
|
|
||||||
|
|
||||||
function findFolder(accountId, path) {
|
function findFolder(accountId, path) {
|
||||||
const account = SysTrayX.Messaging.accounts.filter(
|
const account = SysTrayX.Messaging.accounts.filter(
|
||||||
(account) => account.id === accountId
|
(account) => account.id === accountId
|
||||||
);
|
);
|
||||||
|
|
||||||
console.debug(
|
|
||||||
"Account scanning: " + accountId + ": " + JSON.stringify(account)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (SysTrayX.browserInfo.version.split(".")[0] < 74) {
|
if (SysTrayX.browserInfo.version.split(".")[0] < 74) {
|
||||||
|
//
|
||||||
|
// Search the pre TB74 account structure
|
||||||
|
//
|
||||||
const folder = account[0].folders.filter(
|
const folder = account[0].folders.filter(
|
||||||
(folder) => folder.path === path
|
(folder) => folder.path === path
|
||||||
);
|
);
|
||||||
|
|
||||||
const folders = account[0].folders.filter((folder) =>
|
const folders = account[0].folders.filter((folder) =>
|
||||||
folder.pathstartsWith(path)
|
folder.path.startsWith(path)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (folders.length > 0) {
|
if (folders.length > 1) {
|
||||||
return "^ Add base folder";
|
return "^ Add base folder";
|
||||||
} else {
|
} else {
|
||||||
return folder[0].name;
|
return folder[0].name;
|
||||||
@@ -164,55 +183,12 @@ function checkFilters(filters) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
//
|
||||||
newFilters.foreach((filter) => {
|
// Store the converted filters
|
||||||
filter.folder.accountName = accountNames[filter.accountId];
|
//
|
||||||
});
|
|
||||||
*/
|
|
||||||
|
|
||||||
console.debug("New filters: " + JSON.stringify(newFilters));
|
|
||||||
|
|
||||||
/*
|
|
||||||
let folderArrays = {};
|
|
||||||
SysTrayX.Messaging.accounts.foreach((account) => {
|
|
||||||
if (SysTrayX.browserInfo.version.split(".")[0] < 74) {
|
|
||||||
// Pre TB74 accounts API
|
|
||||||
folderArrays[account.id] = account.folders;
|
|
||||||
} else {
|
|
||||||
// TB74+ accounts API, (this shit never ends...)
|
|
||||||
let folderArray = [];
|
|
||||||
|
|
||||||
function traverse(folders) {
|
|
||||||
if (!folders) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (let f of folders) {
|
|
||||||
arrayOfFolders.push(f);
|
|
||||||
traverse(f.subFolders);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
traverse(account.folders);
|
|
||||||
|
|
||||||
folderArrays[account.id] = folderArray;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
console.debug("FolderArrays: " + JSON.stringify(folderArrays));
|
|
||||||
*/
|
|
||||||
|
|
||||||
// accountName: accountName,
|
|
||||||
// name: folder.name,
|
|
||||||
// Special: "name":"^ Add base folder"
|
|
||||||
// TB74+ check for subfolders var,
|
|
||||||
// before TB75 scan all folders for substring in path?
|
|
||||||
|
|
||||||
// Store extended query filters
|
|
||||||
/*
|
|
||||||
browser.storage.sync.set({
|
browser.storage.sync.set({
|
||||||
filters: newFilters,
|
filters: newFilters,
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,8 +40,6 @@ SysTrayX.SaveOptions = {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
console.debug("Filters: " + JSON.stringify(filters));
|
|
||||||
|
|
||||||
// Store extended query filters
|
// Store extended query filters
|
||||||
browser.storage.sync.set({
|
browser.storage.sync.set({
|
||||||
filters: filters,
|
filters: filters,
|
||||||
|
|||||||
Reference in New Issue
Block a user