diff --git a/libs/flag.js b/libs/flag.js index eda73c0c1..81db8f53f 100644 --- a/libs/flag.js +++ b/libs/flag.js @@ -114,7 +114,9 @@ function getThreshold(aModel, aContent, aAuthor, aCallback) { } exports.getThreshold = getThreshold; -function saveContent(aModel, aContent, aAuthor, aFlags, aIsFlagging, aCallback) { +function saveContent(aModel, aContent, aAuthor, aWeight, aIsFlagging, aCallback) { + var weight = (aAuthor.role < 4 ? 2 : 1); + if (!aContent.flags) { aContent.flags = {}; } @@ -127,14 +129,14 @@ function saveContent(aModel, aContent, aAuthor, aFlags, aIsFlagging, aCallback) aContent.flags.absolute = 0; } - aContent.flags.critical += aFlags; + aContent.flags.critical += aWeight; if (aIsFlagging) { aContent.flags.absolute += - (aFlags > 0 ? 1 : (aFlags < 0 && aContent.flags.absolute !== 0 ? -1 : 0)); + (aWeight > 0 ? 1 : (aWeight < 0 && aContent.flags.absolute !== 0 ? -1 : 0)); } - if (aContent.flags.critical >= thresholds[aModel.modelName] * (aAuthor.role < 4 ? 2 : 1)) { + if (aContent.flags.critical >= thresholds[aModel.modelName] * weight) { return getThreshold(aModel, aContent, aAuthor, function (aThreshold) { aContent.flagged = aContent.flags.critical >= aThreshold; @@ -168,6 +170,7 @@ function flag(aModel, aContent, aUser, aAuthor, aReason, aCallback) { 'model': aModel.modelName, '_contentId': aContent._id, '_userId': aUser._id, + 'weight': aUser.role < 4 ? 2 : 1, 'reason': aReason, 'created': now }); @@ -191,7 +194,7 @@ function flag(aModel, aContent, aUser, aAuthor, aReason, aCallback) { aContent.flagged = false; } - saveContent(aModel, aContent, aAuthor, aUser.role < 4 ? 2 : 1, true, aCallback); + saveContent(aModel, aContent, aAuthor, aFlag.weight, true, aCallback); }); } @@ -238,7 +241,7 @@ exports.unflag = function (aModel, aContent, aUser, aReason, aCallback) { aFlag.remove(function (aErr) { // WARNING: No err handling - saveContent(aModel, aContent, aAuthor, aUser.role < 4 ? -2 : -1, true, aCallback); + saveContent(aModel, aContent, aAuthor, -aFlag.weight, true, aCallback); }); } diff --git a/models/flag.js b/models/flag.js index 4f234fc7c..822df48f2 100644 --- a/models/flag.js +++ b/models/flag.js @@ -14,6 +14,7 @@ var Schema = mongoose.Schema; var flagSchema = new Schema({ model: String, reason: String, + weight: Number, // Natural number with the role weight of User at time of flagging _contentId: Schema.Types.ObjectId, _userId: Schema.Types.ObjectId, diff --git a/package.json b/package.json index f921526f6..ce2059207 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "OpenUserJS.org", "description": "An open source user scripts repo built using Node.js", - "version": "0.5.1", + "version": "0.5.2", "main": "app", "dependencies": { "ace-builds": "1.4.12",