From 50d4a13aa9406a4cb7c3d074548df8287ae96553 Mon Sep 17 00:00:00 2001 From: typoworx-de Date: Thu, 17 Oct 2024 16:39:56 +0200 Subject: [PATCH] Update webview.js bugfix to merge this fix into official receipe for msteams: https://gist.github.com/tulexx/54df51101366b329cbdcc050f9a9037c discussed in issue https://github.com/ferdium/ferdium-app/issues/1675 --- recipes/msteams/webview.js | 39 +++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/recipes/msteams/webview.js b/recipes/msteams/webview.js index b343196fd..a1bcfcb0f 100644 --- a/recipes/msteams/webview.js +++ b/recipes/msteams/webview.js @@ -4,20 +4,15 @@ function _interopRequireDefault(obj) { const _path = _interopRequireDefault(require('path')); +// Variable to keep previous notification in +let previousNotification = null; + module.exports = Ferdium => { const getMessages = () => { let messages = 0; - - const isTeamsV2 = window.location.href.includes('/v2/'); - - let badges = document.querySelectorAll( + const badges = document.querySelectorAll( '.activity-badge.dot-activity-badge .activity-badge', ); - - if (isTeamsV2) { - badges = document.querySelectorAll('.fui-Badge'); - } - if (badges) { Array.prototype.forEach.call(badges, badge => { messages += Ferdium.safeParseInt(badge.textContent); @@ -38,4 +33,30 @@ module.exports = Ferdium => { Ferdium.injectCSS(_path.default.join(__dirname, 'service.css')); Ferdium.injectJSUnsafe(_path.default.join(__dirname, 'webview-unsafe.js')); + + // Function to handle the double notifications + Ferdium.onNotify(notification => { + // Turn off the need for clicking on the notification, for it to disappear + notification.options.requireInteraction = false; + + if (previousNotification === null) { + // Handle very first notification + previousNotification = notification; + + return notification; + } + + // Updating the previous notification variable + previousNotification = notification; + + if ( + previousNotification.title === notification.title + && previousNotification.options.body === notification.options.body + ) { + // The notification is the same as previous one, so we return null to ensure that it will not show + return null; + } + + return notification; + }); };