2022-06-06 14:17:51 +00:00
|
|
|
import log from './helpers/log';
|
2022-11-29 16:26:58 +00:00
|
|
|
import { IMessage, TSubscriptionModel } from '../../definitions';
|
2022-04-07 16:53:07 +00:00
|
|
|
import { store } from '../store/auxStore';
|
2022-04-04 19:15:29 +00:00
|
|
|
import { isGroupChat } from './helpers';
|
2022-04-28 20:37:25 +00:00
|
|
|
import { getRoom } from './getRoom';
|
2022-04-04 19:15:29 +00:00
|
|
|
|
|
|
|
type TRoomType = 'p' | 'c' | 'd';
|
|
|
|
|
2022-11-29 16:26:58 +00:00
|
|
|
export async function getPermalinkMessage(message: IMessage): Promise<string | null> {
|
2022-04-04 19:15:29 +00:00
|
|
|
let room: TSubscriptionModel;
|
|
|
|
try {
|
2022-11-29 16:26:58 +00:00
|
|
|
room = await getRoom(message.rid);
|
2022-04-04 19:15:29 +00:00
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
const { server } = store.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}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getPermalinkChannel(channel: TSubscriptionModel): string {
|
|
|
|
const { server } = store.getState().server;
|
|
|
|
const roomType = {
|
|
|
|
p: 'group',
|
|
|
|
c: 'channel',
|
|
|
|
d: 'direct'
|
|
|
|
};
|
|
|
|
|
|
|
|
// @ts-ignore - wrong SubscriptionType
|
|
|
|
const room = roomType[channel.t];
|
|
|
|
|
|
|
|
return `${server}/${room}/${channel.name}`;
|
|
|
|
}
|