From 63d82c4c32028ae8901589a6a08cf2ce41c46a13 Mon Sep 17 00:00:00 2001 From: gabriellsh Date: Wed, 13 Dec 2023 11:28:29 -0300 Subject: [PATCH 1/5] shortname to unicode --- .../meteor/app/lib/server/functions/notifications/email.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/meteor/app/lib/server/functions/notifications/email.js b/apps/meteor/app/lib/server/functions/notifications/email.js index b0953293ac73..89c6ac5ba197 100644 --- a/apps/meteor/app/lib/server/functions/notifications/email.js +++ b/apps/meteor/app/lib/server/functions/notifications/email.js @@ -1,4 +1,5 @@ import { escapeHTML } from '@rocket.chat/string-helpers'; +import emojione from 'emojione'; import { Meteor } from 'meteor/meteor'; import { callbacks } from '../../../../../lib/callbacks'; @@ -40,7 +41,7 @@ async function getEmailContent({ message, user, room }) { return header; } - let messageContent = escapeHTML(message.msg); + let messageContent = escapeHTML(emojione.shortnameToUnicode(message.msg)); if (message.t === 'e2e') { messageContent = i18n.t('Encrypted_message', { lng }); @@ -70,7 +71,7 @@ async function getEmailContent({ message, user, room }) { let content = `${escapeHTML(message.file.name)}`; if (message.attachments && message.attachments.length === 1 && message.attachments[0].description !== '') { - content += `

${escapeHTML(message.attachments[0].description)}`; + content += `

${escapeHTML(emojione.shortnameToUnicode(message.attachments[0].description))}`; } return `${fileHeader}:

${content}`; @@ -89,7 +90,7 @@ async function getEmailContent({ message, user, room }) { content += `${escapeHTML(attachment.title)}
`; } if (attachment.text) { - content += `${escapeHTML(attachment.text)}
`; + content += `${escapeHTML(emojione.shortnameToUnicode(attachment.text))}
`; } return `${header}:

${content}`; From bb6782d03780e47563a49611b94e55147a089aa2 Mon Sep 17 00:00:00 2001 From: gabriellsh <40830821+gabriellsh@users.noreply.github.com> Date: Wed, 13 Dec 2023 11:34:45 -0300 Subject: [PATCH 2/5] add cs --- .changeset/green-timers-cross.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/green-timers-cross.md diff --git a/.changeset/green-timers-cross.md b/.changeset/green-timers-cross.md new file mode 100644 index 000000000000..7af076cc0303 --- /dev/null +++ b/.changeset/green-timers-cross.md @@ -0,0 +1,5 @@ +--- +"@rocket.chat/meteor": patch +--- + +notification emails should now show emojis properly From 94e7cc0d7e81483fdb9e6f6eac7614ea1e5cb4d0 Mon Sep 17 00:00:00 2001 From: gabriellsh Date: Wed, 13 Dec 2023 15:25:09 -0300 Subject: [PATCH 3/5] only do it once --- .../lib/server/functions/notifications/email.js | 7 +++---- .../lib/server/lib/sendNotificationsOnMessage.js | 14 +++++++++++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/apps/meteor/app/lib/server/functions/notifications/email.js b/apps/meteor/app/lib/server/functions/notifications/email.js index 89c6ac5ba197..b0953293ac73 100644 --- a/apps/meteor/app/lib/server/functions/notifications/email.js +++ b/apps/meteor/app/lib/server/functions/notifications/email.js @@ -1,5 +1,4 @@ import { escapeHTML } from '@rocket.chat/string-helpers'; -import emojione from 'emojione'; import { Meteor } from 'meteor/meteor'; import { callbacks } from '../../../../../lib/callbacks'; @@ -41,7 +40,7 @@ async function getEmailContent({ message, user, room }) { return header; } - let messageContent = escapeHTML(emojione.shortnameToUnicode(message.msg)); + let messageContent = escapeHTML(message.msg); if (message.t === 'e2e') { messageContent = i18n.t('Encrypted_message', { lng }); @@ -71,7 +70,7 @@ async function getEmailContent({ message, user, room }) { let content = `${escapeHTML(message.file.name)}`; if (message.attachments && message.attachments.length === 1 && message.attachments[0].description !== '') { - content += `

${escapeHTML(emojione.shortnameToUnicode(message.attachments[0].description))}`; + content += `

${escapeHTML(message.attachments[0].description)}`; } return `${fileHeader}:

${content}`; @@ -90,7 +89,7 @@ async function getEmailContent({ message, user, room }) { content += `${escapeHTML(attachment.title)}
`; } if (attachment.text) { - content += `${escapeHTML(emojione.shortnameToUnicode(attachment.text))}
`; + content += `${escapeHTML(attachment.text)}
`; } return `${header}:

${content}`; diff --git a/apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.js b/apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.js index ce262e4e6756..05e9bf75d374 100644 --- a/apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.js +++ b/apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.js @@ -1,5 +1,6 @@ import { Room } from '@rocket.chat/core-services'; import { Subscriptions, Users } from '@rocket.chat/models'; +import emojione from 'emojione'; import { Meteor } from 'meteor/meteor'; import moment from 'moment'; @@ -142,12 +143,23 @@ export const sendNotification = async ({ isThread, }) ) { + const messageWithUnicode = emojione.shortnameToUnicode(message.msg); + const firstAttachment = message.attachments?.length > 0 && message.attachments.shift(); + firstAttachment.description = + typeof firstAttachment.description === 'string' ? emojione.shortnameToUnicode(firstAttachment.description) : undefined; + firstAttachment.text = typeof firstAttachment.text === 'string' ? emojione.shortnameToUnicode(firstAttachment.text) : undefined; + + const attachments = [firstAttachment, ...message.attachments].filter(Boolean); for await (const email of receiver.emails) { if (email.verified) { queueItems.push({ type: 'email', data: await getEmailData({ - message, + message: { + ...message, + msg: messageWithUnicode, + ...(attachments.length > 0 ? { attachments } : {}), + }, receiver, sender, subscription, From e6bb90945fe65034cb70259787b1b8088e9863cf Mon Sep 17 00:00:00 2001 From: gabriellsh Date: Wed, 13 Dec 2023 15:28:53 -0300 Subject: [PATCH 4/5] fix crash --- apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.js b/apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.js index 05e9bf75d374..ad9e34b33fb2 100644 --- a/apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.js +++ b/apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.js @@ -149,7 +149,7 @@ export const sendNotification = async ({ typeof firstAttachment.description === 'string' ? emojione.shortnameToUnicode(firstAttachment.description) : undefined; firstAttachment.text = typeof firstAttachment.text === 'string' ? emojione.shortnameToUnicode(firstAttachment.text) : undefined; - const attachments = [firstAttachment, ...message.attachments].filter(Boolean); + const attachments = firstAttachment ? [firstAttachment, ...message.attachments].filter(Boolean) : []; for await (const email of receiver.emails) { if (email.verified) { queueItems.push({ From de952f152ad767b8f5e985edd1637c1ffb8455bd Mon Sep 17 00:00:00 2001 From: gabriellsh Date: Fri, 19 Jan 2024 16:44:06 -0300 Subject: [PATCH 5/5] check if msg exists --- apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.js b/apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.js index 8fabb09ef94d..b3f7a11dc0d7 100644 --- a/apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.js +++ b/apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.js @@ -146,7 +146,7 @@ export const sendNotification = async ({ isThread, }) ) { - const messageWithUnicode = emojione.shortnameToUnicode(message.msg); + const messageWithUnicode = message.msg ? emojione.shortnameToUnicode(message.msg) : message.msg; const firstAttachment = message.attachments?.length > 0 && message.attachments.shift(); firstAttachment.description = typeof firstAttachment.description === 'string' ? emojione.shortnameToUnicode(firstAttachment.description) : undefined;