Skip to content

Commit

Permalink
fix: Message update being broadcasted without updated values (#32472)
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego authored May 27, 2024
1 parent 88d3114 commit cd96032
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/four-onions-camp.md
Original file line number Diff line number Diff line change
@@ -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.
22 changes: 13 additions & 9 deletions apps/meteor/app/lib/server/functions/updateMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
};

0 comments on commit cd96032

Please sign in to comment.