The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/client/lib/utils/goToRoomById.ts

30 lines
1.0 KiB

import type { IRoom } from '@rocket.chat/core-typings';
import { memoize } from '@rocket.chat/memo';
import { callWithErrorHandling } from './callWithErrorHandling';
import { router } from '../../providers/RouterProvider';
import { Subscriptions } from '../../stores';
import { roomCoordinator } from '../rooms/roomCoordinator';
const getRoomById = memoize((rid: IRoom['_id']) => callWithErrorHandling('getRoomById', rid));
export type GoToRoomByIdOptions = {
replace?: boolean;
routeParamsOverrides?: Record<string, string>;
};
export const goToRoomById = async (rid: IRoom['_id'], options: GoToRoomByIdOptions = {}): Promise<void> => {
if (!rid) {
return;
}
const subscription = Subscriptions.state.find((record) => record.rid === rid);
if (subscription) {
roomCoordinator.openRouteLink(subscription.t, subscription, router.getSearchParameters(), options);
return;
}
const room = await getRoomById(rid);
roomCoordinator.openRouteLink(room.t, { rid: room._id, ...room }, router.getSearchParameters(), options);
};