-
-
Notifications
You must be signed in to change notification settings - Fork 827
notification issue fixed #240
Changes from 5 commits
98343a0
1875377
818299d
cbcf23f
349b472
9b5519e
8191eaa
8605ca1
6fc0aae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,6 +123,28 @@ var Notifier = { | |
return global.Notification.permission == 'granted'; | ||
}, | ||
|
||
isPermissionDefault: function() { | ||
if (!this.supportsDesktopNotifications()) return false; | ||
return global.Notification.permission == 'default'; | ||
}, | ||
|
||
// Function to be used by clients to check weather or not to | ||
// show the toolbar. | ||
shouldShowToolbar: function() { | ||
// Check localStorage for any such meta data | ||
if (global.localStorage) { | ||
if (global.localStorage.getItem('notifications_hidden') === 'true') | ||
return false; | ||
} | ||
|
||
// Check if permission is granted by any chance. | ||
if (this.havePermission()) return false; | ||
|
||
// means the permission is blocked | ||
if (!this.isPermissionDefault()) return false; | ||
return true; | ||
}, | ||
|
||
setEnabled: function(enable, callback) { | ||
// make sure that we persist the current setting audio_enabled setting | ||
// before changing anything | ||
|
@@ -133,38 +155,42 @@ var Notifier = { | |
} | ||
|
||
if(enable) { | ||
if (!this.havePermission()) { | ||
global.Notification.requestPermission(function() { | ||
if (callback) { | ||
callback(); | ||
// Case when we do not have the permission as 'granted' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is no longer helpful |
||
if (this.isPermissionDefault()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think there's any need for this test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well yeah normally it would never lead to this, as if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand your answer.
But the point is, you do not need to test for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah that makes more sense :) |
||
// Attempt to get permission from user | ||
var self = this; | ||
global.Notification.requestPermission().then(function(result) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we can rely on our users having browsers which support the promise-returning version of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :O it supported on chrome, but yeah we need to have backward compatibility. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I shall shift this to callback one? I think that MDN doc is little updated, as this is supported in chrome now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I think you might as well use the callback flow. Obviously the MDN doc is outdated, but we don't know which version of Chrome introduced the promise; we don't know if it works in Safari; and using the promise doesn't buy us anything. |
||
if (result === 'denied') { | ||
dis.dispatch({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. still don't think it is necessary to raise an event here |
||
action: "notifier_enabled", | ||
value: true | ||
value: false | ||
}); | ||
self.setToolbarHidden(true, false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. still don't think it is correct to hide the toolbar here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should atleast change the message or remove the link? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm running out of ways to say this: Leave it alone for now, and make it a separate PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, no actions if denied! |
||
return; | ||
} | ||
if (result === 'default') { | ||
// The permission request was dismissed | ||
return; | ||
} | ||
}); | ||
} | ||
|
||
if (!global.localStorage) return; | ||
global.localStorage.setItem('notifications_enabled', 'true'); | ||
if (callback) callback(); | ||
dis.dispatch({ | ||
action: "notifier_enabled", | ||
value: true | ||
}); | ||
|
||
if (this.havePermission) { | ||
dis.dispatch({ | ||
action: "notifier_enabled", | ||
value: true | ||
if (!global.localStorage) return; | ||
global.localStorage.setItem('notifications_enabled', 'true'); | ||
}); | ||
} | ||
} | ||
else { | ||
} else { | ||
if (!global.localStorage) return; | ||
global.localStorage.setItem('notifications_enabled', 'false'); | ||
dis.dispatch({ | ||
action: "notifier_enabled", | ||
value: false | ||
}); | ||
} | ||
|
||
this.setToolbarHidden(false); | ||
}, | ||
|
||
isEnabled: function() { | ||
|
@@ -192,12 +218,23 @@ var Notifier = { | |
return enabled === 'true'; | ||
}, | ||
|
||
setToolbarHidden: function(hidden) { | ||
setToolbarHidden: function(hidden, persistent = true) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
}); | ||
|
||
if (persistent) { | ||
this.setToolbarPersistantHidden(); | ||
} | ||
}, | ||
|
||
setToolbarPersistantHidden: function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/Persistant/Persistent/, but to be honest you might as well inline this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. w/o a function? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes. it's only two lines, and only used in one place. Having a separate function doesn't do much for code clarity. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. still needs inlining |
||
// update the info to localStorage | ||
if (global.localStorage) { | ||
global.localStorage.setItem('notifications_hidden', 'true'); | ||
} | ||
}, | ||
|
||
isToolbarHidden: function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1046,7 +1046,7 @@ module.exports = React.createClass({ | |
if (MatrixClientPeg.get().isGuest()) { | ||
topBar = <GuestWarningBar />; | ||
} | ||
else if (Notifier.supportsDesktopNotifications() && !Notifier.isEnabled() && !Notifier.isToolbarHidden()) { | ||
else if (Notifier.supportsDesktopNotifications() && Notifier.shouldShowToolbar()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this change is necessary. It's clearer to keep |
||
topBar = <MatrixToolbar />; | ||
} | ||
else if (this.state.hasNewVersion) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@richvdh Tell me what do you think about showing a message if the user has blocked notif request & not yet attempted to close the toolbar - if yes, I'll change this method to return enums - 'show', 'hide', 'blocked' and the vector will take decision accordingly.