Skip to content

Node.js based forum software built for the modern web

wait for state to be updated

Barış Soner Uşaklı67bc58f04cd7
diff --git a/src/flags.js b/src/flags.js
index 209a5166d5..df6ec625f3 100644
--- a/src/flags.js
+++ b/src/flags.js
@@ -370,9 +370,11 @@ Flags.create = function (type, id, uid, reason, timestamp, callback) {
if (targetUid) {
tasks.push(async.apply(db.sortedSetAdd.bind(db), 'flags:byTargetUid:' + targetUid, timestamp, flagId)); // by target uid
}
+
if (targetCid) {
tasks.push(async.apply(db.sortedSetAdd.bind(db), 'flags:byCid:' + targetCid, timestamp, flagId)); // by target cid
}
+
if (type === 'post') {
tasks.push(async.apply(db.sortedSetAdd.bind(db), 'flags:byPid:' + id, timestamp, flagId)); // by target pid
if (targetUid) {
@@ -381,16 +383,12 @@ Flags.create = function (type, id, uid, reason, timestamp, callback) {
}
}
- async.parallel(tasks, function (err) {
- if (err) {
- return next(err);
- }
-
- if (doHistoryAppend) {
- Flags.update(flagId, uid, { state: 'open' });
- }
+ if (doHistoryAppend) {
+ tasks.push(async.apply(Flags.update, flagId, uid, { state: 'open' }));
+ }
- next(null, flagId);
+ async.parallel(tasks, function (err) {
+ next(err, flagId);
});
},
async.apply(Flags.get),