diff --git a/lib/calendarClient.ts b/lib/calendarClient.ts index baa47349..6d59ff7a 100644 --- a/lib/calendarClient.ts +++ b/lib/calendarClient.ts @@ -512,10 +512,11 @@ const listCalendars = (withCredentials) => const createEvent = async ( credential: Credential, calEvent: CalendarEvent, - noMail = false + noMail = false, + maybeUid: string = null ): Promise => { const parser: CalEventParser = new CalEventParser(calEvent); - const uid: string = parser.getUid(); + const uid: string = maybeUid ?? parser.getUid(); const richEvent: CalendarEvent = parser.asRichEvent(); let success = true; diff --git a/lib/events/EventManager.ts b/lib/events/EventManager.ts index be68f58b..98987022 100644 --- a/lib/events/EventManager.ts +++ b/lib/events/EventManager.ts @@ -54,19 +54,21 @@ export default class EventManager { * Takes a CalendarEvent and creates all necessary integration entries for it. * When a video integration is chosen as the event's location, a video integration * event will be scheduled for it as well. + * An optional uid can be set to override the auto-generated uid. * * @param event + * @param maybeUid */ - public async create(event: CalendarEvent): Promise { + public async create(event: CalendarEvent, maybeUid: string = null): Promise { event = EventManager.processLocation(event); const isVideo = EventManager.isIntegration(event.location); // First, create all calendar events. If this is a video event, don't send a mail right here. - const results: Array = await this.createAllCalendarEvents(event, isVideo); + const results: Array = await this.createAllCalendarEvents(event, isVideo, maybeUid); // If and only if event type is a video meeting, create a video meeting as well. if (isVideo) { - results.push(await this.createVideoEvent(event)); + results.push(await this.createVideoEvent(event, maybeUid)); } const referencesToCreate: Array = results.map((result) => { @@ -151,13 +153,20 @@ export default class EventManager { * a video meeting because then the mail containing the video credentials will be * more important than the mails created for these bare calendar events. * + * When the optional uid is set, it will be used instead of the auto generated uid. + * * @param event * @param noMail + * @param maybeUid * @private */ - private createAllCalendarEvents(event: CalendarEvent, noMail: boolean): Promise> { + private createAllCalendarEvents( + event: CalendarEvent, + noMail: boolean, + maybeUid: string = null + ): Promise> { return async.mapLimit(this.calendarCredentials, 5, async (credential: Credential) => { - return createEvent(credential, event, noMail); + return createEvent(credential, event, noMail, maybeUid); }); } @@ -175,14 +184,17 @@ export default class EventManager { /** * Creates a video event entry for the selected integration location. * + * When optional uid is set, it will be used instead of the auto generated uid. + * * @param event + * @param maybeUid * @private */ - private createVideoEvent(event: CalendarEvent): Promise { + private createVideoEvent(event: CalendarEvent, maybeUid: string = null): Promise { const credential = this.getVideoCredential(event); if (credential) { - return createMeeting(credential, event); + return createMeeting(credential, event, maybeUid); } else { return Promise.reject("No suitable credentials given for the requested integration name."); } diff --git a/lib/videoClient.ts b/lib/videoClient.ts index faea7d0b..1f4e3d3d 100644 --- a/lib/videoClient.ts +++ b/lib/videoClient.ts @@ -201,8 +201,12 @@ const getBusyVideoTimes = (withCredentials) => results.reduce((acc, availability) => acc.concat(availability), []) ); -const createMeeting = async (credential, calEvent: CalendarEvent): Promise => { - const uid: string = translator.fromUUID(uuidv5(JSON.stringify(calEvent), uuidv5.URL)); +const createMeeting = async ( + credential, + calEvent: CalendarEvent, + maybeUid: string = null +): Promise => { + const uid: string = maybeUid ?? translator.fromUUID(uuidv5(JSON.stringify(calEvent), uuidv5.URL)); if (!credential) { throw new Error(