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/methods/loadNextMessages.js

45 lines
981 B

import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import { Message } from '../sdk';
import { settings } from '../../app/settings';
import { normalizeMessagesForUser } from '../../app/utils/server/lib/normalizeMessagesForUser';
Meteor.methods({
loadNextMessages(rid, end, limit = 20) {
check(rid, String);
check(limit, Number);
if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: 'loadNextMessages',
});
}
const fromId = Meteor.userId();
if (!Meteor.call('canAccessRoom', rid, fromId)) {
return false;
}
const queryOptions = {
returnTotal: false,
sort: {
ts: 1,
},
limit,
};
if (!settings.get('Message_ShowEditedStatus')) {
queryOptions.fields = {
editedAt: 0,
};
}
const { records } = Promise.await(Message.get(fromId, { rid, oldest: end, queryOptions }));
return {
messages: normalizeMessagesForUser(records, fromId),
};
},
});