Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/hip-hornets-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

fixed `room-opened` event not dispatching when navigating cached rooms
8 changes: 6 additions & 2 deletions apps/meteor/client/views/room/hooks/useOpenRoom.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { IRoom, RoomType } from '@rocket.chat/core-typings';
import { useMethod, useRoute, useSetting, useUser } from '@rocket.chat/ui-contexts';
import { useQuery } from '@tanstack/react-query';
import { useRef } from 'react';

import { ChatRoom, ChatSubscription } from '../../../../app/models/client';
import { LegacyRoomManager } from '../../../../app/ui-utils/client';
Expand All @@ -20,6 +21,8 @@ export function useOpenRoom({ type, reference }: { type: RoomType; reference: st
const openRoom = useMethod('openRoom');
const directRoute = useRoute('direct');

const unsubscribeFromRoomOpenedEvent = useRef<() => void>(() => undefined);

return useQuery(
// we need to add uid and username here because `user` is not loaded all at once (see UserProvider -> Meteor.user())
['rooms', { type, reference }, { uid: user?._id, username: user?.username }] as const,
Expand Down Expand Up @@ -63,14 +66,15 @@ export function useOpenRoom({ type, reference }: { type: RoomType; reference: st
throw new RoomNotFoundError(undefined, { rid: room._id });
}

unsubscribeFromRoomOpenedEvent.current();
unsubscribeFromRoomOpenedEvent.current = RoomManager.once('opened', () => fireGlobalEvent('room-opened', omit(room, 'usernames')));

LegacyRoomManager.open({ typeName: type + reference, rid: room._id });

if (room._id === RoomManager.opened) {
return { rid: room._id };
}

fireGlobalEvent('room-opened', omit(room, 'usernames'));

// update user's room subscription
const sub = ChatSubscription.findOne({ rid: room._id });
if (sub && !sub.open) {
Expand Down