feat: ability to mute users

new mute privilege
This commit is contained in:
Barış Soner Uşaklı
2022-03-11 23:07:20 -05:00
parent feaf3068f8
commit be6bbabd0e
18 changed files with 256 additions and 14 deletions

View File

@@ -18,7 +18,7 @@ module.exports = function (User) {
return;
}
const [userData, isAdminOrMod] = await Promise.all([
User.getUserFields(uid, ['uid', 'banned', 'joindate', 'email', 'reputation'].concat([field])),
User.getUserFields(uid, ['uid', 'banned', 'mutedUntil', 'joindate', 'email', 'reputation'].concat([field])),
privileges.categories.isAdminOrMod(cid, uid),
]);
@@ -35,6 +35,16 @@ module.exports = function (User) {
}
const now = Date.now();
if (userData.mutedUntil > now) {
let muteLeft = ((userData.mutedUntil - now) / (1000 * 60));
if (muteLeft > 60) {
muteLeft = (muteLeft / 60).toFixed(0);
throw new Error(`[[error:user-muted-for-hours, ${muteLeft}]]`);
} else {
throw new Error(`[[error:user-muted-for-minutes, ${muteLeft.toFixed(0)}]]`);
}
}
if (now - userData.joindate < meta.config.initialPostDelay * 1000) {
throw new Error(`[[error:user-too-new, ${meta.config.initialPostDelay}]]`);
}