Added maybeUid to createEvent and createMeeting

This commit is contained in:
nicolas 2021-07-25 17:05:18 +02:00
parent 4fb8e8285e
commit b0ac65b0f6
3 changed files with 28 additions and 11 deletions

View file

@ -512,10 +512,11 @@ const listCalendars = (withCredentials) =>
const createEvent = async ( const createEvent = async (
credential: Credential, credential: Credential,
calEvent: CalendarEvent, calEvent: CalendarEvent,
noMail = false noMail = false,
maybeUid: string = null
): Promise<EventResult> => { ): Promise<EventResult> => {
const parser: CalEventParser = new CalEventParser(calEvent); const parser: CalEventParser = new CalEventParser(calEvent);
const uid: string = parser.getUid(); const uid: string = maybeUid ?? parser.getUid();
const richEvent: CalendarEvent = parser.asRichEvent(); const richEvent: CalendarEvent = parser.asRichEvent();
let success = true; let success = true;

View file

@ -54,19 +54,21 @@ export default class EventManager {
* Takes a CalendarEvent and creates all necessary integration entries for it. * 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 * When a video integration is chosen as the event's location, a video integration
* event will be scheduled for it as well. * event will be scheduled for it as well.
* An optional uid can be set to override the auto-generated uid.
* *
* @param event * @param event
* @param maybeUid
*/ */
public async create(event: CalendarEvent): Promise<CreateUpdateResult> { public async create(event: CalendarEvent, maybeUid: string = null): Promise<CreateUpdateResult> {
event = EventManager.processLocation(event); event = EventManager.processLocation(event);
const isVideo = EventManager.isIntegration(event.location); const isVideo = EventManager.isIntegration(event.location);
// First, create all calendar events. If this is a video event, don't send a mail right here. // First, create all calendar events. If this is a video event, don't send a mail right here.
const results: Array<EventResult> = await this.createAllCalendarEvents(event, isVideo); const results: Array<EventResult> = await this.createAllCalendarEvents(event, isVideo, maybeUid);
// If and only if event type is a video meeting, create a video meeting as well. // If and only if event type is a video meeting, create a video meeting as well.
if (isVideo) { if (isVideo) {
results.push(await this.createVideoEvent(event)); results.push(await this.createVideoEvent(event, maybeUid));
} }
const referencesToCreate: Array<PartialReference> = results.map((result) => { const referencesToCreate: Array<PartialReference> = results.map((result) => {
@ -151,13 +153,20 @@ export default class EventManager {
* a video meeting because then the mail containing the video credentials will be * a video meeting because then the mail containing the video credentials will be
* more important than the mails created for these bare calendar events. * 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 event
* @param noMail * @param noMail
* @param maybeUid
* @private * @private
*/ */
private createAllCalendarEvents(event: CalendarEvent, noMail: boolean): Promise<Array<EventResult>> { private createAllCalendarEvents(
event: CalendarEvent,
noMail: boolean,
maybeUid: string = null
): Promise<Array<EventResult>> {
return async.mapLimit(this.calendarCredentials, 5, async (credential: Credential) => { 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. * 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 event
* @param maybeUid
* @private * @private
*/ */
private createVideoEvent(event: CalendarEvent): Promise<EventResult> { private createVideoEvent(event: CalendarEvent, maybeUid: string = null): Promise<EventResult> {
const credential = this.getVideoCredential(event); const credential = this.getVideoCredential(event);
if (credential) { if (credential) {
return createMeeting(credential, event); return createMeeting(credential, event, maybeUid);
} else { } else {
return Promise.reject("No suitable credentials given for the requested integration name."); return Promise.reject("No suitable credentials given for the requested integration name.");
} }

View file

@ -201,8 +201,12 @@ const getBusyVideoTimes = (withCredentials) =>
results.reduce((acc, availability) => acc.concat(availability), []) results.reduce((acc, availability) => acc.concat(availability), [])
); );
const createMeeting = async (credential, calEvent: CalendarEvent): Promise<EventResult> => { const createMeeting = async (
const uid: string = translator.fromUUID(uuidv5(JSON.stringify(calEvent), uuidv5.URL)); credential,
calEvent: CalendarEvent,
maybeUid: string = null
): Promise<EventResult> => {
const uid: string = maybeUid ?? translator.fromUUID(uuidv5(JSON.stringify(calEvent), uuidv5.URL));
if (!credential) { if (!credential) {
throw new Error( throw new Error(