1
0
mirror of https://github.com/nerzhul/ocsms.git synced 2025-06-08 00:16:24 +00:00

Added support for desktop notifications

This commit is contained in:
Loic Blot 2014-10-10 16:08:59 +00:00
parent 68d8cb40ff
commit b974a946b0

View File

@ -12,6 +12,7 @@
// Some global vars to improve performances // Some global vars to improve performances
var selectedConversation = null; var selectedConversation = null;
var curPhoneNumber = null; var curPhoneNumber = null;
var curContactName = '';
var lastMsgDate = 0; var lastMsgDate = 0;
var unreadCount = 0; var unreadCount = 0;
var originalTitle = document.title; var originalTitle = document.title;
@ -49,6 +50,7 @@ var refreshConversation = function() {
if (document.hasFocus() == false) { if (document.hasFocus() == false) {
unreadCount += fmt[0]; unreadCount += fmt[0];
document.title = originalTitle + " (" + unreadCount + ")"; document.title = originalTitle + " (" + unreadCount + ")";
desktopNotify(unreadCount + " unread message(s) in conversation with " + curContactName);
} }
} }
@ -86,10 +88,12 @@ function fetchConversation(phoneNumber) {
conversationBuf += '<div class="msg-endtag"></div>'; conversationBuf += '<div class="msg-endtag"></div>';
if (typeof jsondata['contactName'] == 'undefined') { if (typeof jsondata['contactName'] == 'undefined') {
$('#ocsms-phone-label').html(phoneNumberLabel); $('#ocsms-phone-label').html(phoneNumberLabel);
curContactName = phoneNumberLabel;
$('#ocsms-phone-opt-number').html(''); $('#ocsms-phone-opt-number').html('');
} }
else { else {
$('#ocsms-phone-label').html(jsondata['contactName']); $('#ocsms-phone-label').html(jsondata['contactName']);
curContactName = jsondata['contactName'];
$('#ocsms-phone-opt-number').html(phoneNumberLabel); $('#ocsms-phone-opt-number').html(phoneNumberLabel);
} }
@ -197,6 +201,33 @@ function fetchInitialPeerList(jsondata) {
} }
} }
function initDesktopNotifies() {
Notification.requestPermission(function (permission) {
if(!('permission' in Notification)) {
Notification.permission = permission;
}
});
}
function desktopNotify(msg) {
if (!("Notification" in window)) {
return;
}
else if (Notification.permission === "granted") {
new Notification("ownCloud SMS - " + msg);
}
else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
if(!('permission' in Notification)) {
Notification.permission = permission;
}
if (permission === "granted") {
new Notification("ownCloud SMS - " + msg);
}
});
}
}
(function ($, OC) { (function ($, OC) {
$(document).ready(function () { $(document).ready(function () {
// Register real title // Register real title
@ -241,6 +272,7 @@ function fetchInitialPeerList(jsondata) {
} }
}); });
initDesktopNotifies();
setInterval(refreshConversation, 10000); setInterval(refreshConversation, 10000);
}); });