-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Expand file tree
/
Copy pathgoToRoomById.ts
More file actions
30 lines (23 loc) · 1.01 KB
/
goToRoomById.ts
File metadata and controls
30 lines (23 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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);
};