diff --git a/src/calendarIntegration/addMeetingLink.ts b/src/calendarIntegration/addMeetingLink.ts index 11468a0..40591d5 100644 --- a/src/calendarIntegration/addMeetingLink.ts +++ b/src/calendarIntegration/addMeetingLink.ts @@ -1,6 +1,14 @@ /* global Office, console */ -import { appendToBody, getBody, getLocation, getMailboxItemSubject, getOrganizer, setLocation } from "../utils/mailbox"; +import { + appendToBody, + getBody, + getLocation, + getMailboxItemSubject, + getOrganizer, + getOrganizerOnMobile, + setLocation, +} from "../utils/mailbox"; import { createMeetingSummary } from "./createMeetingSummary"; import { setCustomPropertyAsync, getCustomPropertyAsync } from "../utils/customProperties"; import { showNotification, removeNotification } from "../utils/notifications"; @@ -8,7 +16,7 @@ import { isOutlookCalIntegrationEnabled } from "./isOutlookCalIntegrationEnabled import { createEvent } from "./createEvent"; import { mailboxItem } from "../commands/commands"; import { EventResult } from "../types/EventResult"; -import { getUserDetails } from "../utils/userDetailsStore"; +import { PlatformType } from "../types/PlatformTypes"; const defaultSubjectValue = "New Appointment"; let createdMeeting: EventResult; @@ -76,6 +84,18 @@ async function createNewMeeting(): Promise { removeNotification("adding-wire-meeting"); } +/** + * Retrieves the platform-specific organizer for the current mailbox item. + * + * @return {Promise} A promise that resolves to the platform-specific organizer. + */ +async function getPlatformSpecificOrganizer(): Promise { + if (Office.context.platform.toString() == PlatformType.IOS || Office.context.platform.toString() == PlatformType.ANDROID) { + return await getOrganizerOnMobile(mailboxItem); + } else { + return await getOrganizer(mailboxItem); + } +} /** * Updates the meeting details by setting the location and appending the meeting summary to the body of the mailbox item. * @@ -83,18 +103,12 @@ async function createNewMeeting(): Promise { * @return {Promise} A promise that resolves when the meeting details are updated. */ async function updateMeetingDetails(eventResult: EventResult): Promise { - await setLocation(mailboxItem, eventResult.link, () => {}); - // const organizer = await getOrganizer(mailboxItem); - const user = getUserDetails(); - const meetingSummary = createMeetingSummary(eventResult.link, user.name); - await appendToBody(mailboxItem, user.name); - // getOrganizer(mailboxItem, async (organizer) => { - // const meetingSummary = createMeetingSummary(eventResult.link, organizer); - // await appendToBody(mailboxItem, meetingSummary); - // }); + const organizer = await getPlatformSpecificOrganizer(); + const meetingSummary = createMeetingSummary(eventResult.link, organizer); + await appendToBody(mailboxItem, meetingSummary); } /** @@ -111,16 +125,17 @@ async function handleExistingMeeting(): Promise { const currentLocation = await getLocation(mailboxItem); const normalizedCurrentBody = currentBody.replace(/&/g, "&"); const normalizedMeetingLink = createdMeeting.link?.replace(/&/g, "&"); + const organizer = await getPlatformSpecificOrganizer(); + const meetingSummary = createMeetingSummary(createdMeeting.link, organizer); - // getOrganizer(mailboxItem, async (organizer) => { - // if (!currentLocation) { - // await setLocation(mailboxItem, createdMeeting.link, () => {}); - // } - // const meetingSummary = createMeetingSummary(createdMeeting.link, organizer); - // if (!normalizedCurrentBody.includes(normalizedMeetingLink)) { - // await appendToBody(mailboxItem, meetingSummary); - // } - // }); + if (!currentLocation) { + await setLocation(mailboxItem, createdMeeting.link, () => {}); + } + + + if (!normalizedCurrentBody.includes(normalizedMeetingLink)) { + await appendToBody(mailboxItem, meetingSummary); + } await setCustomPropertyAsync(mailboxItem, "wireId", createdMeeting.id); await setCustomPropertyAsync(mailboxItem, "wireLink", createdMeeting.link); @@ -134,11 +149,9 @@ async function handleExistingMeeting(): Promise { */ async function addMeetingLink(event: Office.AddinCommands.Event): Promise { try { - const isEnabled = await isFeatureEnabled(); if (!isEnabled) return; - await fetchCustomProperties(); if (!createdMeeting) { await createNewMeeting(); @@ -149,6 +162,12 @@ async function addMeetingLink(event: Office.AddinCommands.Event): Promise console.error("Error during adding Wire meeting link", error); handleAddMeetingLinkError(error); } finally { + if ( + Office.context.platform.toString() == PlatformType.IOS || + Office.context.platform.toString() == PlatformType.ANDROID + ) { + await appendToBody(mailboxItem, ""); + } event.completed(); } } diff --git a/src/types/PlatformTypes.ts b/src/types/PlatformTypes.ts new file mode 100644 index 0000000..6a97e6e --- /dev/null +++ b/src/types/PlatformTypes.ts @@ -0,0 +1,8 @@ +export enum PlatformType { + IOS = "iOS", + ANDROID = "Android", + PC = "PC", + OFFICEONLINE = "OfficeOnline", + MAC = "Mac", + UNIVERSAL = "Universal" +} \ No newline at end of file diff --git a/src/utils/mailbox.ts b/src/utils/mailbox.ts index 31ce2c9..4055941 100644 --- a/src/utils/mailbox.ts +++ b/src/utils/mailbox.ts @@ -23,6 +23,22 @@ export async function getOrganizer(item): Promise { }); } +export async function getOrganizerOnMobile(item) { + return new Promise((resolve, reject) => { + item.body.getAsync( + "html", + { asyncContext: Office.context.mailbox.userProfile.displayName }, + (result) => { + if (result.status === Office.AsyncResultStatus.Succeeded) { + resolve(result.asyncContext); + } else { + reject(new Error("Failed to get body.")); + } + } + ); + }); +} + export async function getSubject(item, callback) { const { subject } = item;