From b3d73f5293f2766e3a04129d59c8361e0f29edc5 Mon Sep 17 00:00:00 2001 From: jonas0b1011001 <43352574+jonas0b1011001@users.noreply.github.com> Date: Tue, 5 Nov 2019 13:44:49 +0100 Subject: [PATCH 1/7] Remove triggers from previous versions As mentioned in Discord support channel --- Helpers.gs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Helpers.gs b/Helpers.gs index 53b84e8..4e8c090 100644 --- a/Helpers.gs +++ b/Helpers.gs @@ -34,7 +34,7 @@ function condenseCalendarMap(calendarMap){ function deleteAllTriggers(){ var triggers = ScriptApp.getProjectTriggers(); for (var i = 0; i < triggers.length; i++){ - if (triggers[i].getHandlerFunction() == "startSync" || triggers[i].getHandlerFunction() == "install"){ + if (triggers[i].getHandlerFunction() == "startSync" || triggers[i].getHandlerFunction() == "install" || triggers[i].getHandlerFunction() == "main"){ ScriptApp.deleteTrigger(triggers[i]); } } @@ -790,4 +790,4 @@ function checkForUpdate(){ } catch(e){} } -} \ No newline at end of file +} From 3acb601085f5bcdca845e1b25b2b972e687d2988 Mon Sep 17 00:00:00 2001 From: jonas0b1011001 <43352574+jonas0b1011001@users.noreply.github.com> Date: Fri, 13 Dec 2019 14:21:42 +0100 Subject: [PATCH 2/7] Fix #77 and #84 --- Code.gs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/Code.gs b/Code.gs index 87ba8dc..6970e7f 100644 --- a/Code.gs +++ b/Code.gs @@ -87,15 +87,19 @@ var email = ""; // OPTIONAL: If "emailWhenAdded" is set t //!!!!!!!!!!!!!!!! DO NOT EDIT BELOW HERE UNLESS YOU REALLY KNOW WHAT YOU'RE DOING !!!!!!!!!!!!!!!!!!!! //===================================================================================================== function install(){ - //Delete any already existing triggers so we don't create excessive triggers - deleteAllTriggers(); - - if (howFrequent < 1){ - throw "[ERROR] \"howFrequent\" must be greater than 0."; - } - else{ - ScriptApp.newTrigger("install").timeBased().after(howFrequent * 60 * 1000).create();//Schedule next Execution - ScriptApp.newTrigger("startSync").timeBased().after(1000).create();//Start the sync routine + try{ + //Delete any already existing triggers so we don't create excessive triggers + deleteAllTriggers(); + + if (howFrequent < 1){ + throw "[ERROR] \"howFrequent\" must be greater than 0."; + } + else{ + ScriptApp.newTrigger("install").timeBased().after(howFrequent * 60 * 1000).create();//Schedule next Execution + ScriptApp.newTrigger("startSync").timeBased().after(1000).create();//Start the sync routine + } + }catch(e){ + install();//Retry on error } } @@ -104,6 +108,7 @@ function uninstall(){ } var targetCalendarId; +var targetCalendarName; var calendarEvents = []; var calendarEventsIds = []; var icsEventsIds = []; @@ -123,7 +128,7 @@ function startSync(){ sourceCalendars = condenseCalendarMap(sourceCalendars); for each (var calendar in sourceCalendars){ calendarEvents = []; - var targetCalendarName = calendar[0]; + targetCalendarName = calendar[0]; var sourceCalendarURLs = calendar[1]; var vevents; //------------------------ Fetch URL items ------------------------ From 41f4c8392c2b3b36eadc03c6e3f02decaa6911ab Mon Sep 17 00:00:00 2001 From: jonas0b1011001 <43352574+jonas0b1011001@users.noreply.github.com> Date: Mon, 27 Jan 2020 07:05:42 +0100 Subject: [PATCH 3/7] Fix #95 and 'native' organizer support --- Helpers.gs | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/Helpers.gs b/Helpers.gs index 4e8c090..3b64fe7 100644 --- a/Helpers.gs +++ b/Helpers.gs @@ -281,7 +281,7 @@ function createEvent(event, calendarTz){ newEvent.status = status; } - if (event.hasProperty('url')){ + if (event.hasProperty('url') && event.getFirstPropertyValue('url').toString() != ''){ newEvent.source = Calendar.newEventSource() newEvent.source.url = event.getFirstPropertyValue('url').toString(); } @@ -295,8 +295,8 @@ function createEvent(event, calendarTz){ else if (event.hasProperty('summary')) newEvent.summary = icalEvent.summary; - if (addOrganizerToTitle){ - var organizer = parseOrganizerName(event.toString()); + if (addOrganizerToTitle && event.hasProperty('organizer')){ + var organizer = event.getFirstProperty('organizer').getParameter('cn').toString(); if (organizer != null) newEvent.summary = organizer + ": " + newEvent.summary; } @@ -672,28 +672,6 @@ function parseAttendeeResp(veventString){ } } -/** - * Parses the provided string to find the name of the event organizer. - * Will return null if no name is found. - * - * @param {string} veventString - The string to parse - * @return {?String} The organizer's name found in the string, null if no name was found - */ -function parseOrganizerName(veventString){ - /*A regex match is necessary here because ICAL.js doesn't let us directly - * get the "CN" part of an ORGANIZER property. With something like - * ORGANIZER;CN="Sally Example":mailto:sally@example.com - * VEVENT.getFirstPropertyValue('organizer') returns "mailto:sally@example.com". - * Therefore we have to use a regex match on the VEVENT string instead - */ - - var nameMatch = RegExp("organizer(?:;|:)cn=(.*?):", "gi").exec(veventString); - if (nameMatch != null && nameMatch.length > 1) - return nameMatch[1]; - else - return null; -} - /** * Parses the provided string to find the notification time of an event. * Will return 0 by default. From c84d0823e055f38f364493f99e0a8a709fc22ea2 Mon Sep 17 00:00:00 2001 From: jonas0b1011001 <43352574+jonas0b1011001@users.noreply.github.com> Date: Thu, 30 Jan 2020 18:13:31 +0100 Subject: [PATCH 4/7] Added X-WR-CALNAME support as mentioned in #94 X-WR-CALNAME has higher priority than NAME if both are present. --- Helpers.gs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Helpers.gs b/Helpers.gs index 3b64fe7..a2dce69 100644 --- a/Helpers.gs +++ b/Helpers.gs @@ -113,7 +113,7 @@ function parseResponses(responses){ } var allEvents = component.getAllSubcomponents("vevent"); - var calName = component.getFirstPropertyValue("name"); + var calName = component.getFirstPropertyValue("x-wr-calname") || component.getFirstPropertyValue("name"); if (calName != null) allEvents.forEach(function(event){event.addPropertyWithValue("parentCal", calName); }); From 47efdc69e6685b271f35b44be6b7f6b46f762a8c Mon Sep 17 00:00:00 2001 From: jonas0b1011001 <43352574+jonas0b1011001@users.noreply.github.com> Date: Thu, 30 Jan 2020 18:22:14 +0100 Subject: [PATCH 5/7] Fix #81 (presumably #92) Proper handling of recurrence-id timestamps. Timestamp will be converted to Z as processEventInstance retrieves instances in Z. --- Helpers.gs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Helpers.gs b/Helpers.gs index a2dce69..468921b 100644 --- a/Helpers.gs +++ b/Helpers.gs @@ -150,7 +150,8 @@ function processEvent(event, calendarTz){ //------------------------ Save instance overrides ------------------------ //----------- To make sure the parent event is actually created ----------- if (event.hasProperty('recurrence-id')){ - newEvent.recurringEventId = event.getFirstPropertyValue('recurrence-id').toString(); + var recID = new ICAL.Time.fromDateTimeString(event.getFirstPropertyValue('recurrence-id').toString(), event.getFirstProperty('recurrence-id')); + newEvent.recurringEventId = recID.convertToZone(ICAL.TimezoneService.get('UTC')).toString(); Logger.log("Saving event instance for later: " + newEvent.recurringEventId); newEvent.extendedProperties.private['rec-id'] = newEvent.extendedProperties.private['id'] + "_" + newEvent.recurringEventId; recurringEvents.push(newEvent); From c8ff465cea3fe69000402d8505992a3141aabeb6 Mon Sep 17 00:00:00 2001 From: jonas0b1011001 <43352574+jonas0b1011001@users.noreply.github.com> Date: Thu, 30 Jan 2020 18:35:09 +0100 Subject: [PATCH 6/7] #85 Quicker way to filter past events. This will filter events without processing them and should be able to handle thousands of events. --- Helpers.gs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Helpers.gs b/Helpers.gs index 468921b..27a41dc 100644 --- a/Helpers.gs +++ b/Helpers.gs @@ -120,6 +120,23 @@ function parseResponses(responses){ result = [].concat(allEvents, result); } + if (onlyFutureEvents){ + result = result.filter(function(event){ + try{ + if (event.hasProperty('recurrence-id') || event.hasProperty('rrule') || event.hasProperty('rdate') || event.hasProperty('exdate')){ + //Keep recurrences to properly filter them later on + return true; + } + var eventEnde; + eventEnde = new ICAL.Time.fromString(event.getFirstPropertyValue('dtend').toString()); + eventEnde = eventEnde.adjust(1,0,0,0);//Avoid timezone issues + return (eventEnde.compare(startUpdateTime) >= 0); + }catch(e){ + return true; + } + }); + } + result.forEach(function(event){ if(event.hasProperty('recurrence-id')){ icsEventsIds.push(event.getFirstPropertyValue('uid').toString() + "_" + event.getFirstPropertyValue('recurrence-id').toString()); From a63d5a506addd1793013e08325ed3450c94fecc9 Mon Sep 17 00:00:00 2001 From: jonas0b1011001 <43352574+jonas0b1011001@users.noreply.github.com> Date: Thu, 30 Jan 2020 18:50:27 +0100 Subject: [PATCH 7/7] Increased version number --- Helpers.gs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Helpers.gs b/Helpers.gs index 27a41dc..3837754 100644 --- a/Helpers.gs +++ b/Helpers.gs @@ -769,7 +769,7 @@ function checkForUpdate(){ var alreadyAlerted = PropertiesService.getScriptProperties().getProperty("alertedForNewVersion"); if (alreadyAlerted == null){ try{ - var thisVersion = 5.0; + var thisVersion = 5.1; var html = UrlFetchApp.fetch("https://github.com/derekantrican/GAS-ICS-Sync/releases"); var regex = RegExp("","g"); var latestRelease = regex.exec(html)[0];