1
0
mirror of https://github.com/nerzhul/ocsms.git synced 2025-06-07 07:56:23 +00:00

move notifications handling outside of legacy to dedicated object

This commit is contained in:
Loic Blot 2017-12-28 17:47:05 +01:00
parent 20b77148c7
commit e0a7ad5a3b
No known key found for this signature in database
GPG Key ID: EFAA458E8C153987
3 changed files with 45 additions and 31 deletions

2
js/app.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -386,19 +386,6 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
$scope.lastContactListMsgDate = jsondata["lastRead"]; $scope.lastContactListMsgDate = jsondata["lastRead"];
}; };
$scope.initDesktopNotifies = function () {
if (!("Notification" in window)) {
return;
}
Notification.requestPermission(function (permission) {
if (!('permission' in Notification)) {
Notification.permission = permission;
}
});
};
// Return (int) msgCount, (str) htmlConversation // Return (int) msgCount, (str) htmlConversation
$scope.formatConversation = function (jsondata) { $scope.formatConversation = function (jsondata) {
// Improve jQuery performance // Improve jQuery performance
@ -443,22 +430,7 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
return; return;
} }
if (!("Notification" in window)) { SmsNotifications.notify(msg);
return;
}
else if (Notification.permission === "granted") {
new Notification("Phone Sync - " + msg);
}
else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
if (!('permission' in Notification)) {
Notification.permission = permission;
}
if (permission === "granted") {
new Notification("Phone Sync - " + msg);
}
});
}
}; };
$interval($scope.refreshConversation, 10000); $interval($scope.refreshConversation, 10000);
@ -488,7 +460,7 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
} }
}); });
$scope.fetchInitialSettings(); $scope.fetchInitialSettings();
$scope.initDesktopNotifies(); SmsNotifications.init();
$scope.checkNewMessages(); $scope.checkNewMessages();
}); });
} }

42
js/devel/notifications.js Normal file
View File

@ -0,0 +1,42 @@
/**
* Nextcloud - Phone Sync
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Loic Blot <loic.blot@unix-experience.fr>
* @copyright Loic Blot 2014-2017
*/
var SmsNotifications = {
init: function () {
if (!("Notification" in window)) {
return;
}
Notification.requestPermission(function (permission) {
if (!('permission' in Notification)) {
Notification.permission = permission;
}
});
},
notify: function (message) {
if (!("Notification" in window)) {
return;
}
if (Notification.permission === "granted") {
new Notification("Phone Sync - " + message);
}
else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
if (!('permission' in Notification)) {
Notification.permission = permission;
}
if (permission === "granted") {
new Notification("Phone Sync - " + message);
}
});
}
}
};