Fix #2136: update cache and group list when copying pads

This commit is contained in:
Marcel Klehr 2014-06-11 22:23:43 +02:00
parent cd294c608b
commit c4f9828825
1 changed files with 29 additions and 19 deletions

View File

@ -412,6 +412,7 @@ Pad.prototype.init = function init(text, callback) {
Pad.prototype.copy = function copy(destinationID, force, callback) { Pad.prototype.copy = function copy(destinationID, force, callback) {
var sourceID = this.id; var sourceID = this.id;
var _this = this; var _this = this;
var destGroupID;
// make force optional // make force optional
if (typeof force == "function") { if (typeof force == "function") {
@ -436,7 +437,8 @@ Pad.prototype.copy = function copy(destinationID, force, callback) {
{ {
if (destinationID.indexOf("$") != -1) if (destinationID.indexOf("$") != -1)
{ {
groupManager.doesGroupExist(destinationID.split("$")[0], function (err, exists) destGroupID = destinationID.split("$")[0]
groupManager.doesGroupExist(destGroupID, function (err, exists)
{ {
if(ERR(err, callback)) return; if(ERR(err, callback)) return;
@ -493,6 +495,7 @@ Pad.prototype.copy = function copy(destinationID, force, callback) {
db.get("pad:"+sourceID, function(err, pad) { db.get("pad:"+sourceID, function(err, pad) {
db.set("pad:"+destinationID, pad); db.set("pad:"+destinationID, pad);
}); });
callback(); callback();
}, },
//copy all relations //copy all relations
@ -547,6 +550,13 @@ Pad.prototype.copy = function copy(destinationID, force, callback) {
// parallel // parallel
], callback); ], callback);
}, },
function(callback) {
// Group pad? Add it to the group's list
if(destGroupID) db.setSub("group:" + destGroupID, ["pads", padID], 1);
// Initialize the new pad (will update the listAllPads cache)
padManager.getPad(destinationID, null, callback)
}
// series // series
], function(err) ], function(err)
{ {