forked from nishant8BITS/Rocket.Chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloadNextMessages.js
More file actions
51 lines (42 loc) · 963 Bytes
/
loadNextMessages.js
File metadata and controls
51 lines (42 loc) · 963 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
};
}
});