Update all non-major dependencies
[ProtonMail-WebClient.git] / applications / calendar / src / app / components / eventModal / eventForm / propertiesToAttendeeModel.ts
blobf5049680bc06055e0508060141e20ae2f5513be7
1 import { ICAL_ATTENDEE_RSVP } from '@proton/shared/lib/calendar/constants';
2 import { extractEmailAddress } from '@proton/shared/lib/calendar/vcalConverter';
3 import { getAttendeePartstat, getAttendeeRole } from '@proton/shared/lib/calendar/vcalHelper';
4 import { captureMessage } from '@proton/shared/lib/helpers/sentry';
5 import type { AttendeeModel } from '@proton/shared/lib/interfaces/calendar';
6 import type { VcalAttendeeProperty } from '@proton/shared/lib/interfaces/calendar/VcalModel';
8 export const propertiesToAttendeeModel = (attendee?: VcalAttendeeProperty[]): AttendeeModel[] => {
9     if (!attendee) {
10         return [];
11     }
12     return attendee
13         .map<AttendeeModel | null>((attendee) => {
14             const email = extractEmailAddress(attendee);
15             if (email === undefined) {
16                 captureMessage('Malformed attendee', { extra: { attendee } });
17                 return null;
18             }
19             const result: AttendeeModel = {
20                 email,
21                 rsvp: ICAL_ATTENDEE_RSVP.TRUE,
22                 cn: attendee.parameters?.cn || email,
23                 partstat: getAttendeePartstat(attendee),
24                 role: getAttendeeRole(attendee),
25                 token: attendee?.parameters?.['x-pm-token'],
26             };
27             return result;
28         })
29         .filter<AttendeeModel>((attendee) => attendee !== null);