introduce GlodaFolder class, still needs more lovin'
authorAndrew Sutherland <asutherland@asutherland.org>
Mon, 06 Oct 2008 13:45:59 -0700
changeset 957 c7cc67e37b99617ae7888b0acf93aa17e09cce9c
parent 956 6aecee406c684fe17fadba4794cf0fac922cbd7b
child 958 6dbc624a875bc399c8d6f552cb0650eeaca9f2e0
push idunknown
push userunknown
push dateunknown
introduce GlodaFolder class, still needs more lovin'
modules/datamodel.js
modules/gloda.js
--- a/modules/datamodel.js
+++ b/modules/datamodel.js
@@ -31,17 +31,17 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 EXPORTED_SYMBOLS = ["GlodaAttributeDef",
-                    "GlodaConversation", "GlodaMessage",
+                    "GlodaConversation", "GlodaFolder", "GlodaMessage",
                     "GlodaContact", "GlodaIdentity"];
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cr = Components.results;
 const Cu = Components.utils;
 
 Cu.import("resource://gloda/modules/log4moz.js");
@@ -307,16 +307,32 @@ GlodaConversation.prototype = {
     return this._messages;
   },
 
   toString: function gloda_conversation_toString() {
     return this._subject;
   },
 };
 
+function GlodaFolder(aDatastore, aID, aURI, aPrettyName) {
+  this._datastore = aDatastore;
+  this._id = aID;
+  this._uri = aURI;
+  this._prettyName = aPrettyName;
+}
+
+GlodaFolder.prototype = {
+ NOUN_ID: 100,
+ get id() { return this._id; },
+ get uri() { return this._uri; },
+  toString: function gloda_folder_toString() {
+    return this._prettyName;
+  }
+}
+
 /**
  * @class A message representation.
  */
 function GlodaMessage(aDatastore, aID, aFolderID, aMessageKey,
                       aConversationID, aConversation, aDate,
                       aHeaderMessageID, aDeleted) {
   this._datastore = aDatastore;
   this._id = aID;
--- a/modules/gloda.js
+++ b/modules/gloda.js
@@ -190,16 +190,22 @@ var Gloda = {
    *
    * @return the gloda messages that corresponds to the provided nsIMsgDBHdr
    *    if one exists, null if one cannot be found.
    */
   getMessageForHeader: function gloda_ns_getMessageForHeader(aMsgHdr) {
     return GlodaDatastore.getMessageFromLocation(aMsgHdr.folder.URI,
                                                  aMsgHdr.messageKey);
   },
+  
+  getFolderForFolder: function gloda_ns_getFolderForFolder(aMsgFolder) {
+    let uri = aMsgFolder.URI;
+    return new GlodaFolder(GlodaDatastore, GlodaDatastore._mapFolderURI(uri),
+                           uri, aMsgFolder.prettyName);
+  },
 
   /**
    * Given one or more full mail addresses (ex: "Bob Smith" <bob@smith.com>),
    *  return a list of the identities that corresponds to each mail address,
    *  creating them as required.
    */
   getIdentitiesForFullMailAddresses:
       function gloda_ns_getIdentitiesForMailAddresses(aMailAddresses) {
@@ -484,17 +490,17 @@ var Gloda = {
    * Doesn't actually work owing to a lack of an object to represent a folder.
    *  We do expose the folderURI and folderID of a message, but need to map that
    *  to a good abstraction.  Probably something thin around a SteelFolder or
    *  the like; we would contribute the functionality to easily move from a
    *  folder to the list of gloda messages in that folder, as well as the
    *  indexing preferences for that folder.
    * @TODO folder noun and related abstraction
    */
-  NOUN_FOLDER: 100,
+  NOUN_FOLDER: GlodaFolder.prototype.NOUN_ID, // 100
   /**
    * All messages belong to a conversation.  See datamodel.js for the
    *  definition of the GlodaConversation class.
    */
   NOUN_CONVERSATION: GlodaConversation.prototype.NOUN_ID, // 101
   /**
    * A one-to-one correspondence with underlying (indexed) nsIMsgDBHdr
    *  instances.  See datamodel.js for the definition of the GlodaMessage class.
@@ -743,23 +749,29 @@ var Gloda = {
         return aString;
       },
       toParamAndValue: function(aString) {
         return [null, aString];
       }}, this.NOUN_FULLTEXT);
 
     this.defineNoun({
       name: "folder",
-      class: null,
+      class: GlodaFolder,
       firstClass: false,
       fromParamAndValue: function(aParam, aID) {
+        // XXX map into folder-space rather than uri-space
+        // (this does not pose an immediate problem because folders are
+        //  currently special attributes because they are cols on message rows.)
         return GlodaDatastore._mapFolderID(aID);
       },
-      toParamAndValue: function(aFolderURI) {
-        return [null, GlodaDatastore._mapFolderURI(aFolderURI)];
+      toParamAndValue: function(aFolderOrURI) {
+        if (aFolderOrURI instanceof GlodaFolder)
+          return [null, aFolderOrURI.id];
+        else
+          return [null, GlodaDatastore._mapFolderURI(aFolderOrURI)];
       }}, this.NOUN_FOLDER);
     // TODO: use some form of (weak) caching layer... it is reasonably likely
     //  that there will be a high degree of correlation in many cases, and
     //  unless the UI is extremely clever and does its cleverness before
     //  examining the data, we will probably hit the correlation.
     this.defineNoun({
       name: "conversation",
       class: GlodaConversation,