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/server/methods/loadMissedMessages.ts

37 lines
1.0 KiB

import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import type { IMessage, IRoom } from '@rocket.chat/core-typings';
import type { ServerMethods } from '@rocket.chat/ui-contexts';
import { Messages } from '@rocket.chat/models';
import { canAccessRoomIdAsync } from '../../app/authorization/server/functions/canAccessRoom';
declare module '@rocket.chat/ui-contexts' {
// eslint-disable-next-line @typescript-eslint/naming-convention
interface ServerMethods {
loadMissedMessages(rid: IRoom['_id'], ts: Date): Promise<false | IMessage[]>;
}
}
Meteor.methods<ServerMethods>({
async loadMissedMessages(rid, start) {
check(rid, String);
check(start, Date);
const fromId = Meteor.userId() ?? undefined;
if (!rid) {
throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'getUsersOfRoom' });
}
if (!(await canAccessRoomIdAsync(rid, fromId))) {
return false;
}
return Messages.findVisibleByRoomIdAfterTimestamp(rid, start, {
sort: {
ts: -1,
},
}).toArray();
},
});