Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

notification issue fixed #240

Merged
merged 9 commits into from
Mar 29, 2016
49 changes: 27 additions & 22 deletions src/Notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,38 +133,31 @@ var Notifier = {
}

if(enable) {
if (!this.havePermission()) {
global.Notification.requestPermission(function() {
if (callback) {
callback();
dis.dispatch({
action: "notifier_enabled",
value: true
});
}
});
}

if (!global.localStorage) return;
global.localStorage.setItem('notifications_enabled', 'true');

if (this.havePermission) {
// Case when we do not have the permission as 'granted'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is no longer helpful

// Attempt to get permission from user
global.Notification.requestPermission(function(result) {
if (result !== 'granted') {
// The permission request was dismissed or denied
return;
}

if (callback) callback();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to update the localStorage setting before you run the callback and dispatch the notifier_enabled setting, otherwise things will get confused.

dis.dispatch({
action: "notifier_enabled",
value: true
});
}
}
else {

if (!global.localStorage) return;
global.localStorage.setItem('notifications_enabled', 'true');
});
} else {
if (!global.localStorage) return;
global.localStorage.setItem('notifications_enabled', 'false');
dis.dispatch({
action: "notifier_enabled",
value: false
});
}

this.setToolbarHidden(false);
},

isEnabled: function() {
Expand Down Expand Up @@ -192,15 +185,27 @@ var Notifier = {
return enabled === 'true';
},

setToolbarHidden: function(hidden) {
setToolbarHidden: function(hidden, persistent = true) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just fyi: you may know this already but default parameters are a feature of ES6, which means that we can't use them in some browsers. But it's ok to use in react-sdk because babel translates it for us.

this.toolbarHidden = hidden;
dis.dispatch({
action: "notifier_enabled",
value: this.isEnabled()
});

// update the info to localStorage for persistent settings
if (persistent && global.localStorage) {
global.localStorage.setItem('notifications_hidden', 'true');
}
},

isToolbarHidden: function() {
// Check localStorage for any such meta data
if (global.localStorage) {
if (global.localStorage.getItem('notifications_hidden') === 'true') {
return true;
}
}

return this.toolbarHidden;
},

Expand Down