diff --git a/package-lock.json b/package-lock.json index b3ff500..160a633 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "obsidian-ics", - "version": "1.5.2", + "version": "1.5.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "obsidian-ics", - "version": "1.5.2", + "version": "1.5.3", "license": "MIT", "dependencies": { "moment-timezone": "^0.5.43", diff --git a/src/IEvent.ts b/src/IEvent.ts index 1b48fc4..f5b8b04 100644 --- a/src/IEvent.ts +++ b/src/IEvent.ts @@ -11,11 +11,12 @@ export interface IEvent { location: string; // Physical location where the event takes place, if applicable callUrl: string; // URL for joining online meetings/calls associated with the event callType: string; // Type of online meeting (e.g., Zoom, Skype, etc.) - guests: IGuest[]; // Array of guests attending the event + attendees: IAttendee[]; // Array of attendees } -export interface IGuest { - name: string; // Name of the guest - email: string; // Email of the guest - status: string; // Participation status (e.g., "Accepted", "Declined") +export interface IAttendee { + email: string; + name: string; + role: string; + status: string; // Participation status (accepted, declined, etc.) } diff --git a/src/main.ts b/src/main.ts index 68ff7a6..19a76f4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -20,7 +20,7 @@ import { request } from 'obsidian'; import { parseIcs, filterMatchingEvents, extractMeetingInfo } from './icalUtils'; -import { IEvent, IGuest } from './IEvent'; +import { IEvent, IAttendee } from './IEvent'; export default class ICSPlugin extends Plugin { data: ICSSettings; @@ -42,7 +42,13 @@ export default class ICSPlugin extends Plugin { formatEvent(e: IEvent): string { const callLinkOrLocation = e.callType ? `[${e.callType}](${e.callUrl})` : e.location; - const guestListFormatted = e.guests.map(guest => `\t\t- ${guest.name} (${guest.email}): ${guest.status}`).join('\n'); + const attendeeList = e.attendees.map(attendee => { + // Check if the name and the email are identical + const displayName = attendee.name === attendee.email + ? attendee.name // If identical, use only one of them + : `${attendee.name} (${attendee.email})`; // If not, use both + return `\t\t- ${displayName}: ${attendee.status}`; + }).join('\n'); // Conditionally format start and end time based on dataViewSyntax setting const startTimeFormatted = this.data.format.dataViewSyntax ? `[startTime:: ${e.time}]` : `${e.time}`; @@ -57,7 +63,7 @@ export default class ICSPlugin extends Plugin { e.format.summary ? e.summary : '', e.format.location ? callLinkOrLocation : '', e.format.description && e.description ? `\n\t- ${e.description}` : '', - e.guests.length > 0 ? `\n\t- Guests:\n${guestListFormatted}` : '' + e.attendees.length > 0 ? `\n\t- Attendees:\n${attendeeList}` : '' ].filter(Boolean).join(' ').trim(); } @@ -101,25 +107,7 @@ export default class ICSPlugin extends Plugin { dateEvents.forEach((e) => { const { callUrl, callType } = extractMeetingInfo(e); - let guests: IGuest[] = []; - if (e.attendee) { - if (Array.isArray(e.attendee)) { - guests = e.attendee.map(att => { - return { - name: att.params.CN, - email: att.val.substring(7), // Remove 'mailto:' prefix - status: att.params.PARTSTAT - }; - }); - } else { - guests.push({ - name: e.attendee.params.CN, - email: e.attendee.val.substring(7), // Remove 'mailto:' prefix - status: e.attendee.params.PARTSTAT - }); - } - } - let event: IEvent = { + const event: IEvent = { utime: moment(e.start).format('X'), time: moment(e.start).format(this.data.format.timeFormat), endTime: moment(e.end).format(this.data.format.timeFormat), @@ -130,7 +118,12 @@ export default class ICSPlugin extends Plugin { location: e.location ? e.location : null, callUrl: callUrl, callType: callType, - guests: guests + attendees: e.attendee ? (Array.isArray(e.attendee) ? e.attendee : [e.attendee]).map(attendee => ({ + name: attendee.params.CN, + email: attendee.val.substring(7), + status: attendee.params.PARTSTAT, + role: attendee.params.ROLE + })) : [] }; events.push(event); });