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

51 lines
970 B

import _ from 'underscore';
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 options = {
sort: {
ts: 1,
},
limit,
};
if (!RocketChat.settings.get('Message_ShowEditedStatus')) {
options.fields = {
editedAt: 0,
};
}
let records;
if (end) {
records = RocketChat.models.Messages.findVisibleByRoomIdAfterTimestamp(rid, end, options).fetch();
} else {
records = RocketChat.models.Messages.findVisibleByRoomId(rid, options).fetch();
}
const messages = records.map((message) => {
message.starred = _.findWhere(message.starred, {
_id: fromId,
});
return message;
});
return {
messages,
};
},
});