From 9acdc6808c070555352951c651921df181b10993 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Sun, 15 May 2022 21:49:27 -0400 Subject: [PATCH] feat: allow unban/unmute on flag details page. closes #10593 --- public/src/client/account/header.js | 18 ++++++++++++------ public/src/client/flags/detail.js | 8 ++++++++ src/posts/user.js | 2 +- src/user/data.js | 4 ++++ 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/public/src/client/account/header.js b/public/src/client/account/header.js index e11f6373d7..ed443cf81a 100644 --- a/public/src/client/account/header.js +++ b/public/src/client/account/header.js @@ -57,8 +57,12 @@ define('forum/account/header', [ components.get('account/mute').on('click', function () { muteAccount(ajaxify.data.theirid); }); - components.get('account/unban').on('click', unbanAccount); - components.get('account/unmute').on('click', unmuteAccount); + components.get('account/unban').on('click', function () { + unbanAccount(ajaxify.data.theirid); + }); + components.get('account/unmute').on('click', function () { + unmuteAccount(ajaxify.data.theirid); + }); components.get('account/delete-account').on('click', handleDeleteEvent.bind(null, 'account')); components.get('account/delete-content').on('click', handleDeleteEvent.bind(null, 'content')); components.get('account/delete-all').on('click', handleDeleteEvent.bind(null, 'purge')); @@ -73,6 +77,8 @@ define('forum/account/header', [ // TODO: This exported method is used in forum/flags/detail -- refactor?? AccountHeader.banAccount = banAccount; AccountHeader.muteAccount = muteAccount; + AccountHeader.unbanAccount = unbanAccount; + AccountHeader.unmuteAccount = unmuteAccount; function hidePrivateLinks() { if (!app.user.uid || app.user.uid !== parseInt(ajaxify.data.theirid, 10)) { @@ -176,8 +182,8 @@ define('forum/account/header', [ }); } - function unbanAccount() { - api.del('/users/' + ajaxify.data.theirid + '/ban').then(() => { + function unbanAccount(theirid) { + api.del('/users/' + theirid + '/ban').then(() => { ajaxify.refresh(); }).catch(alerts.error); } @@ -223,8 +229,8 @@ define('forum/account/header', [ }); } - function unmuteAccount() { - api.del('/users/' + ajaxify.data.theirid + '/mute').then(() => { + function unmuteAccount(theirid) { + api.del('/users/' + theirid + '/mute').then(() => { ajaxify.refresh(); }).catch(alerts.error); } diff --git a/public/src/client/flags/detail.js b/public/src/client/flags/detail.js index c55269e3ca..fdffc096f2 100644 --- a/public/src/client/flags/detail.js +++ b/public/src/client/flags/detail.js @@ -69,10 +69,18 @@ define('forum/flags/detail', [ AccountHeader.banAccount(uid, ajaxify.refresh); break; + case 'unban': + AccountHeader.unbanAccount(uid); + break; + case 'mute': AccountHeader.muteAccount(uid, ajaxify.refresh); break; + case 'unmute': + AccountHeader.unmuteAccount(uid); + break; + case 'delete-account': AccountsDelete.account(uid, ajaxify.refresh); break; diff --git a/src/posts/user.js b/src/posts/user.js index e0964bc8c3..960e4960a6 100644 --- a/src/posts/user.js +++ b/src/posts/user.js @@ -104,7 +104,7 @@ module.exports = function (Posts) { 'uid', 'username', 'fullname', 'userslug', 'reputation', 'postcount', 'topiccount', 'picture', 'signature', 'banned', 'banned:expire', 'status', - 'lastonline', 'groupTitle', + 'lastonline', 'groupTitle', 'mutedUntil', ]; const result = await plugins.hooks.fire('filter:posts.addUserFields', { fields: fields, diff --git a/src/user/data.js b/src/user/data.js index a58b95669a..c1e218613f 100644 --- a/src/user/data.js +++ b/src/user/data.js @@ -252,6 +252,10 @@ module.exports = function (User) { user.banned = false; } } + + if (user.hasOwnProperty('mutedUntil')) { + user.muted = user.mutedUntil > Date.now(); + } })); return await plugins.hooks.fire('filter:users.get', users);