Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-Authored-By: Tasso Evangelista <tasso.evangelista@rocket.chat>
  • Loading branch information
ggazzo and tassoevan authored Oct 28, 2019
1 parent 06928f5 commit 436fad9
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/authorization/server/functions/canDeleteMessage.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { hasPermissionAsync } from './hasPermission';
import { getValue } from '../../../settings/server/raw';

const diff = (ts) => {
const elapsedTime = (ts) => {
const dif = Date.now() - ts;
return Math.round((dif / 1000) / 60);
};
Expand All @@ -13,7 +13,7 @@ export const canDeleteMessageAsync = async (uid, { u, rid, ts }) => {
return true;
}

if (ts == null) {
if (!ts) {
return false;
}
const deleteAllowed = await getValue('Message_AllowDeleting');
Expand All @@ -35,7 +35,8 @@ export const canDeleteMessageAsync = async (uid, { u, rid, ts }) => {
}

const currentTsDiff = diff(ts);
return currentTsDiff <= blockDeleteInMinutes;
const timeElapsedForMessage = elapsedTime(ts);
return timeElapsedForMessage <= blockDeleteInMinutes;
};

export const canDeleteMessage = (uid, { u, rid, ts }) => Promise.await(canDeleteMessageAsync(uid, { u, rid, ts }));

0 comments on commit 436fad9

Please sign in to comment.