mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-05 13:36:01 +01:00
change history saving to append an object not a serialised array, #5232
This commit is contained in:
39
src/flags.js
39
src/flags.js
@@ -422,7 +422,6 @@ Flags.getTargetUid = function (type, id, callback) {
|
|||||||
Flags.update = function (flagId, uid, changeset, callback) {
|
Flags.update = function (flagId, uid, changeset, callback) {
|
||||||
// Retrieve existing flag data to compare for history-saving purposes
|
// Retrieve existing flag data to compare for history-saving purposes
|
||||||
var fields = ['state', 'assignee'];
|
var fields = ['state', 'assignee'];
|
||||||
var history = [];
|
|
||||||
var tasks = [];
|
var tasks = [];
|
||||||
var now = Date.now();
|
var now = Date.now();
|
||||||
|
|
||||||
@@ -445,9 +444,6 @@ Flags.update = function (flagId, uid, changeset, callback) {
|
|||||||
tasks.push(async.apply(db.sortedSetAdd.bind(db), 'flags:byAssignee:' + changeset[prop], now, flagId));
|
tasks.push(async.apply(db.sortedSetAdd.bind(db), 'flags:byAssignee:' + changeset[prop], now, flagId));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append to history payload
|
|
||||||
history.push(prop + ':' + changeset[prop]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -460,7 +456,7 @@ Flags.update = function (flagId, uid, changeset, callback) {
|
|||||||
// Save new object to db (upsert)
|
// Save new object to db (upsert)
|
||||||
tasks.push(async.apply(db.setObject, 'flag:' + flagId, changeset));
|
tasks.push(async.apply(db.setObject, 'flag:' + flagId, changeset));
|
||||||
// Append history
|
// Append history
|
||||||
tasks.push(async.apply(Flags.appendHistory, flagId, uid, history));
|
tasks.push(async.apply(Flags.appendHistory, flagId, uid, changeset));
|
||||||
|
|
||||||
async.parallel(tasks, function (err, data) {
|
async.parallel(tasks, function (err, data) {
|
||||||
return next(err);
|
return next(err);
|
||||||
@@ -484,28 +480,21 @@ Flags.getHistory = function (flagId, callback) {
|
|||||||
|
|
||||||
uids.push(entry.value[0]);
|
uids.push(entry.value[0]);
|
||||||
|
|
||||||
// Deserialise field object
|
// Deserialise changeset
|
||||||
var fields = entry.value[1].map(function (field) {
|
var changeset = entry.value[1];
|
||||||
field = field.toString().split(':');
|
if (changeset.hasOwnProperty('state')) {
|
||||||
|
changeset.state = changeset.state === undefined ? '' : '[[flags:state-' + changeset.state + ']]';
|
||||||
switch (field[0]) {
|
}
|
||||||
case 'state':
|
if (changeset.hasOwnProperty('assignee')) {
|
||||||
field[1] = field[1] === undefined ? null : '[[flags:state-' + field[1] + ']]';
|
changeset.assignee = changeset.assignee || '';
|
||||||
break;
|
}
|
||||||
|
if (changeset.hasOwnProperty('notes')) {
|
||||||
default:
|
changeset.notes = changeset.notes || '';
|
||||||
field[1] = field[1] === undefined ? null : field[1];
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return {
|
|
||||||
"attribute": field[0],
|
|
||||||
"value": field[1]
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
uid: entry.value[0],
|
uid: entry.value[0],
|
||||||
fields: fields,
|
fields: changeset,
|
||||||
datetime: entry.score,
|
datetime: entry.score,
|
||||||
datetimeISO: new Date(entry.score).toISOString()
|
datetimeISO: new Date(entry.score).toISOString()
|
||||||
};
|
};
|
||||||
@@ -549,7 +538,9 @@ Flags.appendNote = function (flagId, uid, note, callback) {
|
|||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
async.apply(db.sortedSetAdd, 'flag:' + flagId + ':notes', Date.now(), payload),
|
async.apply(db.sortedSetAdd, 'flag:' + flagId + ':notes', Date.now(), payload),
|
||||||
async.apply(Flags.appendHistory, flagId, uid, ['notes'])
|
async.apply(Flags.appendHistory, flagId, uid, {
|
||||||
|
notes: null
|
||||||
|
})
|
||||||
], callback);
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user