From c96da54a5603c9f6c7858265f3714f8c7e13f713 Mon Sep 17 00:00:00 2001 From: Filipe Marins Date: Tue, 3 May 2022 12:58:10 -0300 Subject: [PATCH 1/2] fix: add await to room coordinator --- apps/meteor/app/ui-utils/client/lib/openRoom.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/meteor/app/ui-utils/client/lib/openRoom.js b/apps/meteor/app/ui-utils/client/lib/openRoom.js index 212f63391d00..747f9d36b3c4 100644 --- a/apps/meteor/app/ui-utils/client/lib/openRoom.js +++ b/apps/meteor/app/ui-utils/client/lib/openRoom.js @@ -37,7 +37,7 @@ export const openRoom = async function (type, name, render = true) { } try { - const room = roomCoordinator.getRoomDirectives(type)?.findRoom(name) || (await call('getRoomByTypeAndName', type, name)); + const room = (await roomCoordinator.getRoomDirectives(type)?.findRoom(name)) || (await call('getRoomByTypeAndName', type, name)); Rooms.upsert({ _id: room._id }, _.omit(room, '_id')); if (room._id !== name && type === 'd') { From 6c10ebf8242582407d7ea25c00dc9c62d4bf13d8 Mon Sep 17 00:00:00 2001 From: Filipe Marins Date: Tue, 3 May 2022 16:34:17 -0300 Subject: [PATCH 2/2] fix: remove await and add after flush --- .../meteor/app/ui-utils/client/lib/openRoom.js | 4 ++-- apps/meteor/app/ui/client/views/app/room.js | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/apps/meteor/app/ui-utils/client/lib/openRoom.js b/apps/meteor/app/ui-utils/client/lib/openRoom.js index 747f9d36b3c4..03bd35c48a67 100644 --- a/apps/meteor/app/ui-utils/client/lib/openRoom.js +++ b/apps/meteor/app/ui-utils/client/lib/openRoom.js @@ -37,7 +37,7 @@ export const openRoom = async function (type, name, render = true) { } try { - const room = (await roomCoordinator.getRoomDirectives(type)?.findRoom(name)) || (await call('getRoomByTypeAndName', type, name)); + const room = roomCoordinator.getRoomDirectives(type)?.findRoom(name) || (await call('getRoomByTypeAndName', type, name)); Rooms.upsert({ _id: room._id }, _.omit(room, '_id')); if (room._id !== name && type === 'd') { @@ -72,7 +72,7 @@ export const openRoom = async function (type, name, render = true) { // update user's room subscription const sub = ChatSubscription.findOne({ rid: room._id }); if (sub && sub.open === false) { - callWithErrorHandling('openRoom', room._id); + await callWithErrorHandling('openRoom', room._id); } if (FlowRouter.getQueryParam('msg')) { diff --git a/apps/meteor/app/ui/client/views/app/room.js b/apps/meteor/app/ui/client/views/app/room.js index dddbed3f4ce4..7087e7a148e2 100644 --- a/apps/meteor/app/ui/client/views/app/room.js +++ b/apps/meteor/app/ui/client/views/app/room.js @@ -934,16 +934,18 @@ Meteor.startup(() => { }, 500); this.autorun(() => { - if (rid !== Session.get('openedRoom')) { - return; - } + Tracker.afterFlush(() => { + if (rid !== Session.get('openedRoom')) { + return; + } - let room = Rooms.findOne({ _id: rid }, { fields: { t: 1 } }); + let room = Rooms.findOne({ _id: rid }, { fields: { t: 1 } }); - if (room?.t === 'l') { - room = Tracker.nonreactive(() => Rooms.findOne({ _id: rid })); - roomCoordinator.getRoomDirectives(room.t)?.openCustomProfileTab(this, room, room.v.username); - } + if (room?.t === 'l') { + room = Tracker.nonreactive(() => Rooms.findOne({ _id: rid })); + roomCoordinator.getRoomDirectives(room.t)?.openCustomProfileTab(this, room, room.v.username); + } + }); }); this.autorun(() => {