mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: #7958, give rewards one by one
no need to check group.exists when leaving groups, if group doesn't exists isMember will be false anyways
This commit is contained in:
@@ -14,12 +14,9 @@ module.exports = function (Groups) {
|
|||||||
groupNames = [groupNames];
|
groupNames = [groupNames];
|
||||||
}
|
}
|
||||||
|
|
||||||
const [isMembers, exists] = await Promise.all([
|
const isMembers = await Groups.isMemberOfGroups(uid, groupNames);
|
||||||
Groups.isMemberOfGroups(uid, groupNames),
|
|
||||||
Groups.exists(groupNames),
|
|
||||||
]);
|
|
||||||
|
|
||||||
const groupsToLeave = groupNames.filter((groupName, index) => isMembers[index] && exists[index]);
|
const groupsToLeave = groupNames.filter((groupName, index) => isMembers[index]);
|
||||||
if (!groupsToLeave.length) {
|
if (!groupsToLeave.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -132,17 +132,16 @@ module.exports = function (Plugins) {
|
|||||||
if (!Array.isArray(hookList) || !hookList.length) {
|
if (!Array.isArray(hookList) || !hookList.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await async.each(hookList, function (hookObj, next) {
|
for (const hookObj of hookList) {
|
||||||
if (typeof hookObj.method !== 'function') {
|
if (typeof hookObj.method !== 'function') {
|
||||||
if (global.env === 'development') {
|
if (global.env === 'development') {
|
||||||
winston.warn('[plugins] Expected method for hook \'' + hook + '\' in plugin \'' + hookObj.id + '\' not found, skipping.');
|
winston.warn('[plugins] Expected method for hook \'' + hook + '\' in plugin \'' + hookObj.id + '\' not found, skipping.');
|
||||||
}
|
}
|
||||||
return next();
|
} else {
|
||||||
|
/* eslint-disable no-await-in-loop */
|
||||||
|
await hookObj.method(params);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
hookObj.method(params);
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fireStaticHook(hook, hookList, params) {
|
async function fireStaticHook(hook, hookList, params) {
|
||||||
|
|||||||
@@ -70,10 +70,11 @@ async function checkCondition(reward, method) {
|
|||||||
|
|
||||||
async function giveRewards(uid, rewards) {
|
async function giveRewards(uid, rewards) {
|
||||||
const rewardData = await getRewardsByRewardData(rewards);
|
const rewardData = await getRewardsByRewardData(rewards);
|
||||||
await Promise.all(rewards.map(async function (reward) {
|
for (let i = 0; i < rewards.length; i++) {
|
||||||
plugins.fireHook('action:rewards.award:' + reward.rid, { uid: uid, reward: rewardData[rewards.indexOf(reward)] });
|
/* eslint-disable no-await-in-loop */
|
||||||
await db.sortedSetIncrBy('uid:' + uid + ':rewards', 1, reward.id);
|
await plugins.fireHook('action:rewards.award:' + rewards[i].rid, { uid: uid, reward: rewardData[i] });
|
||||||
}));
|
await db.sortedSetIncrBy('uid:' + uid + ':rewards', 1, rewards[i].id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
require('../promisify')(rewards);
|
require('../promisify')(rewards);
|
||||||
|
|||||||
Reference in New Issue
Block a user