Duplicate meeting within non-traditional calendars (#5208)

* Filter calendars and don't return

* Adding comment

* Applying feedback
pull/5248/head^2
Leo Giovanetti 2022-11-01 13:07:28 -03:00 committed by GitHub
parent 98f6fd836e
commit edabf27929
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 5 deletions

View File

@ -78,6 +78,9 @@ export default class EventManager {
const appCredentials = getApps(user.credentials).flatMap((app) =>
app.credentials.map((creds) => ({ ...creds, appName: app.name }))
);
// This includes all calendar-related apps, traditional calendars such as Google Calendar
// (type google_calendar) and non-traditional calendars such as CRMs like Close.com
// (type closecom_other_calendar)
this.calendarCredentials = appCredentials.filter((cred) => cred.type.endsWith("_calendar"));
this.videoCredentials = appCredentials.filter((cred) => cred.type.endsWith("_video"));
}
@ -317,7 +320,10 @@ export default class EventManager {
);
if (credential) {
createdEvents.push(await createEvent(credential, event));
const createdEvent = await createEvent(credential, event);
if (createdEvent) {
createdEvents.push(createdEvent);
}
}
} else {
const destinationCalendarCredentials = this.calendarCredentials.filter(
@ -332,11 +338,13 @@ export default class EventManager {
* Not ideal but, if we don't find a destination calendar,
* fallback to the first connected calendar
*/
const [credential] = this.calendarCredentials;
if (!credential) {
return [];
const [credential] = this.calendarCredentials.filter((cred) => cred.type === "calendar");
if (credential) {
const createdEvent = await createEvent(credential, event);
if (createdEvent) {
createdEvents.push(createdEvent);
}
}
createdEvents.push(await createEvent(credential, event));
}
// Taking care of non-traditional calendar integrations