From a79df25823eca1f8d24600c146779f89089907bc Mon Sep 17 00:00:00 2001 From: Filipe Marins Date: Mon, 18 Apr 2022 12:07:17 -0300 Subject: [PATCH 1/2] refactor: load from server all chatsubscription before open room --- apps/meteor/app/ui-utils/client/lib/openRoom.js | 3 ++- 1 file changed, 2 insertions(+), 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 8699d91202bb..e3f00d82f710 100644 --- a/apps/meteor/app/ui-utils/client/lib/openRoom.js +++ b/apps/meteor/app/ui-utils/client/lib/openRoom.js @@ -12,7 +12,7 @@ import { callWithErrorHandling } from '../../../../client/lib/utils/callWithErro import { call } from '../../../../client/lib/utils/call'; import { RoomManager, RoomHistoryManager } from '..'; import { RoomManager as NewRoomManager } from '../../../../client/lib/RoomManager'; -import { Rooms } from '../../../models/client'; +import { CachedChatSubscription, Rooms } from '../../../models/client'; import { fireGlobalEvent } from '../../../../client/lib/utils/fireGlobalEvent'; import { roomCoordinator } from '../../../../client/lib/rooms/roomCoordinator'; @@ -96,6 +96,7 @@ export const openRoom = async function (type, name, render = true) { if (type === 'd') { try { const { rid } = await call('createDirectMessage', ...name.split(', ')); + CachedChatSubscription.loadFromServerAndPopulate(); return FlowRouter.go('direct', { rid }, FlowRouter.current().queryParams); } catch (error) { console.error(error); From 94398e086af0cf568b40e6dbb4fe35b669a6263c Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Wed, 20 Apr 2022 18:47:56 -0300 Subject: [PATCH 2/2] Fix review --- apps/meteor/app/ui-utils/client/lib/openRoom.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/meteor/app/ui-utils/client/lib/openRoom.js b/apps/meteor/app/ui-utils/client/lib/openRoom.js index e3f00d82f710..212f63391d00 100644 --- a/apps/meteor/app/ui-utils/client/lib/openRoom.js +++ b/apps/meteor/app/ui-utils/client/lib/openRoom.js @@ -5,6 +5,7 @@ import { Session } from 'meteor/session'; import _ from 'underscore'; import { appLayout } from '../../../../client/lib/appLayout'; +import { waitUntilFind } from '../../../../client/lib/utils/waitUntilFind'; import { Messages, ChatSubscription } from '../../../models'; import { settings } from '../../../settings'; import { callbacks } from '../../../../lib/callbacks'; @@ -12,7 +13,7 @@ import { callWithErrorHandling } from '../../../../client/lib/utils/callWithErro import { call } from '../../../../client/lib/utils/call'; import { RoomManager, RoomHistoryManager } from '..'; import { RoomManager as NewRoomManager } from '../../../../client/lib/RoomManager'; -import { CachedChatSubscription, Rooms } from '../../../models/client'; +import { Rooms, Subscriptions } from '../../../models/client'; import { fireGlobalEvent } from '../../../../client/lib/utils/fireGlobalEvent'; import { roomCoordinator } from '../../../../client/lib/rooms/roomCoordinator'; @@ -96,7 +97,7 @@ export const openRoom = async function (type, name, render = true) { if (type === 'd') { try { const { rid } = await call('createDirectMessage', ...name.split(', ')); - CachedChatSubscription.loadFromServerAndPopulate(); + await waitUntilFind(() => Subscriptions.findOne({ rid })); return FlowRouter.go('direct', { rid }, FlowRouter.current().queryParams); } catch (error) { console.error(error);