mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-27 01:39:53 +01:00
fix: #8287, fix users:flags as well
This commit is contained in:
@@ -296,8 +296,7 @@ Flags.create = async function (type, id, uid, reason, timestamp) {
|
|||||||
if (type === 'post') {
|
if (type === 'post') {
|
||||||
await db.sortedSetAdd('flags:byPid:' + id, timestamp, flagId); // by target pid
|
await db.sortedSetAdd('flags:byPid:' + id, timestamp, flagId); // by target pid
|
||||||
if (targetUid) {
|
if (targetUid) {
|
||||||
await db.sortedSetIncrBy('users:flags', 1, targetUid);
|
await user.incrementUserFlagsBy(targetUid, 1);
|
||||||
await user.incrementUserFieldBy(targetUid, 'flags', 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ module.exports = {
|
|||||||
'users:joindate',
|
'users:joindate',
|
||||||
'users:reputation',
|
'users:reputation',
|
||||||
'users:postcount',
|
'users:postcount',
|
||||||
|
'users:flags',
|
||||||
], 'null');
|
], 'null');
|
||||||
|
|
||||||
await batch.processArray(allUids, async function (uids) {
|
await batch.processArray(allUids, async function (uids) {
|
||||||
@@ -34,6 +35,7 @@ module.exports = {
|
|||||||
'users:joindate',
|
'users:joindate',
|
||||||
'users:reputation',
|
'users:reputation',
|
||||||
'users:postcount',
|
'users:postcount',
|
||||||
|
'users:flags',
|
||||||
], uids[index]);
|
], uids[index]);
|
||||||
if (userData && !userData.uid) {
|
if (userData && !userData.uid) {
|
||||||
await db.delete('user:' + uids[index]);
|
await db.delete('user:' + uids[index]);
|
||||||
@@ -46,6 +48,9 @@ module.exports = {
|
|||||||
['users:reputation', userData.reputation, uids[index]],
|
['users:reputation', userData.reputation, uids[index]],
|
||||||
['users:postcount', userData.postcount, uids[index]],
|
['users:postcount', userData.postcount, uids[index]],
|
||||||
]);
|
]);
|
||||||
|
if (userData.hasOwnProperty('flags') && parseInt(userData.flags, 10) > 0) {
|
||||||
|
await db.sortedSetAdd('users:flags', userData.flags, uids[index]);
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
}, {
|
}, {
|
||||||
progress: progress,
|
progress: progress,
|
||||||
|
|||||||
@@ -74,6 +74,10 @@ module.exports = function (User) {
|
|||||||
return await incrementUserFieldAndSetBy(uid, 'reputation', 'users:reputation', value);
|
return await incrementUserFieldAndSetBy(uid, 'reputation', 'users:reputation', value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
User.incrementUserFlagsBy = async function (uid, value) {
|
||||||
|
return await incrementUserFieldAndSetBy(uid, 'flags', 'users:flags', value);
|
||||||
|
};
|
||||||
|
|
||||||
async function incrementUserFieldAndSetBy(uid, field, set, value) {
|
async function incrementUserFieldAndSetBy(uid, field, set, value) {
|
||||||
value = parseInt(value, 10);
|
value = parseInt(value, 10);
|
||||||
if (!value || !field || !(parseInt(uid, 10) > 0)) {
|
if (!value || !field || !(parseInt(uid, 10) > 0)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user