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/loadHistory.coffee

41 lines
1.2 KiB

Meteor.methods
loadHistory: (rid, end, limit=20, ls) ->
if not Meteor.userId()
throw new Meteor.Error 'error-invalid-user', 'Invalid user', { method: 'loadHistory' }
fromId = Meteor.userId()
unless Meteor.call 'canAccessRoom', rid, fromId
return false
options =
sort:
ts: -1
limit: limit
if not RocketChat.settings.get 'Message_ShowEditedStatus'
options.fields = { 'editedAt': 0 }
if end?
records = RocketChat.models.Messages.findVisibleByRoomIdBeforeTimestamp(rid, end, options).fetch()
else
records = RocketChat.models.Messages.findVisibleByRoomId(rid, options).fetch()
messages = _.map records, (message) ->
message.starred = _.findWhere message.starred, { _id: fromId }
return message
unreadNotLoaded = 0
if ls?
firstMessage = messages[messages.length - 1]
if firstMessage?.ts > ls
delete options.limit
unreadMessages = RocketChat.models.Messages.findVisibleByRoomIdBetweenTimestamps(rid, ls, firstMessage.ts, { limit: 1, sort: { ts: 1 } })
firstUnread = unreadMessages.fetch()[0]
unreadNotLoaded = unreadMessages.count()
return {
messages: messages
firstUnread: firstUnread
unreadNotLoaded: unreadNotLoaded
}