diff --git a/src/flags.js b/src/flags.js index a50ea54973..02e7fdeaad 100644 --- a/src/flags.js +++ b/src/flags.js @@ -336,7 +336,10 @@ Flags.create = function (type, id, uid, reason, timestamp, callback) { 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 uid + 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 } async.parallel(tasks, function (err, data) { diff --git a/test/flags.js b/test/flags.js index 9df1a11a2b..af53b61271 100644 --- a/test/flags.js +++ b/test/flags.js @@ -80,6 +80,14 @@ describe('Flags', function () { done(); }); }); + + it('should add the flag to the byPid zset for pid 1 if it is of type post', function (done) { + db.isSortedSetMember('flags:byPid:' + 1, 1, function (err, isMember) { + assert.ifError(err); + assert.ok(isMember); + done(); + }); + }); }); describe('.exists()', function () {