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/app/lib/server/methods/deleteMessage.js

40 lines
940 B

import { Meteor } from 'meteor/meteor';
import { Match, check } from 'meteor/check';
import { canDeleteMessage } from '../../../authorization/server/functions/canDeleteMessage';
import { Messages } from '../../../models';
import { deleteMessage } from '../functions';
Meteor.methods({
deleteMessage(message) {
check(message, Match.ObjectIncluding({
_id: String,
}));
const uid = Meteor.userId();
if (!uid) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: 'deleteMessage',
});
}
const originalMessage = Messages.findOneById(message._id, {
fields: {
u: 1,
rid: 1,
file: 1,
ts: 1,
},
});
if (!originalMessage || !canDeleteMessage(uid, originalMessage)) {
throw new Meteor.Error('error-action-not-allowed', 'Not allowed', {
method: 'deleteMessage',
action: 'Delete_message',
});
}
return deleteMessage(originalMessage, Meteor.user());
},
});