From 41d9e8e7c114a760131370ed78923cb10768a488 Mon Sep 17 00:00:00 2001 From: Ximi1970 Date: Tue, 8 Dec 2020 21:32:23 +0100 Subject: [PATCH 1/2] Make some filters languages dependent --- webext/js/defaults.js | 58 ++++++++++++++++++++++++++++++++- webext/js/options_accounts.js | 2 ++ webext/schema_folderchange.json | 3 ++ 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/webext/js/defaults.js b/webext/js/defaults.js index d94b998..5715675 100644 --- a/webext/js/defaults.js +++ b/webext/js/defaults.js @@ -228,6 +228,7 @@ function createFoldersArrayPre74(baseFolders) { r.result.push({ accountId: folder.accountId, name: folder.name, + type: folder.type, path: folder.path, subFolders: r[name].result, }); @@ -288,13 +289,45 @@ function checkFolderFilters(filters) { const found = accountFolders[filter.folder.accountId].filter((folder) => { if (filter.folder.version) { - return folder.path === filter.folder.path; + const folderPaths = folder.path.split("/"); + const folderPathLast = folderPaths.pop(); + const folderPathFirst = folderPaths.join("/"); + + const filterFolderPaths = filter.folder.path.split("/"); + const filterFolderPathLast = filterFolderPaths.pop(); + const filterFolderPathFirst = filterFolderPaths.join("/"); + + if ( + folderPathFirst === filterFolderPathFirst && + folderPathLast !== filterFolderPathLast && + ((folder.type === "inbox" && filter.folder.type === "inbox") || + (folder.type === "trash" && filter.folder.type === "trash") || + (folder.type === "drafts" && filter.folder.type === "drafts") || + (folder.type === "outbox" && filter.folder.type === "outbox")) + ) { + filter.folder.path = folder.path; + filter.folder.name = folder.name; + filtersChanged = true; + return true; + } + + if (folder.path === filter.folder.path) { + if (folder.type != filter.folder.type && filter.folder.type == undefined ) { + filter.folder.type = folder.type !== undefined ? folder.type : ""; + filtersChanged = true; + } + return true; + } + + return false; } else { return folder.pathOrig === filter.folder.path; } }); if (found.length === 0) { + console.debug("Removed filter: " + JSON.stringify(filter)); + filtersChanged = true; continue; } @@ -329,9 +362,32 @@ function checkFolderFilters(filters) { function checkFilters(filters) { let newFilters = []; + console.debug( + "Current accounts: " + JSON.stringify(SysTrayX.Messaging.accounts) + ); + if (filters === undefined) { // Create base filters for (const account of SysTrayX.Messaging.accounts) { + /* + // + // Display specials + // + accountFolders = []; + if (SysTrayX.browserInfo.version.split(".")[0] < 74) { + // Pre TB74 accounts API + accountFolders = createFoldersArrayPre74(account.folders); + } else { + // TB74+ accounts API + accountFolders = createFoldersArray(account.folders); + } + + const specials = accountFolders.filter( + (folder) => folder.type != undefined + ); + console.debug("Special folders: " + JSON.stringify(specials)); +*/ + const inbox = account.folders.filter((folder) => folder.type == "inbox"); if (inbox.length > 0) { diff --git a/webext/js/options_accounts.js b/webext/js/options_accounts.js index 74620ca..070ad2f 100644 --- a/webext/js/options_accounts.js +++ b/webext/js/options_accounts.js @@ -39,6 +39,7 @@ SysTrayX.Accounts = { r.result.push({ accountId: folder.accountId, name: folder.name, + type: folder.type, subFolders: r[name].result, }); } @@ -196,6 +197,7 @@ SysTrayX.Accounts = { JSON.stringify({ accountName: element.accountName, accountId: element.accountId, + type: element.type != undefined ? element.type : "", path: element.path, name: element.path.split("/").pop(), version: SysTrayX.version, diff --git a/webext/schema_folderchange.json b/webext/schema_folderchange.json index 48f57dd..470c9e7 100644 --- a/webext/schema_folderchange.json +++ b/webext/schema_folderchange.json @@ -43,6 +43,9 @@ "name": { "type": "string" }, + "type": { + "type": "string" + }, "path": { "type": "string" }, From de5251e3b5a1c1d96dcd06fd8ed07966bd6bbb30 Mon Sep 17 00:00:00 2001 From: Ximi1970 Date: Tue, 8 Dec 2020 21:59:02 +0100 Subject: [PATCH 2/2] Add all the types --- webext/js/defaults.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/webext/js/defaults.js b/webext/js/defaults.js index 5715675..2a9e349 100644 --- a/webext/js/defaults.js +++ b/webext/js/defaults.js @@ -301,8 +301,13 @@ function checkFolderFilters(filters) { folderPathFirst === filterFolderPathFirst && folderPathLast !== filterFolderPathLast && ((folder.type === "inbox" && filter.folder.type === "inbox") || - (folder.type === "trash" && filter.folder.type === "trash") || (folder.type === "drafts" && filter.folder.type === "drafts") || + (folder.type === "sent" && filter.folder.type === "sent") || + (folder.type === "trash" && filter.folder.type === "trash") || + (folder.type === "templates" && + filter.folder.type === "templates") || + (folder.type === "archives" && filter.folder.type === "archives") || + (folder.type === "junk" && filter.folder.type === "junk") || (folder.type === "outbox" && filter.folder.type === "outbox")) ) { filter.folder.path = folder.path; @@ -312,7 +317,10 @@ function checkFolderFilters(filters) { } if (folder.path === filter.folder.path) { - if (folder.type != filter.folder.type && filter.folder.type == undefined ) { + if ( + folder.type != filter.folder.type && + filter.folder.type == undefined + ) { filter.folder.type = folder.type !== undefined ? folder.type : ""; filtersChanged = true; }