import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; import { canAccessRoomId } from '../../../authorization/server'; import { Messages } from '../../../models/server'; Meteor.methods({ getSingleMessage(msgId) { check(msgId, String); const uid = Meteor.userId(); if (!uid) { throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getSingleMessage' }); } const msg = Messages.findOneById(msgId); if (!msg || !msg.rid) { return undefined; } if (!canAccessRoomId(msg.rid, uid)) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'getSingleMessage' }); } return msg; }, });