Skip to content

Commit

Permalink
fix: getOrganizer Name on different platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin.jaroschewski committed Jul 4, 2024
1 parent d363274 commit 5e3dfe8
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 22 deletions.
63 changes: 41 additions & 22 deletions src/calendarIntegration/addMeetingLink.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
/* 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";
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;
Expand Down Expand Up @@ -76,25 +84,31 @@ async function createNewMeeting(): Promise<void> {
removeNotification("adding-wire-meeting");
}

/**
* Retrieves the platform-specific organizer for the current mailbox item.
*
* @return {Promise<any>} A promise that resolves to the platform-specific organizer.
*/
async function getPlatformSpecificOrganizer(): Promise<any> {
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.
*
* @param {EventResult} eventResult - The event result containing the link for the meeting.
* @return {Promise<void>} A promise that resolves when the meeting details are updated.
*/
async function updateMeetingDetails(eventResult: EventResult): Promise<void> {

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);
}

/**
Expand All @@ -111,16 +125,17 @@ async function handleExistingMeeting(): Promise<void> {
const currentLocation = await getLocation(mailboxItem);
const normalizedCurrentBody = currentBody.replace(/&amp;/g, "&");
const normalizedMeetingLink = createdMeeting.link?.replace(/&amp;/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);
Expand All @@ -134,11 +149,9 @@ async function handleExistingMeeting(): Promise<void> {
*/
async function addMeetingLink(event: Office.AddinCommands.Event): Promise<void> {
try {

const isEnabled = await isFeatureEnabled();
if (!isEnabled) return;


await fetchCustomProperties();
if (!createdMeeting) {
await createNewMeeting();
Expand All @@ -149,6 +162,12 @@ async function addMeetingLink(event: Office.AddinCommands.Event): Promise<void>
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();
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/types/PlatformTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export enum PlatformType {
IOS = "iOS",
ANDROID = "Android",
PC = "PC",
OFFICEONLINE = "OfficeOnline",
MAC = "Mac",
UNIVERSAL = "Universal"
}
16 changes: 16 additions & 0 deletions src/utils/mailbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ export async function getOrganizer(item): Promise<string> {
});
}

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;

Expand Down

0 comments on commit 5e3dfe8

Please sign in to comment.