2022-02-10 12:10:42 +00:00
|
|
|
import log from '../../../utils/log';
|
|
|
|
import { TMessageModel, TSubscriptionModel } from '../../../definitions';
|
|
|
|
import reduxStore from '../../createStore';
|
|
|
|
import getRoom from './getRoom';
|
|
|
|
import isGroupChat from './isGroupChat';
|
|
|
|
|
|
|
|
type TRoomType = 'p' | 'c' | 'd';
|
|
|
|
|
|
|
|
export default async function getPermalinkMessage(message: TMessageModel): Promise<string | null> {
|
2022-02-17 00:07:24 +00:00
|
|
|
if (!message.subscription) return null;
|
2022-02-10 12:10:42 +00:00
|
|
|
let room: TSubscriptionModel;
|
|
|
|
try {
|
|
|
|
room = await getRoom(message.subscription.id);
|
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
const { server } = reduxStore.getState().server;
|
|
|
|
const roomType = {
|
|
|
|
p: 'group',
|
|
|
|
c: 'channel',
|
|
|
|
d: 'direct'
|
|
|
|
}[room.t as TRoomType];
|
|
|
|
return `${server}/${roomType}/${isGroupChat(room) ? room.rid : room.name}?msg=${message.id}`;
|
|
|
|
}
|