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/server/lib/messages/getMessageForUser.ts

21 lines
623 B

import type { IUser } from '../../../definition/IUser';
import type { IMessage } from '../../../definition/IMessage/IMessage';
import { Messages } from '../../../app/models/server/raw';
import { canAccessRoomId } from '../../../app/authorization/server';
export async function getMessageForUser(messageId: IMessage['_id'], uid: IUser['_id']): Promise<IMessage | undefined> {
if (!uid) {
throw new Error('error-invalid-user');
}
const message = await Messages.findOne(messageId);
if (!message) {
return;
}
if (!canAccessRoomId(message.rid, uid)) {
throw new Error('error-not-allowed');
}
return message;
}