Optimize count for TB115

This commit is contained in:
Ximi1970
2023-11-05 22:57:50 +01:00
parent 16c5f5f904
commit 8876045205
2 changed files with 86 additions and 24 deletions

View File

@@ -27,6 +27,7 @@ SysTrayX.Messaging = {
accounts: [],
folderTree: {},
countType: "0",
showNewIndicator: "false",
closeType: "1",
apiCountMethod: "false",
filters: undefined,
@@ -108,6 +109,10 @@ SysTrayX.Messaging = {
const getCountTypePromise = () => new Promise((res) => res(getCountType()));
SysTrayX.Messaging.countType = await getCountTypePromise();
// Get the show new indicator
const getShowNewIndicatorPromise = () => new Promise((res) => res(getShowNewIndicator()));
SysTrayX.Messaging.showNewIndicator = await getShowNewIndicatorPromise();
// Check the filters for the accounts
SysTrayX.Messaging.accountFilterCheck();
@@ -400,6 +405,13 @@ SysTrayX.Messaging = {
sendMailCount();
}
if ("showNewIndicator" in changes && changes["showNewIndicator"].newValue) {
SysTrayX.Messaging.showNewIndicator = changes["showNewIndicator"].newValue;
sendMailCountPre115();
sendMailCount();
}
if ("addonprefchanged" in changes && changes["addonprefchanged"].newValue) {
//
// Send new preferences to the app

View File

@@ -275,12 +275,27 @@ async function getCountType() {
}
function reject() {
return undefined;
return "0";
}
return await storage().get("countType").then(resolve, reject);
}
//
// Get show new indicator
//
async function getShowNewIndicator() {
function resolve(result) {
return result.showNewIndicator || "false";
}
function reject() {
return "false";
}
return await storage().get("showNewIndicator").then(resolve, reject);
}
//
// Get start app parameters
//
@@ -476,37 +491,72 @@ const sendMailCount = async () => {
let unreadCount = 0;
let newCount = 0;
for (const filter of SysTrayX.Messaging.filters) {
for (const path of filter.folders) {
const folder = {
accountId: filter.accountId,
path: path,
};
if( SysTrayX.Messaging.countType === "1" || SysTrayX.Messaging.newIndicator === "true" ) {
async function* listMessages(folder) {
let page = await messenger.messages.list(folder);
for (let message of page.messages) {
yield message;
}
while (page.id) {
page = await messenger.messages.continueList(page.id);
// Get both unread and new message count
for (const filter of SysTrayX.Messaging.filters) {
for (const path of filter.folders) {
const folder = {
accountId: filter.accountId,
path: path,
};
async function* listMessages(folder) {
let page = await messenger.messages.list(folder);
for (let message of page.messages) {
yield message;
}
while (page.id) {
page = await messenger.messages.continueList(page.id);
for (let message of page.messages) {
yield message;
}
}
}
let messages = listMessages(folder);
for await (let message of messages) {
if( message.new )
{
newCount = newCount + 1;
}
if( !message.read )
{
unreadCount = unreadCount + 1;
}
}
}
let messages = listMessages(folder);
for await (let message of messages) {
if( message.new )
{
newCount = newCount + 1;
}
} else {
// Only unread count
for (const filter of SysTrayX.Messaging.filters) {
for (const path of filter.folders) {
const folder = {
accountId: filter.accountId,
path: path,
};
let mailFolderInfo = {};
try {
mailFolderInfo = await browser.folders.getFolderInfo(folder);
} catch (err) {
//console.debug("Filter error: " + err);
//console.debug("Filter error: " + JSON.stringify(folder));
// Get all accounts
SysTrayX.Messaging.accounts = await browser.accounts.list(false);
// Check the filters for the accounts
SysTrayX.Messaging.accountFilterCheck();
}
if( !message.read )
{
unreadCount = unreadCount + 1;
if (mailFolderInfo.unreadMessageCount !== undefined) {
unreadCount = unreadCount + mailFolderInfo.unreadMessageCount;
}
}
}