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/client/lib/utils/canDeleteMessage.ts

42 lines
1.2 KiB

import { Meteor } from 'meteor/meteor';
import moment, { MomentInput } from 'moment';
import { hasPermission } from '../../../app/authorization/client';
import { settings } from '../../../app/settings/client';
import { IRoom } from '../../../definition/IRoom';
import { IUser } from '../../../definition/IUser';
export const canDeleteMessage = ({ rid, ts, uid }: { rid: IRoom['_id']; ts: MomentInput; uid: IUser['_id'] }): boolean => {
const userId = Meteor.userId();
const forceDelete = hasPermission('force-delete-message', rid);
if (forceDelete) {
return true;
}
const isDeleteAllowed: boolean | undefined = settings.get('Message_AllowDeleting');
if (!isDeleteAllowed) {
return false;
}
const allowed = hasPermission('delete-message', rid);
const deleteOwn = allowed || (uid === userId && hasPermission('delete-own-message'));
if (!allowed && !deleteOwn) {
return false;
}
const blockDeleteInMinutes: number | undefined = settings.get('Message_AllowDeleting_BlockDeleteInMinutes');
if (blockDeleteInMinutes && blockDeleteInMinutes !== 0) {
if (!ts) {
return false;
}
const msgTs = moment(ts);
const now = moment();
return now.diff(msgTs, 'minutes') < blockDeleteInMinutes;
}
return true;
};