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(); 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 * Hide the count type for TB90 and up, not supported

View File

@@ -22,8 +22,8 @@ SysTrayX.Info = {
SysTrayX.Messaging = { SysTrayX.Messaging = {
accounts: [], accounts: [],
folderTree: {}, folderTree: {},
countType: 0, countType: "0",
closeType: 1, closeType: "1",
filters: undefined, filters: undefined,
unread: {}, unread: {},
new: {}, new: {},
@@ -146,7 +146,7 @@ SysTrayX.Messaging = {
SysTrayX.Messaging.listenerFolderDeleted SysTrayX.Messaging.listenerFolderDeleted
); );
if (SysTrayX.Messaging.countType === 0) { if (SysTrayX.Messaging.countType === "0") {
// Get the unread count // Get the unread count
const getCountUnreadPromise = () => const getCountUnreadPromise = () =>
new Promise((res) => res(SysTrayX.Messaging.countUnread())); 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 // Try to catch the window state
browser.windows.onFocusChanged.addListener(SysTrayX.Window.focusChanged); 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; let count = 0;
SysTrayX.Messaging.filters.forEach((filter) => { SysTrayX.Messaging.filters.forEach((filter) => {
const accountId = filter.accountId; const accountId = filter.accountId;
@@ -205,6 +210,7 @@ SysTrayX.Messaging = {
}); });
}); });
// console.debug("listenerNewMail: New count");
SysTrayX.Link.postSysTrayXMessage({ unreadMail: count }); SysTrayX.Link.postSysTrayXMessage({ unreadMail: count });
} }
}, },
@@ -229,18 +235,15 @@ SysTrayX.Messaging = {
deleteFolderFromFilters(deletedFolder); deleteFolderFromFilters(deletedFolder);
}, },
listenerFolderInfoChanged: function (folder, folderInfo) { listenerFolderInfoChanged: async function (folder, folderInfo) {
console.debug("FolderInfoChanged: " + JSON.stringify(folder)); // console.debug("FolderInfoChanged: " + JSON.stringify(folder));
console.debug("FolderInfoChanged: " + JSON.stringify(folderInfo)); // console.debug("FolderInfoChanged: " + JSON.stringify(folderInfo));
if (folderInfo.unreadMessageCount !== undefined) { if (folderInfo.unreadMessageCount !== undefined) {
if (SysTrayX.Messaging.unread[folder.accountId] === undefined) { if (SysTrayX.Messaging.unread[folder.accountId] === undefined) {
SysTrayX.Messaging.unread[folder.accountId] = {}; SysTrayX.Messaging.unread[folder.accountId] = {};
} }
SysTrayX.Messaging.unread[folder.accountId][folder.path] =
folderInfo.unreadMessageCount;
if (SysTrayX.Messaging.new[folder.accountId] === undefined) { if (SysTrayX.Messaging.new[folder.accountId] === undefined) {
SysTrayX.Messaging.new[folder.accountId] = {}; SysTrayX.Messaging.new[folder.accountId] = {};
} }
@@ -248,57 +251,63 @@ SysTrayX.Messaging = {
if (SysTrayX.Messaging.new[folder.accountId][folder.path] === undefined) { if (SysTrayX.Messaging.new[folder.accountId][folder.path] === undefined) {
SysTrayX.Messaging.new[folder.accountId][folder.path] = []; SysTrayX.Messaging.new[folder.accountId][folder.path] = [];
} }
}
if (SysTrayX.Messaging.countType === 0) { SysTrayX.Messaging.unread[folder.accountId][folder.path] =
let count = 0; folderInfo.unreadMessageCount;
SysTrayX.Messaging.filters.forEach((filter) => {
const accountId = filter.accountId; if (SysTrayX.Messaging.countType === "0") {
filter.folders.forEach((path) => { let count = 0;
if (SysTrayX.Messaging.unread[accountId] !== undefined) { SysTrayX.Messaging.filters.forEach((filter) => {
if (SysTrayX.Messaging.unread[accountId][path] !== undefined) { const accountId = filter.accountId;
count = count + SysTrayX.Messaging.unread[accountId][path]; filter.folders.forEach((path) => {
if (SysTrayX.Messaging.unread[accountId] !== undefined) {
if (SysTrayX.Messaging.unread[accountId][path] !== undefined) {
count = count + SysTrayX.Messaging.unread[accountId][path];
}
}
});
});
// 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];
if (messages.length > 0) {
const newMessages = [];
for (let i = 0; i < messages.length; ++i) {
const message = messages[i];
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,
];
SysTrayX.Link.postSysTrayXMessage({ unreadMail: count }); let count = 0;
} else { SysTrayX.Messaging.filters.forEach((filter) => {
// Check if the new mails have been read, remove from new storage const accountId = filter.accountId;
const messages = SysTrayX.Messaging.new[folder.accountId][folder.path]; 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("Messages: " + JSON.stringify(messages)); // console.debug("listenerFolderInfoChanged: New count");
SysTrayX.Link.postSysTrayXMessage({ unreadMail: count });
const newMessages = [];
messages.forEach(async (message) => {
console.debug("Message Id: " + message.id);
const header = await browser.messages.get(message.id);
console.debug("Header: " + JSON.stringify(header));
if (!header.read) {
newMessages.push(message);
} }
}); }
SysTrayX.Messaging.new[folder.accountId][folder.path] = newMessages;
console.debug("New Messages: " + JSON.stringify(newMessages));
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;
}
}
});
});
SysTrayX.Link.postSysTrayXMessage({ unreadMail: count });
} }
}, },
@@ -336,6 +345,7 @@ SysTrayX.Messaging = {
) )
); );
// console.debug("countUnread: Unread count");
SysTrayX.Link.postSysTrayXMessage({ unreadMail: count }); SysTrayX.Link.postSysTrayXMessage({ unreadMail: count });
}, },
@@ -379,6 +389,7 @@ SysTrayX.Messaging = {
) )
); );
// console.debug("countNew: New count");
SysTrayX.Link.postSysTrayXMessage({ unreadMail: count }); SysTrayX.Link.postSysTrayXMessage({ unreadMail: count });
}, },
@@ -403,7 +414,7 @@ SysTrayX.Messaging = {
if (SysTrayX.Info.browserInfo.majorVersion < 91) { if (SysTrayX.Info.browserInfo.majorVersion < 91) {
browser.folderChange.setFilters(SysTrayX.Messaging.filters); browser.folderChange.setFilters(SysTrayX.Messaging.filters);
} else { } else {
if (SysTrayX.Messaging.countType === 0) { if (SysTrayX.Messaging.countType === "0") {
// Update unread count // Update unread count
const getCountUnreadPromise = () => const getCountUnreadPromise = () =>
new Promise((res) => res(SysTrayX.Messaging.countUnread())); new Promise((res) => res(SysTrayX.Messaging.countUnread()));
@@ -458,6 +469,7 @@ SysTrayX.Messaging = {
// Callback for unReadMessages // Callback for unReadMessages
// //
unreadCb: function (count) { unreadCb: function (count) {
// console.debug("unreadCb: Unread/New count");
SysTrayX.Link.postSysTrayXMessage({ unreadMail: count }); SysTrayX.Link.postSysTrayXMessage({ unreadMail: count });
}, },
@@ -898,6 +910,46 @@ SysTrayX.Window = {
SysTrayX.Link.postSysTrayXMessage({ window: win.state }); 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() { async function start() {

View File

@@ -1178,7 +1178,7 @@ async function start() {
SysTrayX.Info.version; SysTrayX.Info.version;
// Disable incompatible items // 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"; document.getElementById("counttype").style.display = "none";
} }