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/app/threads/server/methods/getThreadMessages.js

38 lines
1.2 KiB

import { Meteor } from 'meteor/meteor';
import { Messages, Rooms } from '../../../models/server';
import { canAccessRoom } from '../../../authorization/server';
import { settings } from '../../../settings/server';
import { readThread } from '../functions';
const MAX_LIMIT = 100;
Meteor.methods({
getThreadMessages({ tmid, limit, skip }) {
if (limit > MAX_LIMIT) {
throw new Meteor.Error('error-not-allowed', `max limit: ${ MAX_LIMIT }`, { method: 'getThreadMessages' });
}
if (!Meteor.userId() || !settings.get('Threads_enabled')) {
throw new Meteor.Error('error-not-allowed', 'Threads Disabled', { method: 'getThreadMessages' });
}
const thread = Messages.findOneById(tmid);
if (!thread) {
return [];
}
const user = Meteor.user();
const room = Rooms.findOneById(thread.rid);
if (!canAccessRoom(room, user)) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'getThreadMessages' });
}
readThread({ userId: user._id, rid: thread.rid, tmid });
const result = Messages.findVisibleThreadByThreadId(tmid, { ...skip && { skip }, ...limit && { limit }, sort: { ts: -1 } }).fetch();
return [thread, ...result];
},
});