Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
zachmann committed May 24, 2024
1 parent 29cdc00 commit d4d0c68
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions internal/server/web/static/js/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,28 @@ $(function () {
})

function listNotifications(...next) {
let notificationIterator = function (n) {
notificationsMap[n["management_code"]] = n;
if (n["user_wide"]) {
addToArrayMap(momIDNotificationsMap, "user", n, (a, b) => a["notification_id"] === b["notification_id"])
} else {
let tokens = n["subscribed_tokens"];
if (tokens !== undefined) {
tokens.forEach(momid => {
addToArrayMap(momIDNotificationsMap, momid, n, (a, b) => a["notification_id"] === b["notification_id"])
});
}
}
};

$.ajax({
type: "GET",
url: storageGet('notifications_endpoint'),
success: function (res) {
let notifications = res["notifications"] || [];
notificationsMap = {};
momIDNotificationsMap = {};
notifications.forEach(function (n) {
notificationsMap[n["management_code"]] = n;
if (n["user_wide"]) {
addToArrayMap(momIDNotificationsMap, "user", n, (a, b) => a["notification_id"] === b["notification_id"])
} else {
let tokens = n["subscribed_tokens"];
if (tokens !== undefined) {
tokens.forEach(function (momid) {
addToArrayMap(momIDNotificationsMap, momid, n, (a, b) => a["notification_id"] === b["notification_id"])
});
}
}
})
notifications.forEach(notificationIterator);
$('#notifications-msg').html(notificationsToTable(notifications, true, n => `<button class="btn" type="button" onclick="showDeleteNotificationModal('${n["management_code"]}')" data-toggle="tooltip" data-placement="right" data-original-title="Delete Notification"><i class="fas fa-trash"></i></button>`));
$('[data-toggle="tooltip"]').tooltip();
doNext(...next);
Expand Down Expand Up @@ -617,7 +619,7 @@ function getCalendars(callback = undefined, ...next) {
let cals = res["calendars"] || [];
cals.forEach(function (c) {
let tokens = c["subscribed_tokens"] || [];
tokens.forEach(function (momid) {
tokens.forEach(momid => {
addToArrayMap(momIDCalendarsMap, momid, c, (a, b) => a["ics_path"] === b["ics_path"])
});
calendarURLs[c["name"]] = c["ics_path"];
Expand Down

0 comments on commit d4d0c68

Please sign in to comment.