Commit 4e97f824 authored by Nicolas Wavrant's avatar Nicolas Wavrant

erp5_web_jabber_client: implement desktop notifications

parent 027fb6a3
Pipeline #12840 failed with stage
in 0 seconds
/*global window, rJS, RSVP, jIO, document, loopEventListener */
/*global window, rJS, RSVP, jIO, Notification, document, loopEventListener */
/*jslint indent: 2, maxerr: 3, nomen: true */
(function (window, rJS, RSVP, jIO, document, loopEventListener) {
(function (window, rJS, RSVP, jIO, Notification, document, loopEventListener) {
"use strict";
var CONNECTION_GADGET_SCOPE = "connection",
CONNECTION_GADGET_URL = "connection/",
JIO_GADGET_URL = "gadget_jio.html";
function dropNotification() {
function dropNotification(gadget) {
var contact;
document.querySelector("link[rel='shortcut icon']").setAttribute("href", "gadget_jabberclient_notification_ok.ico");
for (contact in gadget.state_parameter_dict.notification_per_contact) {
if (gadget.state_parameter_dict.notification_per_contact.hasOwnProperty(contact)) {
gadget.state_parameter_dict.notification_per_contact[contact].close();
delete gadget.state_parameter_dict.notification_per_contact[contact];
}
}
}
function wrapJioCall(gadget, method_name, argument_list) {
......@@ -272,7 +279,8 @@
document.querySelector("link[rel='shortcut icon']").setAttribute("href", "gadget_jabberclient_notification_warning.ico");
}
var gadget = this;
var gadget = this,
from = argument_list[0];
return addLog(this, argument_list[0], argument_list[2], true)
.push(function () {
return initializeContact(gadget, argument_list[0]);
......@@ -281,6 +289,17 @@
doc.notification = true;
return gadget.state_parameter_dict.volatile_jio.put(argument_list[0], doc);
})
.push(function () {
if (!document.hasFocus() && Notification.permission === "granted") {
gadget.state_parameter_dict.notification_per_contact[from] = new Notification(
"New message from " + from,
{
silent: true,
tag: 'jabberclient:' + from
}
);
}
})
.push(function () {
return gadget.refresh();
});
......@@ -361,9 +380,10 @@
connected: false,
server: 'https://mail.nexedi.net/chat/http-bind/',
jio: '',
passwd: ''
passwd: '',
notification_per_contact: {}
};
dropNotification();
dropNotification(gadget);
})
.ready(function (gadget) {
return gadget.getDeclaredGadget('persistent_jio')
......@@ -485,12 +505,16 @@
})
.declareService(function () {
var gadget = this;
function _dropNotification() {
return dropNotification(gadget);
}
return loopEventListener(
window,
'focus',
false,
dropNotification
_dropNotification
);
});
}(window, rJS, RSVP, jIO, document, loopEventListener));
\ No newline at end of file
}(window, rJS, RSVP, jIO, Notification, document, loopEventListener));
\ No newline at end of file
......@@ -236,7 +236,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>967.46266.46579.39065</string> </value>
<value> <string>988.26490.15321.9130</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -254,7 +254,7 @@
</tuple>
<state>
<tuple>
<float>1526979580.7</float>
<float>1606985968.14</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS*/
/*global window, rJS, Notification*/
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS) {
(function (window, rJS, Notification) {
"use strict";
rJS(window)
......@@ -102,7 +102,16 @@
]]
}
});
})
.push(function () {
return gadget.requestNotificationPermission();
});
})
.declareJob("requestNotificationPermission", function () {
if (Notification !== undefined && Notification.permission !== "denied") {
return Notification.requestPermission();
}
});
}(window, rJS));
\ No newline at end of file
}(window, rJS, Notification));
\ No newline at end of file
......@@ -236,7 +236,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>968.4124.44320.51336</string> </value>
<value> <string>988.37813.29181.47069</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -254,7 +254,7 @@
</tuple>
<state>
<tuple>
<float>1528383833.91</float>
<float>1607665366.11</float>
<string>UTC</string>
</tuple>
</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