From 9217c4fcf7c5cc6b5e71ee219e014e45fefd2238 Mon Sep 17 00:00:00 2001 From: gabriellsh <40830821+gabriellsh@users.noreply.github.com> Date: Mon, 22 Jan 2024 11:51:44 -0300 Subject: [PATCH] feat: Convert emoji shortname to unicode on notification emails. (#31225) --- .changeset/green-timers-cross.md | 5 +++++ .../lib/server/lib/sendNotificationsOnMessage.js | 14 +++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) 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 00000000000..7af076cc030 --- /dev/null +++ b/.changeset/green-timers-cross.md @@ -0,0 +1,5 @@ +--- +"@rocket.chat/meteor": patch +--- + +notification emails should now show emojis properly diff --git a/apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.js b/apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.js index 395ddfe6d46..b3f7a11dc0d 100644 --- a/apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.js +++ b/apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.js @@ -1,4 +1,5 @@ import { Subscriptions, Users } from '@rocket.chat/models'; +import emojione from 'emojione'; import moment from 'moment'; import { callbacks } from '../../../../lib/callbacks'; @@ -145,12 +146,23 @@ export const sendNotification = async ({ isThread, }) ) { + 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; + firstAttachment.text = typeof firstAttachment.text === 'string' ? emojione.shortnameToUnicode(firstAttachment.text) : undefined; + + const attachments = firstAttachment ? [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,