Skip to content

Commit

Permalink
[Bug fix] Notifications randomly shown with visible page or not shown…
Browse files Browse the repository at this point in the history
… with inactive page (#3426)
  • Loading branch information
kravets-levko authored Feb 12, 2019
1 parent 4dbc175 commit d567765
Showing 1 changed file with 3 additions and 19 deletions.
22 changes: 3 additions & 19 deletions client/app/services/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,11 @@ const hidden = find(
['hidden', 'webkitHidden', 'mozHidden', 'msHidden'],
prop => prop in document,
);
const visibilityChange = find(
['visibilitychange', 'webkitvisibilitychange', 'mozvisibilitychange', 'msvisibilitychange'],
prop => prop in document,
);

class NotificationsService {
constructor() {
this.pageVisible = false;
this.monitorVisibility();
// eslint-disable-next-line class-methods-use-this
get pageVisible() {
return !document[hidden];
}

// eslint-disable-next-line class-methods-use-this
Expand All @@ -35,18 +31,6 @@ class NotificationsService {
}
}

monitorVisibility() {
this.pageVisible = !document[hidden];
let documentHidden = document[hidden];

document.addEventListener(visibilityChange, () => {
if (documentHidden !== document[hidden]) {
this.pageVisible = !document[hidden];
documentHidden = document[hidden];
}
});
}

showNotification(title, content) {
if (!Notification || this.pageVisible || (Notification.permission !== 'granted')) {
return;
Expand Down

0 comments on commit d567765

Please sign in to comment.