From 8bf9b9bef9a36961102801cc1ca32ea0296f2288 Mon Sep 17 00:00:00 2001 From: krukle Date: Tue, 12 Jul 2022 14:35:04 +0200 Subject: [PATCH] Add possibility to fetch calendars through socket notifications --- modules/default/calendar/calendar.js | 4 ++++ modules/default/calendar/node_helper.js | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/modules/default/calendar/calendar.js b/modules/default/calendar/calendar.js index 34d720d3..ec137d26 100644 --- a/modules/default/calendar/calendar.js +++ b/modules/default/calendar/calendar.js @@ -133,6 +133,10 @@ Module.register("calendar", { // Override socket notification handler. socketNotificationReceived: function (notification, payload) { + if (notification === "FETCH_CALENDAR") { + this.sendSocketNotification(notification, {"url": payload.url, "id": this.identifier}) + } + if (this.identifier !== payload.id) { return; } diff --git a/modules/default/calendar/node_helper.js b/modules/default/calendar/node_helper.js index 21fa7e0e..e98e7b4d 100644 --- a/modules/default/calendar/node_helper.js +++ b/modules/default/calendar/node_helper.js @@ -19,6 +19,14 @@ module.exports = NodeHelper.create({ socketNotificationReceived: function (notification, payload) { if (notification === "ADD_CALENDAR") { this.createFetcher(payload.url, payload.fetchInterval, payload.excludedEvents, payload.maximumEntries, payload.maximumNumberOfDays, payload.auth, payload.broadcastPastEvents, payload.selfSignedCert, payload.id); + } else if (notification === "FETCH_CALENDAR") { + key = payload.id + payload.url; + if (typeof this.fetchers[key] === "undefined") { + Log.error("Calendar Error. No fetcher exists with key: ", key); + this.sendSocketNotification("CALENDAR_ERROR", { error_type: "MODULE_ERROR_UNSPECIFIED" }); + return; + } + this.fetchers[key].startFetch(); } },