diff --git a/.changeset/livechat-forward-ul-message.md b/.changeset/livechat-forward-ul-message.md new file mode 100644 index 0000000000000..afe2bee7c0222 --- /dev/null +++ b/.changeset/livechat-forward-ul-message.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/meteor': patch +--- + +Fixes an issue where the "user left" system message could be added to an Omnichannel conversation only after the forwarding process had already finished, causing it to appear out of order in the conversation history diff --git a/apps/meteor/server/lib/omnichannel/RoutingManager.ts b/apps/meteor/server/lib/omnichannel/RoutingManager.ts index 6a713f6e6ac6b..22ac84c72923c 100644 --- a/apps/meteor/server/lib/omnichannel/RoutingManager.ts +++ b/apps/meteor/server/lib/omnichannel/RoutingManager.ts @@ -371,12 +371,11 @@ export const RoutingManager: Routing = { async removeAllRoomSubscriptions(room, ignoreUser) { const { _id: roomId } = room; - const subscriptions = await Subscriptions.findByRoomId(roomId).toArray(); - subscriptions?.forEach(({ u }) => { - if (ignoreUser && ignoreUser._id === u._id) { - return; + for await (const { u } of Subscriptions.findByRoomId(roomId, { projection: { u: 1 } })) { + if (ignoreUser?._id === u._id) { + continue; } - void removeAgentFromSubscription(roomId, u); - }); + await removeAgentFromSubscription(roomId, u); + } }, };