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/getPermaLink.ts

38 lines
1.1 KiB

import type { IMessage, Serialized } from '@rocket.chat/core-typings';
import { getUserId } from './user';
const getMessage = async (msgId: string): Promise<Serialized<IMessage> | null> => {
try {
const { sdk } = await import('../../app/utils/client/lib/SDKClient');
const { message } = await sdk.rest.get('/v1/chat.getMessage', { msgId });
return message;
} catch {
return null;
}
};
export const getPermaLink = async (msgId: string): Promise<string> => {
if (!msgId) {
throw new Error('invalid-parameter');
}
const { Messages, Rooms, Subscriptions } = await import('../stores');
const msg = Messages.state.get(msgId) || (await getMessage(msgId));
if (!msg) {
throw new Error('message-not-found');
}
const roomData = Rooms.state.get(msg.rid);
if (!roomData) {
throw new Error('room-not-found');
}
const subData = Subscriptions.state.find((record) => record.rid === roomData._id && record.u._id === getUserId());
const { roomCoordinator } = await import('./rooms/roomCoordinator');
const roomURL = roomCoordinator.getURL(roomData.t, { ...(subData || roomData), tab: '' });
return `${roomURL}?msg=${msgId}`;
};