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

Notifications randomly shown with visible page or not shown with inactive page #3426

Merged
merged 2 commits into from
Feb 12, 2019
Merged
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
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