Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 30 additions & 49 deletions defaultmodules/calendar/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,7 @@ Module.register("calendar", {

notificationReceived (notification, payload, sender) {
if (notification === "FETCH_CALENDAR") {
if (this.hasCalendarURL(payload.url)) {
this.sendSocketNotification(notification, { url: payload.url, id: this.identifier });
}
this.sendSocketNotification(notification, { url: payload.url, id: this.identifier });
}
},

Expand All @@ -183,40 +181,38 @@ Module.register("calendar", {
}

if (notification === "CALENDAR_EVENTS") {
if (this.hasCalendarURL(payload.url)) {
// have we received events for this url
if (!this.calendarData[payload.url]) {
// no, setup the structure to hold the info
this.calendarData[payload.url] = { events: null, checksum: null };
}
// save the event list
this.calendarData[payload.url].events = payload.events;

this.error = null;
this.loaded = true;
// have we received events for this url
if (!this.calendarData[payload.url]) {
// no, setup the structure to hold the info
this.calendarData[payload.url] = { events: null, checksum: null };
}
// save the event list
this.calendarData[payload.url].events = payload.events;

if (this.config.broadcastEvents) {
this.broadcastEvents();
}
// if the checksum is the same
if (this.calendarData[payload.url].checksum === payload.checksum) {
// then don't update the UI
return;
}
// haven't seen or the checksum is different
this.calendarData[payload.url].checksum = payload.checksum;
this.error = null;
this.loaded = true;

if (!this.config.updateOnFetch) {
if (this.calendarDisplayer[payload.url] === undefined) {
// calendar will never displayed, so display it
this.updateDom(this.config.animationSpeed);
// set this calendar as displayed
this.calendarDisplayer[payload.url] = true;
} else {
Log.debug("[calendar] DOM not updated waiting self update()");
}
return;
if (this.config.broadcastEvents) {
this.broadcastEvents();
}
// if the checksum is the same
if (this.calendarData[payload.url].checksum === payload.checksum) {
// then don't update the UI
return;
}
// haven't seen or the checksum is different
this.calendarData[payload.url].checksum = payload.checksum;

if (!this.config.updateOnFetch) {
if (this.calendarDisplayer[payload.url] === undefined) {
// calendar will never displayed, so display it
this.updateDom(this.config.animationSpeed);
// set this calendar as displayed
this.calendarDisplayer[payload.url] = true;
} else {
Log.debug("[calendar] DOM not updated waiting self update()");
}
return;
}
} else if (notification === "CALENDAR_ERROR") {
let error_message = this.translate(payload.error_type);
Expand Down Expand Up @@ -580,21 +576,6 @@ Module.register("calendar", {
return wrapper;
},

/**
* Checks if this config contains the calendar url.
* @param {string} url The calendar url
* @returns {boolean} True if the calendar config contains the url, False otherwise
*/
hasCalendarURL (url) {
for (const calendar of this.config.calendars) {
if (calendar.url === url) {
return true;
}
}

return false;
},

/**
* converts the given timestamp to a moment with a timezone
* @param {number} timestamp timestamp from an event
Expand Down