Skip to content

Commit

Permalink
chore: Make room closing process more sequential (RocketChat#31435)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevLehman authored Jan 12, 2024
1 parent 3021180 commit dd2967c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 4 additions & 0 deletions apps/meteor/app/livechat/server/api/v1/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,10 @@ API.v1.addRoute(
throw new Error('error-invalid-room');
}

if (!room.open) {
throw new Error('room-closed');
}

if (!(await Omnichannel.isWithinMACLimit(room))) {
throw new Error('error-mac-limit-reached');
}
Expand Down
16 changes: 11 additions & 5 deletions apps/meteor/app/livechat/server/lib/LivechatTyped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,17 @@ class LivechatClass {

this.logger.debug(`Updating DB for room ${room._id} with close data`);

await Promise.all([
LivechatRooms.closeRoomById(rid, closeData),
LivechatInquiry.removeByRoomId(rid),
Subscriptions.removeByRoomId(rid),
]);
const removedInquiry = await LivechatInquiry.removeByRoomId(rid);
if (removedInquiry && removedInquiry.deletedCount !== 1) {
throw new Error('Error removing inquiry');
}

const updatedRoom = await LivechatRooms.closeRoomById(rid, closeData);
if (!updatedRoom || updatedRoom.modifiedCount !== 1) {
throw new Error('Error closing room');
}

await Subscriptions.removeByRoomId(rid);

this.logger.debug(`DB updated for room ${room._id}`);

Expand Down

0 comments on commit dd2967c

Please sign in to comment.