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];
|
||||
}
|
||||
|
||||
const [isMembers, exists] = await Promise.all([
|
||||
Groups.isMemberOfGroups(uid, groupNames),
|
||||
Groups.exists(groupNames),
|
||||
]);
|
||||
const isMembers = await Groups.isMemberOfGroups(uid, groupNames);
|
||||
|
||||
const groupsToLeave = groupNames.filter((groupName, index) => isMembers[index] && exists[index]);
|
||||
const groupsToLeave = groupNames.filter((groupName, index) => isMembers[index]);
|
||||
if (!groupsToLeave.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -132,17 +132,16 @@ module.exports = function (Plugins) {
|
||||
if (!Array.isArray(hookList) || !hookList.length) {
|
||||
return;
|
||||
}
|
||||
await async.each(hookList, function (hookObj, next) {
|
||||
for (const hookObj of hookList) {
|
||||
if (typeof hookObj.method !== 'function') {
|
||||
if (global.env === 'development') {
|
||||
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) {
|
||||
|
||||
@@ -70,10 +70,11 @@ async function checkCondition(reward, method) {
|
||||
|
||||
async function giveRewards(uid, rewards) {
|
||||
const rewardData = await getRewardsByRewardData(rewards);
|
||||
await Promise.all(rewards.map(async function (reward) {
|
||||
plugins.fireHook('action:rewards.award:' + reward.rid, { uid: uid, reward: rewardData[rewards.indexOf(reward)] });
|
||||
await db.sortedSetIncrBy('uid:' + uid + ':rewards', 1, reward.id);
|
||||
}));
|
||||
for (let i = 0; i < rewards.length; i++) {
|
||||
/* eslint-disable no-await-in-loop */
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user