improve the mailing list support
authorBryan Clark <clarkbw@gnome.org>
Thu, 29 Jan 2009 19:31:31 -0800
changeset 39 939023071b01c2414c30a84bb9fdddc4cd7f8ccb
parent 38 0531a755d4ccc40d32108cefc524af156c93a1aa
child 40 7a6e90715442dfd6dcd80d098e88ec54d42480a8
push id1
push userroot
push dateWed, 08 Apr 2009 01:46:05 +0000
improve the mailing list support use the list id as the box display name, with the actual name in larger spaced areas better list id matching for the by_list_id view better display name for the mailing list facet
client/bubbles.xml
client/index.xhtml
server/python/junius/model.py
--- a/client/bubbles.xml
+++ b/client/bubbles.xml
@@ -139,16 +139,20 @@
           return this._discussion;
         },
         _getAttr : function(attr) {
           return this._discussion[attr];
         },
         getName: function() {
           return this._getAttr("name");
         },
+        getListId: function() {
+          /* fake the real "List-Id" since we've done some clean up before */
+          return this.getName() + " " + "<" + this._getAttr("id") + ">";
+        },
         setDiscussion: function(aDiscussion) {
           this._discussion = aDiscussion;
-          this.shadowTree.getElementById("discussion").textContent = this.getName();
+          this.shadowTree.getElementById("discussion").textContent = this.getListId();
         }
       })
     ]]></xbl:implementation>
   </xbl:binding>
 </xbl:xbl>
--- a/client/index.xhtml
+++ b/client/index.xhtml
@@ -72,27 +72,27 @@
         group : true,
         success: function(json) {
           var parent = $("#discussion");
           json.rows.forEach(function(row) {
             var li = $(document.createElement("li")).addClass("discussion-list");
             parent.append(li
                           .append($(document.createElement("a"))
                                             .addClass("discussion-list")
-                                            .attr("title", row.key["name"] + " (" + row.value + ")")
-                                            .attr("href","#/discussion/" + row.key["id"])
+                                            .attr("title", row.value["name"] + " (" + row.value["count"] + ")\n" + row.value["id"])
+                                            .attr("href","#/discussion/" + row.key)
                                             .mousedown(function() { 
                                                           var c = document.getElementById("constraints"); 
                                                           c.clear(); 
-                                                          c.addDiscussion(row.key);
+                                                          c.addDiscussion(row.value);
                                                           var query = document.getElementById("query");
                                                           query.updateConstraints(c);
                                                         }
                                                       )
-                                            .text(row.key["name"] + " (" + row.value + ")")
+                                            .text(row.value["id"] + " (" + row.value["count"] + ")")
                                             )
                                   );
           });
         }
       });
       
     }
 
--- a/server/python/junius/model.py
+++ b/server/python/junius/model.py
@@ -187,35 +187,42 @@ class Message(schema.Document):
             if (doc.timestamp)
                 emit([doc.account_id, doc.storage_path, doc.storage_id], null);
         }''', include_docs=False)
         
     by_mailing_list = schema.View('by_header_id', '''\
         function(doc) {
           if (doc.headers && doc.headers["List-Id"]) {
             var parts = doc.headers["List-Id"].match(/([\W\w]*)\s*<(.+)>.*/);
-            var keys = {"List-Id" : doc.headers["List-Id"],
-                         "id" : parts[2],
-                         "name" : parts[1] };
+            var values = {"List-Id" : doc.headers["List-Id"],
+                          "id" : parts[2],
+                          "name" : parts[1] };
             for each (var headerId in ["List-Post","List-Archive","List-Help",
                                        "List-Subscribe","List-Unsubscribe"]) {
               if (doc.headers[headerId])
-                keys[headerId] = doc.headers[headerId];
+                values[headerId] = doc.headers[headerId];
             }
-            emit(keys, 1);
+            emit(parts[2], values);
           }
         }''', '''\
         function(keys, values, rereduce) {
-          return sum(values);
+          var output = {};
+          output.count = values.length;
+          for (var idx in values) {
+            for (var elm in values[idx]) {
+              output[elm] = values[idx][elm];
+            }
+          }
+          return output;
         }''', include_docs=False, group=True, group_level=1)
 
     by_list_id = schema.View('by_mailing_list', '''\
         function(doc) {
           if (doc.headers && doc.headers["List-Id"]) {
-            var parts = doc.headers["List-Id"].match(/[\W\w]\s*<(.+)>.*/);
+            var parts = doc.headers["List-Id"].match(/[\W\w\s]*<(.+)>.*/);
             emit([parts[1], doc.timestamp], doc.conversation_id);
           }
         }''', include_docs=True)    
         
 DATABASES = {
     # the app database proper, no real data
     'junius': None,
     #