diff options
Diffstat (limited to 'src/node/db')
-rw-r--r-- | src/node/db/API.js | 32 | ||||
-rw-r--r-- | src/node/db/Pad.js | 13 |
2 files changed, 45 insertions, 0 deletions
diff --git a/src/node/db/API.js b/src/node/db/API.js index 87b6d747..237bcb0a 100644 --- a/src/node/db/API.js +++ b/src/node/db/API.js @@ -308,6 +308,38 @@ exports.setText = function(padID, text, callback) } /** +appendText(padID, text) appends text to a pad + +Example returns: + +{code: 0, message:"ok", data: null} +{code: 1, message:"padID does not exist", data: null} +{code: 1, message:"text too long", data: null} +*/ +exports.appendText = function(padID, text, callback) +{ + //text is required + if(typeof text != "string") + { + callback(new customError("text is no string","apierror")); + return; + } + + //get the pad + getPadSafe(padID, true, function(err, pad) + { + if(ERR(err, callback)) return; + + pad.appendText(text); + + //update the clients on the pad + padMessageHandler.updatePadClients(pad, callback); + }); +}; + + + +/** getHTML(padID, [rev]) returns the html of a pad Example returns: diff --git a/src/node/db/Pad.js b/src/node/db/Pad.js index eb6a3ed1..83e15e6d 100644 --- a/src/node/db/Pad.js +++ b/src/node/db/Pad.js @@ -303,6 +303,19 @@ Pad.prototype.setText = function setText(newText) { this.appendRevision(changeset); }; +Pad.prototype.appendText = function appendText(newText) { + //clean the new text + newText = exports.cleanText(newText); + + var oldText = this.text(); + + //create the changeset + var changeset = Changeset.makeSplice(oldText, oldText.length, 0, newText); + + //append the changeset + this.appendRevision(changeset); +}; + Pad.prototype.appendChatMessage = function appendChatMessage(text, userId, time) { this.chatHead++; //save the chat entry in the database |