parent
1131e0014c
commit
672fe95d7e
File diff suppressed because it is too large
Load Diff
@ -1,28 +1,22 @@ |
||||
import { Meteor } from 'meteor/meteor'; |
||||
import { check } from 'meteor/check'; |
||||
|
||||
import { Messages } from '../../../models'; |
||||
import { canAccessRoom } from '../../../authorization/server'; |
||||
import { Messages } from '../../../models/server'; |
||||
|
||||
Meteor.methods({ |
||||
getMessages(messages) { |
||||
check(messages, [String]); |
||||
|
||||
const cache = {}; |
||||
const msgs = Messages.findVisibleByIds(messages).fetch(); |
||||
|
||||
return messages.map((msgId) => { |
||||
const msg = Messages.findOneById(msgId); |
||||
const user = { _id: Meteor.userId() }; |
||||
|
||||
if (!msg || !msg.rid) { |
||||
return undefined; |
||||
} |
||||
const rids = [...new Set(msgs.map((m) => m.rid))]; |
||||
if (!rids.every((_id) => canAccessRoom({ _id }, user))) { |
||||
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'getSingleMessage' }); |
||||
} |
||||
|
||||
cache[msg.rid] = cache[msg.rid] || Meteor.call('canAccessRoom', msg.rid, Meteor.userId()); |
||||
|
||||
if (!cache[msg.rid]) { |
||||
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'getSingleMessage' }); |
||||
} |
||||
|
||||
return msg; |
||||
}); |
||||
return msgs; |
||||
}, |
||||
}); |
||||
|
||||
@ -1,3 +1,3 @@ |
||||
{ |
||||
"version": "4.1.0" |
||||
"version": "4.1.1" |
||||
} |
||||
|
||||
Loading…
Reference in new issue