import type { IMessage, IRoom } from '@rocket.chat/core-typings'; import type { ServerMethods } from '@rocket.chat/ddp-client'; import { Messages } from '@rocket.chat/models'; import { check } from 'meteor/check'; import { Meteor } from 'meteor/meteor'; import { canAccessRoomIdAsync } from '../../lib/authorization/canAccessRoom'; import { methodDeprecationLogger } from '../../lib/deprecationWarningLogger'; declare module '@rocket.chat/ddp-client' { // eslint-disable-next-line @typescript-eslint/naming-convention interface ServerMethods { loadMissedMessages(rid: IRoom['_id'], ts: Date): Promise; } } Meteor.methods({ async loadMissedMessages(rid, start) { methodDeprecationLogger.method('loadMissedMessages', '9.0.0', '/v1/chat.syncMessages'); 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, true, { sort: { ts: -1, }, }).toArray(); }, });