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); } }); };