From 5a9d2a6ac8335ea4f033cc49d78b448e9324cce0 Mon Sep 17 00:00:00 2001 From: Jed Schaaf Date: Fri, 31 Jan 2020 22:58:45 -0500 Subject: [PATCH 1/4] Show ID for downvotes from users in group Public Downvoters. --- plugins/nodebb-plugin-tdwtf-customizations/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/nodebb-plugin-tdwtf-customizations/index.js b/plugins/nodebb-plugin-tdwtf-customizations/index.js index 165d152..058315a 100644 --- a/plugins/nodebb-plugin-tdwtf-customizations/index.js +++ b/plugins/nodebb-plugin-tdwtf-customizations/index.js @@ -43,7 +43,11 @@ SocketPosts.getVoters = async function (socket, data) { // TDWTF: Added: if (!isAdminOrMod) { - downvoteUids = Array(downvoteUids.length).fill(14); + for (i = 0; i < downvoteUids.length; ++i) { + if (!Groups.isMember(downvoteUids[i], 'Public Downvoters', done)) { + downvoteUids[i] = 14; + } + } } // End Added From 314e23a7e4c6600f1f9b4ff3bd53c3330c17aeba Mon Sep 17 00:00:00 2001 From: Jed Schaaf Date: Sat, 1 Feb 2020 00:16:56 -0500 Subject: [PATCH 2/4] Show ID for downvotes from users in group Public Downvoters. --- plugins/nodebb-plugin-tdwtf-customizations/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/nodebb-plugin-tdwtf-customizations/index.js b/plugins/nodebb-plugin-tdwtf-customizations/index.js index 058315a..5b285a4 100644 --- a/plugins/nodebb-plugin-tdwtf-customizations/index.js +++ b/plugins/nodebb-plugin-tdwtf-customizations/index.js @@ -44,7 +44,13 @@ SocketPosts.getVoters = async function (socket, data) { // TDWTF: Added: if (!isAdminOrMod) { for (i = 0; i < downvoteUids.length; ++i) { - if (!Groups.isMember(downvoteUids[i], 'Public Downvoters', done)) { + if (!Groups.isMember(downvoteUids[i], + 'Public Downvoters', + function(err, isMember) { + if (err) { return false; } + else { return isMember; } + }) + ) { downvoteUids[i] = 14; } } From 79aebdf5d317ef68aa4b5e2a5b2b52b02958f8ec Mon Sep 17 00:00:00 2001 From: Jed Schaaf Date: Sat, 1 Feb 2020 01:41:39 -0500 Subject: [PATCH 3/4] Show ID for downvotes from users in group Public Downvoters. Uses async map to resolve all downvoter IDs. --- .../index.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/plugins/nodebb-plugin-tdwtf-customizations/index.js b/plugins/nodebb-plugin-tdwtf-customizations/index.js index 5b285a4..926392d 100644 --- a/plugins/nodebb-plugin-tdwtf-customizations/index.js +++ b/plugins/nodebb-plugin-tdwtf-customizations/index.js @@ -43,17 +43,14 @@ SocketPosts.getVoters = async function (socket, data) { // TDWTF: Added: if (!isAdminOrMod) { - for (i = 0; i < downvoteUids.length; ++i) { - if (!Groups.isMember(downvoteUids[i], - 'Public Downvoters', - function(err, isMember) { - if (err) { return false; } - else { return isMember; } - }) - ) { - downvoteUids[i] = 14; - } - } + downvoteUids = await Promise.all(downvoteUids.map(async voterUid => { + const isPublicDownvoter = await Groups.isMember(voterUid, 'Public Downvoters', function(err, isMember) { + if (err) { return false; } + else { return isMember; } + }); + if (!isPublicDownvoter) { return 14; } + else { return voterUid; } + })); } // End Added From acbbe4922cd9b2af636710ea1d4a7dca5215b749 Mon Sep 17 00:00:00 2001 From: Jed Schaaf Date: Sat, 1 Feb 2020 18:18:20 -0500 Subject: [PATCH 4/4] Show ID for downvotes from users in group Public Downvoters. Use async map to resolve all downvoter IDs. Reduce complexity. --- plugins/nodebb-plugin-tdwtf-customizations/index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/nodebb-plugin-tdwtf-customizations/index.js b/plugins/nodebb-plugin-tdwtf-customizations/index.js index 926392d..5e355c2 100644 --- a/plugins/nodebb-plugin-tdwtf-customizations/index.js +++ b/plugins/nodebb-plugin-tdwtf-customizations/index.js @@ -43,11 +43,12 @@ SocketPosts.getVoters = async function (socket, data) { // TDWTF: Added: if (!isAdminOrMod) { + function coerceErrorToBool(err, value) { + if (err) { return false; } + else { return !!value; } + } downvoteUids = await Promise.all(downvoteUids.map(async voterUid => { - const isPublicDownvoter = await Groups.isMember(voterUid, 'Public Downvoters', function(err, isMember) { - if (err) { return false; } - else { return isMember; } - }); + const isPublicDownvoter = await Groups.isMember(voterUid, 'Public Downvoters', coerceErrorToBool); if (!isPublicDownvoter) { return 14; } else { return voterUid; } }));