diff --git a/plugins/tiddlywiki/tiddlyweb/tiddlyweb.js b/plugins/tiddlywiki/tiddlyweb/tiddlyweb.js index 6d4e5d8bc..911d193b7 100644 --- a/plugins/tiddlywiki/tiddlyweb/tiddlyweb.js +++ b/plugins/tiddlywiki/tiddlyweb/tiddlyweb.js @@ -3,7 +3,7 @@ title: $:/plugins/tiddlywiki/tiddlyweb/tiddlyweb.js type: application/javascript module-type: syncer -Main TiddlyWeb integration module +Main TiddlyWeb syncer module \*/ (function(){ @@ -18,6 +18,10 @@ Creates a TiddlyWebSyncer object var TiddlyWebSyncer = function(options) { this.wiki = options.wiki; this.connection = undefined; + this.tiddlerInfo = {}; // Hashmap of {revision:,changeCount:} + // Tasks are {type: "load"/"save", title:, queueTime:, lastModificationTime:} + this.taskQueue = {}; // Hashmap of tasks to be performed + this.taskInProgress = {}; // Hashmap of tasks in progress }; TiddlyWebSyncer.titleIsLoggedIn = "$:/plugins/tiddlyweb/IsLoggedIn"; @@ -35,11 +39,11 @@ TiddlyWebSyncer.prototype.addConnection = function(connection) { var self = this; // Check if we've already got a connection if(this.connection) { - return Error("TiddlyWebSyncer can only handle a single connection"); + return new Error("TiddlyWebSyncer can only handle a single connection"); } // Check the connection has its constituent parts if(!connection.host || !connection.recipe) { - return Error("Missing connection data") + return new Error("Missing connection data"); } // Mark us as not logged in this.wiki.addTiddler({title: TiddlyWebSyncer.titleIsLoggedIn,text: "no"}); @@ -203,30 +207,36 @@ TiddlyWebSyncer.prototype.logout = function(options) { }; /* -Convert a TiddlyWeb JSON tiddler into a TiddlyWiki5 tiddler +Convert a TiddlyWeb JSON tiddler into a TiddlyWiki5 tiddler and save it in the store */ -TiddlyWebSyncer.prototype.convertTiddler = function(tiddlerFields) { +TiddlyWebSyncer.prototype.storeTiddler = function(tiddlerFields,revision) { var result = {}; // Transfer the fields, pulling down the `fields` hashmap - for(var f in tiddlerFields) { - switch(f) { + $tw.utils.each(tiddlerFields,function(element,title,object) { + switch(title) { case "fields": - for(var ff in tiddlerFields[f]) { - result[ff] = tiddlerFields[f][ff]; - } + $tw.utils.each(element,function(element,subTitle,object) { + result[subTitle] = element; + }); break; default: - result[f] = tiddlerFields[f]; + result[title] = tiddlerFields[title]; break; } - } + }); // Some unholy freaking of content types if(result.type === "text/javascript") { result.type = "application/javascript"; } else if(!result.type || result.type === "None") { result.type = "text/vnd.tiddlywiki2"; } - return result; + // Save the tiddler + this.wiki.addTiddler(new $tw.Tiddler(result)); + // Save the tiddler revision and changeCount details + this.tiddlerInfo[result.title] = { + revision: revision, + changeCount: this.wiki.getChangeCount(result.title) + }; }; /* @@ -243,7 +253,7 @@ console.log("error in syncFromServer",err); } var json = JSON.parse(data); for(var t=0; t