Enable new new mail for TB91+

This commit is contained in:
Ximi1970
2022-06-19 22:01:58 +02:00
parent f7046205c5
commit 4d2b7f2a62
3 changed files with 110 additions and 58 deletions

View File

@@ -602,7 +602,7 @@ void PreferencesDialog::slotBrowserVersion()
{
QString version = m_pref->getBrowserVersion();
if( version.section( '.', 0, 0 ).toInt() > 89 && version.section( '.', 0, 0 ).toInt() < 102)
if( version.section( '.', 0, 0 ).toInt() > 89 && version.section( '.', 0, 0 ).toInt() < 91)
{
/*
* Hide the count type for TB90 and up, not supported

View File

@@ -22,8 +22,8 @@ SysTrayX.Info = {
SysTrayX.Messaging = {
accounts: [],
folderTree: {},
countType: 0,
closeType: 1,
countType: "0",
closeType: "1",
filters: undefined,
unread: {},
new: {},
@@ -146,7 +146,7 @@ SysTrayX.Messaging = {
SysTrayX.Messaging.listenerFolderDeleted
);
if (SysTrayX.Messaging.countType === 0) {
if (SysTrayX.Messaging.countType === "0") {
// Get the unread count
const getCountUnreadPromise = () =>
new Promise((res) => res(SysTrayX.Messaging.countUnread()));
@@ -164,6 +164,11 @@ SysTrayX.Messaging = {
);
}
// Catch a folder change to reset the new counter
browser.mailTabs.onDisplayedFolderChanged.addListener(
SysTrayX.Window.folderChanged
);
// Try to catch the window state
browser.windows.onFocusChanged.addListener(SysTrayX.Window.focusChanged);
},
@@ -192,7 +197,7 @@ SysTrayX.Messaging = {
);
}
if (SysTrayX.Messaging.countType === 1) {
if (SysTrayX.Messaging.countType === "1") {
let count = 0;
SysTrayX.Messaging.filters.forEach((filter) => {
const accountId = filter.accountId;
@@ -205,6 +210,7 @@ SysTrayX.Messaging = {
});
});
// console.debug("listenerNewMail: New count");
SysTrayX.Link.postSysTrayXMessage({ unreadMail: count });
}
},
@@ -229,18 +235,15 @@ SysTrayX.Messaging = {
deleteFolderFromFilters(deletedFolder);
},
listenerFolderInfoChanged: function (folder, folderInfo) {
console.debug("FolderInfoChanged: " + JSON.stringify(folder));
console.debug("FolderInfoChanged: " + JSON.stringify(folderInfo));
listenerFolderInfoChanged: async function (folder, folderInfo) {
// console.debug("FolderInfoChanged: " + JSON.stringify(folder));
// console.debug("FolderInfoChanged: " + JSON.stringify(folderInfo));
if (folderInfo.unreadMessageCount !== undefined) {
if (SysTrayX.Messaging.unread[folder.accountId] === undefined) {
SysTrayX.Messaging.unread[folder.accountId] = {};
}
SysTrayX.Messaging.unread[folder.accountId][folder.path] =
folderInfo.unreadMessageCount;
if (SysTrayX.Messaging.new[folder.accountId] === undefined) {
SysTrayX.Messaging.new[folder.accountId] = {};
}
@@ -248,9 +251,11 @@ SysTrayX.Messaging = {
if (SysTrayX.Messaging.new[folder.accountId][folder.path] === undefined) {
SysTrayX.Messaging.new[folder.accountId][folder.path] = [];
}
}
if (SysTrayX.Messaging.countType === 0) {
SysTrayX.Messaging.unread[folder.accountId][folder.path] =
folderInfo.unreadMessageCount;
if (SysTrayX.Messaging.countType === "0") {
let count = 0;
SysTrayX.Messaging.filters.forEach((filter) => {
const accountId = filter.accountId;
@@ -263,28 +268,28 @@ SysTrayX.Messaging = {
});
});
// console.debug("listenerFolderInfoChanged: Unread count");
SysTrayX.Link.postSysTrayXMessage({ unreadMail: count });
} else {
// Check if the new mails have been read, remove from new storage
const messages = SysTrayX.Messaging.new[folder.accountId][folder.path];
console.debug("Messages: " + JSON.stringify(messages));
if (messages.length > 0) {
const newMessages = [];
messages.forEach(async (message) => {
console.debug("Message Id: " + message.id);
for (let i = 0; i < messages.length; ++i) {
const message = messages[i];
const header = await browser.messages.get(message.id);
console.debug("Header: " + JSON.stringify(header));
const getHeaderPromise = (messageId) =>
new Promise((res) => res(messenger.messages.get(messageId)));
const header = await getHeaderPromise(message.id);
if (!header.read) {
newMessages.push(message);
}
});
SysTrayX.Messaging.new[folder.accountId][folder.path] = newMessages;
console.debug("New Messages: " + JSON.stringify(newMessages));
}
SysTrayX.Messaging.new[folder.accountId][folder.path] = [
...newMessages,
];
let count = 0;
SysTrayX.Messaging.filters.forEach((filter) => {
@@ -292,14 +297,18 @@ SysTrayX.Messaging = {
filter.folders.forEach((path) => {
if (SysTrayX.Messaging.new[accountId] !== undefined) {
if (SysTrayX.Messaging.new[accountId][path] !== undefined) {
count = count + SysTrayX.Messaging.new[accountId][path].length;
count =
count + SysTrayX.Messaging.new[accountId][path].length;
}
}
});
});
// console.debug("listenerFolderInfoChanged: New count");
SysTrayX.Link.postSysTrayXMessage({ unreadMail: count });
}
}
}
},
countUnread: async function () {
@@ -336,6 +345,7 @@ SysTrayX.Messaging = {
)
);
// console.debug("countUnread: Unread count");
SysTrayX.Link.postSysTrayXMessage({ unreadMail: count });
},
@@ -379,6 +389,7 @@ SysTrayX.Messaging = {
)
);
// console.debug("countNew: New count");
SysTrayX.Link.postSysTrayXMessage({ unreadMail: count });
},
@@ -403,7 +414,7 @@ SysTrayX.Messaging = {
if (SysTrayX.Info.browserInfo.majorVersion < 91) {
browser.folderChange.setFilters(SysTrayX.Messaging.filters);
} else {
if (SysTrayX.Messaging.countType === 0) {
if (SysTrayX.Messaging.countType === "0") {
// Update unread count
const getCountUnreadPromise = () =>
new Promise((res) => res(SysTrayX.Messaging.countUnread()));
@@ -458,6 +469,7 @@ SysTrayX.Messaging = {
// Callback for unReadMessages
//
unreadCb: function (count) {
// console.debug("unreadCb: Unread/New count");
SysTrayX.Link.postSysTrayXMessage({ unreadMail: count });
},
@@ -898,6 +910,46 @@ SysTrayX.Window = {
SysTrayX.Link.postSysTrayXMessage({ window: win.state });
});
},
folderChanged: function (tab, displayedFolder) {
/*
console.debug("Folder changed tab: " + JSON.stringify(tab));
console.debug(
"Folder changed displayFolder: " + JSON.stringify(displayedFolder)
);
*/
// console.debug("New storage: " + JSON.stringify(SysTrayX.Messaging.new));
// Clear all other new items except this one for this account
// to emulate TBs new handling
//
Object.keys(SysTrayX.Messaging.new).forEach((accountId) => {
console.debug("Testing: " + accountId);
if (accountId !== displayedFolder.accountId) {
SysTrayX.Messaging.new[accountId] = undefined;
console.debug("Removed: " + accountId);
}
});
// console.debug("New storage cleaned: " + JSON.stringify(SysTrayX.Messaging.new));
if (SysTrayX.Messaging.countType === "1") {
let count = 0;
SysTrayX.Messaging.filters.forEach((filter) => {
const accountId = filter.accountId;
filter.folders.forEach((path) => {
if (SysTrayX.Messaging.new[accountId] !== undefined) {
if (SysTrayX.Messaging.new[accountId][path] !== undefined) {
count = count + SysTrayX.Messaging.new[accountId][path].length;
}
}
});
});
// console.debug("listenerNewMail: New count");
SysTrayX.Link.postSysTrayXMessage({ unreadMail: count });
}
},
};
async function start() {

View File

@@ -1178,7 +1178,7 @@ async function start() {
SysTrayX.Info.version;
// Disable incompatible items
if (SysTrayX.Info.browserInfo.majorVersion > 89 && SysTrayX.Info.browserInfo.majorVersion < 102) {
if (SysTrayX.Info.browserInfo.majorVersion > 89 && SysTrayX.Info.browserInfo.majorVersion < 91) {
document.getElementById("counttype").style.display = "none";
}