Commit ad602133 authored by Vincent Bechu's avatar Vincent Bechu

[erp5_web_jabber_client] Use promise instead synchron code

parent c0b9c034
...@@ -193,6 +193,16 @@ ...@@ -193,6 +193,16 @@
}); });
} }
function createNotification(title, body) {
if (window.Notification !== undefined) {
return window.Notification.requestPermission()
.then(function (result) {
if (result === 'granted') {
return new window.Notification(title, {body: body});
}
});
}
}
rJS(window) rJS(window)
.ready(function (g) { .ready(function (g) {
g.props = {}; g.props = {};
...@@ -265,24 +275,12 @@ ...@@ -265,24 +275,12 @@
.allowPublicAcquisition("notifyXMPPMessageTextReceived", .allowPublicAcquisition("notifyXMPPMessageTextReceived",
function (argument_list) { function (argument_list) {
if (!document.hasFocus()) { if (!document.hasFocus()) {
// Only notify when page has no focused. // Only notify when page has no focused.
// It simplifies a lot notification status // It simplifies a lot notification status
document.querySelector("link[rel='shortcut icon']").setAttribute("href", "gadget_jabberclient_notification_warning.ico"); document.querySelector("link[rel='shortcut icon']").setAttribute("href", "gadget_jabberclient_notification_warning.ico");
if ("Notification" in window) { createNotification(argument_list[0], argument_list[0][2]);
if (Notification.permission === "granted") {
var notification = new Notification(argument_list[0], {body: argument_list[2]});
}
else if (Notification.permission !== "denied") {
Notification.requestPermission(function (permission) {
if (permission === "granted") {
var notification = new Notification(argument_list[0], {body: argument_list[2]});
}
});
}
}
} }
var gadget = this; var gadget = this;
......
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>967.46266.46579.39065</string> </value> <value> <string>970.45900.44706.11212</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -248,7 +248,7 @@ ...@@ -248,7 +248,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1526979580.7</float> <float>1538581284.91</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment