|
|
@ -4,8 +4,8 @@
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getNotifications(callback) {
|
|
|
|
function displayNotifications(callback) {
|
|
|
|
var notifications = [];
|
|
|
|
$.post(localStorage.getItem("syncurl"), {
|
|
|
|
$.post(localStorage.getItem("syncurl"), {
|
|
|
|
username: localStorage.getItem("username"),
|
|
|
|
username: localStorage.getItem("username"),
|
|
|
|
key: localStorage.getItem("key"),
|
|
|
|
key: localStorage.getItem("key"),
|
|
|
@ -14,30 +14,76 @@ function displayNotifications(callback) {
|
|
|
|
if (data.status === 'OK') {
|
|
|
|
if (data.status === 'OK') {
|
|
|
|
for (var i = 0; i < data.notifications.length; i++) {
|
|
|
|
for (var i = 0; i < data.notifications.length; i++) {
|
|
|
|
var n = data.notifications[i];
|
|
|
|
var n = data.notifications[i];
|
|
|
|
|
|
|
|
notifications.push({
|
|
|
|
|
|
|
|
id: n.id,
|
|
|
|
|
|
|
|
title: n.title,
|
|
|
|
|
|
|
|
text: n.content,
|
|
|
|
|
|
|
|
sensitive: n.sensitive,
|
|
|
|
|
|
|
|
seen: n.seen
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
callback(notifications);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof callback == 'function') {
|
|
|
|
|
|
|
|
callback(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, "json").fail(function () {
|
|
|
|
|
|
|
|
if (typeof callback == 'function') {
|
|
|
|
|
|
|
|
callback(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function displayNotifications(callback) {
|
|
|
|
|
|
|
|
getNotifications(function (notifications) {
|
|
|
|
|
|
|
|
if (notifications != false) {
|
|
|
|
|
|
|
|
for (var i = 0; i < notifications.length; i++) {
|
|
|
|
|
|
|
|
var n = notifications[i];
|
|
|
|
if (n.seen || shown_notifications.includes(n.id)) {
|
|
|
|
if (n.seen || shown_notifications.includes(n.id)) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cordova.plugins.notification.local.schedule([{
|
|
|
|
cordova.plugins.notification.local.schedule([{
|
|
|
|
title: n.title,
|
|
|
|
title: n.title,
|
|
|
|
text: n.content,
|
|
|
|
text: n.text,
|
|
|
|
actions: [
|
|
|
|
// actions: [
|
|
|
|
{id: 'mark_read', title: "Mark Read"}
|
|
|
|
// {id: 'mark_read', title: "Mark Read"}
|
|
|
|
],
|
|
|
|
// ],
|
|
|
|
id: n.id,
|
|
|
|
id: n.id,
|
|
|
|
lockscreen: !n.sensitive
|
|
|
|
lockscreen: !n.sensitive
|
|
|
|
}]);
|
|
|
|
}]);
|
|
|
|
|
|
|
|
|
|
|
|
shown_notifications.push(n.id);
|
|
|
|
shown_notifications.push(n.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof callback == 'function') {
|
|
|
|
|
|
|
|
callback();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (typeof callback == 'function') {
|
|
|
|
if (typeof callback == 'function') {
|
|
|
|
callback();
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, "json").fail(function () {
|
|
|
|
});
|
|
|
|
if (typeof callback == 'function') {
|
|
|
|
}
|
|
|
|
callback();
|
|
|
|
|
|
|
|
}
|
|
|
|
function deleteNotification(id) {
|
|
|
|
|
|
|
|
$.post(localStorage.getItem("syncurl"), {
|
|
|
|
|
|
|
|
username: localStorage.getItem("username"),
|
|
|
|
|
|
|
|
key: localStorage.getItem("key"),
|
|
|
|
|
|
|
|
password: localStorage.getItem("password"),
|
|
|
|
|
|
|
|
action: "deletenotification",
|
|
|
|
|
|
|
|
id: id
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function readNotification(id) {
|
|
|
|
|
|
|
|
$.post(localStorage.getItem("syncurl"), {
|
|
|
|
|
|
|
|
username: localStorage.getItem("username"),
|
|
|
|
|
|
|
|
key: localStorage.getItem("key"),
|
|
|
|
|
|
|
|
password: localStorage.getItem("password"),
|
|
|
|
|
|
|
|
action: "readnotification",
|
|
|
|
|
|
|
|
id: id
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|