Node.js based forum software built for the modern web
#5232, update flag history to save new value
Julian Lam169defd19476
diff --git a/src/flags.js b/src/flags.jsindex 54f6f0bd30..893bba4442 100644--- a/src/flags.js+++ b/src/flags.js@@ -290,14 +290,18 @@ Flags.targetExists = function (type, id, callback) {Flags.update = function (flagId, uid, changeset, callback) {// Retrieve existing flag data to compare for history-saving purposesvar fields = ['state', 'assignee'];+ var history = [];async.waterfall([async.apply(db.getObjectFields.bind(db), 'flag:' + flagId, fields),function (current, next) {- for(var prop in changeset) {+ for (var prop in changeset) {if (changeset.hasOwnProperty(prop)) {if (current[prop] === changeset[prop]) {delete changeset[prop];+ } else {+ // Append to history payload+ history.push(prop + ':' + changeset[prop]);}}}@@ -311,7 +315,7 @@ Flags.update = function (flagId, uid, changeset, callback) {// Save new object to db (upsert)async.apply(db.setObject, 'flag:' + flagId, changeset),// Append history- async.apply(Flags.appendHistory, flagId, uid, Object.keys(changeset))+ async.apply(Flags.appendHistory, flagId, uid, history)], function (err, data) {return next(err);});@@ -334,9 +338,18 @@ Flags.getHistory = function (flagId, callback) {uids.push(entry.value[0]);+ // Deserialise field object+ var fields = entry.value[1].map(function (field) {+ field = field.toString().split(':');+ return {+ "attribute": field[0],+ "value": field[1] === undefined ? null : field[1]+ };+ });+return {uid: entry.value[0],- fields: entry.value[1],+ fields: fields,datetime: entry.score,datetimeISO: new Date(entry.score).toISOString()};@@ -349,6 +362,7 @@ Flags.getHistory = function (flagId, callback) {return callback(err);}+ // Append user data to each history eventhistory = history.map(function (event, idx) {event.user = users[idx];return event;