verdnatura-chat/app/lib/methods/getRoomInfo.ts

38 lines
843 B
TypeScript

import { IServerSubscription, RoomType } from '../../definitions';
import { getSubscriptionByRoomId } from '../database/services/Subscription';
import RocketChat from '../rocketchat';
export interface IRoomInfoResult {
rid: IServerSubscription['rid'];
name: IServerSubscription['name'];
fname: IServerSubscription['fname'];
t: IServerSubscription['t'];
}
const getRoomInfo = async (rid: string): Promise<IRoomInfoResult | null> => {
let result;
result = await getSubscriptionByRoomId(rid);
if (result) {
return {
rid,
name: result.name,
fname: result.fname,
t: result.t as RoomType
};
}
result = await RocketChat.getRoomInfo(rid);
if (result?.success) {
return {
rid,
name: result.room.name as string,
fname: result.room.fname,
t: result.room.t
};
}
return null;
};
export default getRoomInfo;