♻️(addons) try using the default client font

Refactor the message builder so that rendered messages are displayed
in a nicer way. Based on user feedback from the social ministries.

Go for a hybrid approach: on the desktop client, insert plain text so
it picks up the default font configured by the client theme; on the
web client, insert HTML, as the editor there is rendered using HTML.
This commit is contained in:
lebaudantoine
2026-06-08 19:52:01 +02:00
committed by aleb_the_flash
parent f777f2fdeb
commit 491866e584
3 changed files with 50 additions and 24 deletions
+7 -5
View File
@@ -24,19 +24,21 @@ function notify(message) {
function insertMeetingLink(event, session) {
createRoom(session)
.then((data) => {
const { url, message } = buildMeetingMessage(data);
const isWeb = Office.context.diagnostics.platform === "OfficeOnline";
const { url, text } = buildMeetingMessage(data, isWeb);
const item = Office.context.mailbox.item;
const coercionType = isWeb ? Office.CoercionType.Html : Office.CoercionType.Text;
return new Promise((resolve, reject) => {
item.body.getAsync(Office.CoercionType.Html, (getResult) => {
item.body.getAsync(coercionType, (getResult) => {
if (getResult.status !== Office.AsyncResultStatus.Succeeded) {
notify(`Erreur de lecture : ${getResult.error.message}`);
resolve();
return;
}
const newBody = getResult.value + message;
item.body.setAsync(newBody, { coercionType: Office.CoercionType.Html }, (setResult) => {
item.body.setAsync(
getResult.value + text,
{ coercionType: coercionType }, (setResult) => {
if (setResult.status !== Office.AsyncResultStatus.Succeeded) {
notify(`Erreur d'insertion : ${setResult.error.message}`);
resolve();
+36 -14
View File
@@ -21,7 +21,7 @@ function _formatPhone(phone) {
}
// todo - escape html / link
function buildMeetingMessage(data) {
function buildMeetingMessage(data, isWeb) {
if (!data?.url) {
throw new Error("buildMeetingMessage: missing url in data");
}
@@ -30,23 +30,45 @@ function buildMeetingMessage(data) {
const phone = _formatPhone(data.telephony?.phone_number);
const pin = _formatPin(data.telephony?.pin_code);
const telephonyBlock =
phone && pin
? `
let textLines = "";
let phoneLines = [];
Ou appelez (audio uniquement)
(FR) ${phone}
Code : ${pin}`
: "";
phoneLines = phone &&
pin && [
"<br><br>Ou appelez (audio uniquement)",
`<br>(FR) ${phone}`,
`<br>Code ${pin}`
];
const message = `<pre style="font-family:inherit; font-size:inherit; border:none; background:none; margin:16px 0;">
────────────────────────────────────────
Rejoindre la réunion ${APP_NAME}
textLines = [
"<br><br>────────────────────────────────────────",
`<br>Rejoindre la réunion ${APP_NAME}`,
`<br><br><a href="${url}" target="_blank">${url}</a>`,
...phoneLines,
"<br>────────────────────────────────────────<br>",
];
<a href="${url}">${url}</a>${telephonyBlock}
────────────────────────────────────────</pre>`;
} else {
return { url, message };
phoneLines = phone &&
pin && [
"\n\nOu appelez (audio uniquement)",
`\n(FR) ${phone}`,
`\nCode ${pin}`
];
textLines = [
"\n\n────────────────────────────────────────",
`\nRejoindre la réunion ${APP_NAME}`,
`\n\n${url}`,
...phoneLines,
"\n────────────────────────────────────────\n",
];
}
const text = textLines.join("");
return { url, text };
}
module.exports = { buildMeetingMessage };
+7 -5
View File
@@ -71,18 +71,20 @@ function generateMeetingLink() {
createRoom(session)
.then((data) => {
const { url, message } = buildMeetingMessage(data);
const isWeb = Office.context.diagnostics.platform === "OfficeOnline";
const { url, text } = buildMeetingMessage(data, isWeb);
const item = Office.context.mailbox.item;
const coercionType = isWeb ? Office.CoercionType.Html : Office.CoercionType.Text;
return new Promise((resolve, reject) => {
item.body.getAsync(Office.CoercionType.Html, (getResult) => {
item.body.getAsync(coercionType, (getResult) => {
if (getResult.status !== Office.AsyncResultStatus.Succeeded) {
reject(getResult.error);
return;
}
item.body.setAsync(
getResult.value + message,
{ coercionType: Office.CoercionType.Html },
getResult.value + text,
{ coercionType: coercionType },
(setResult) => {
if (setResult.status !== Office.AsyncResultStatus.Succeeded) {
reject(setResult.error);