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; + }); };