Skip to content

Commit

Permalink
fix: fixed add-in for android
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin.jaroschewski committed Jul 10, 2024
1 parent 86d2b50 commit 033edc6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 41 deletions.
9 changes: 3 additions & 6 deletions src/calendarIntegration/addMeetingLink.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import { appendToBody, getBody, getLocation, getMailboxItemSubject, getMeetingTime, getOrganizer, getOrganizerOnMobile, setLocation } from "../utils/mailbox";
import { appendToBody, getBody, getLocation, getMailboxItemSubject, getMeetingTime, getOrganizer, getOrganizerOnMobile, isMobileDevice, setLocation } from "../utils/mailbox";
import { createMeetingSummary } from "./createMeetingSummary";
import { setCustomPropertyAsync, getCustomPropertyAsync } from "../utils/customProperties";
import { showNotification, removeNotification } from "../utils/notifications";
Expand Down Expand Up @@ -99,7 +99,7 @@ async function createNewMeeting(): Promise<void> {
* @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) {
if (isMobileDevice()) {
return await getOrganizerOnMobile(mailboxItem);
} else {
return await getOrganizer(mailboxItem);
Expand Down Expand Up @@ -172,10 +172,7 @@ 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
) {
if (isMobileDevice()) {
await appendToBody(mailboxItem, ""); //Workaround for mobile devices - Without body gets removed
}
event.completed();
Expand Down
80 changes: 45 additions & 35 deletions src/utils/mailbox.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
export async function getMailboxItemSubject(item) : Promise<string> {
return new Promise((resolve,reject) => {
const { subject } = item;
import { PlatformType } from "../types/PlatformTypes";

subject.getAsync(function (asyncResult) {
if (asyncResult.status == Office.AsyncResultStatus.Failed) {
console.error("Failed to get item subject");
reject(new Error("Failed to get item subject"));
} else {
resolve(asyncResult.value);
}
export async function getMailboxItemSubject(item): Promise<string> {
return new Promise((resolve, reject) => {
const { subject } = item;

subject.getAsync(function (asyncResult) {
if (asyncResult.status == Office.AsyncResultStatus.Failed) {
console.error("Failed to get item subject");
reject(new Error("Failed to get item subject"));
} else {
resolve(asyncResult.value);
}
});
});
});
}

export async function getOrganizer(item): Promise<string> {
return new Promise((resolve, reject) => {
const { organizer } = item;

organizer.getAsync(function(asyncResult) {
organizer.getAsync(function (asyncResult) {
if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
resolve(asyncResult.value.displayName);
} else {
Expand All @@ -30,23 +32,17 @@ 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."));
}
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 setSubject(item, newSubject:string){

export async function setSubject(item, newSubject: string) {
const { subject } = item;

subject.setAsync(newSubject, function (asyncResult) {
Expand All @@ -67,18 +63,17 @@ export async function getMeetingTime(item): Promise<string> {
reject(new Error(`Failed to get start time: ${asyncResult.error.message}`));
return;
}
const locale = Office.context.displayLanguage;
const formattedDate = new Date(asyncResult.value).toLocaleString(locale, {
year: 'numeric',
month: 'numeric',
day: 'numeric',
});
resolve(formattedDate);
const locale = Office.context.displayLanguage;
const formattedDate = new Date(asyncResult.value).toLocaleString(locale, {
year: "numeric",
month: "numeric",
day: "numeric",
});
resolve(formattedDate);
});
});
}


export function getBody(item): Promise<string> {
return new Promise((resolve, reject) => {
const { body } = item;
Expand All @@ -94,7 +89,6 @@ export function getBody(item): Promise<string> {
});
}


export function setBody(item, newBody) {
const { body } = item;
const type = { coercionType: Office.CoercionType.Html };
Expand Down Expand Up @@ -129,7 +123,11 @@ export async function getLocation(item) {
});
});
}

export function isMobileDevice() {
return (
Office.context.platform.toString() == PlatformType.IOS || Office.context.platform.toString() == PlatformType.ANDROID
);
}

export async function setLocation(item, meetlingLink) {
const { location } = item;
Expand All @@ -140,4 +138,16 @@ export async function setLocation(item, meetlingLink) {
return;
}
});

if (isMobileDevice()) {
/* Workaround for mobile devices - sometimes location gets removed*/
let currentLocation = await getLocation(item);

location.setAsync(currentLocation + "", function (asyncResult) {
if (asyncResult.status !== Office.AsyncResultStatus.Succeeded) {
console.error(`Action failed with message ${asyncResult.error.message}`);
return;
}
});
}
}

0 comments on commit 033edc6

Please sign in to comment.