From cd960325a0b9c3c715b7c085bf3a92579701312f Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Mon, 27 May 2024 14:30:58 -0300 Subject: [PATCH] fix: Message update being broadcasted without updated values (#32472) --- .changeset/four-onions-camp.md | 5 +++++ .../app/lib/server/functions/updateMessage.ts | 22 +++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 .changeset/four-onions-camp.md diff --git a/.changeset/four-onions-camp.md b/.changeset/four-onions-camp.md new file mode 100644 index 000000000000..8068ac023638 --- /dev/null +++ b/.changeset/four-onions-camp.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/meteor': patch +--- + +When using `DISABLE_DB_WATCHERS=true` this fixes message updates with URLs that were missing the link preview. diff --git a/apps/meteor/app/lib/server/functions/updateMessage.ts b/apps/meteor/app/lib/server/functions/updateMessage.ts index 8327b0892b26..2954517fb018 100644 --- a/apps/meteor/app/lib/server/functions/updateMessage.ts +++ b/apps/meteor/app/lib/server/functions/updateMessage.ts @@ -94,17 +94,21 @@ export const updateMessage = async function ( setImmediate(async () => { const msg = await Messages.findOneById(_id); - if (msg) { - await callbacks.run('afterSaveMessage', msg, room, user._id); + if (!msg) { + return; + } + + // although this is an "afterSave" kind callback, we know they can extend message's properties + // so we wait for it to run before broadcasting + const data = await callbacks.run('afterSaveMessage', msg, room, user._id); - void broadcastMessageFromData({ - id: msg._id, - data: msg, - }); + void broadcastMessageFromData({ + id: msg._id, + data: data as any, // TODO move "afterSaveMessage" type definition to specify a return value + }); - if (room?.lastMessage?._id === msg._id) { - void notifyOnRoomChangedById(message.rid); - } + if (room?.lastMessage?._id === msg._id) { + void notifyOnRoomChangedById(message.rid); } }); };