Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update webview.js to fix issue with popup-message notifications (https://github.com/ferdium/ferdium-app/issues/1675) #604

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions recipes/msteams/webview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
});
};
Loading