changeset 297:37187074a143

make unsubscribing work again
author Myk Melez <myk@mozilla.org>
date Mon, 29 Sep 2008 17:00:41 -0700
parents 7c8e1c6430e0
children 7aac9baff8e5
files content/collections.js
diffstat 1 files changed, 25 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/content/collections.js	Mon Sep 29 16:54:19 2008 -0700
+++ b/content/collections.js	Mon Sep 29 17:00:41 2008 -0700
@@ -322,6 +322,31 @@
 this._log.info(row.value + " is selected");
 else
 this._log.info(row.value + " is not selected");
+  },
+
+  unsubscribe: function() {
+    let collection = this._rows[this._tree.currentIndex];
+
+    if (!collection.parent || collection.parent.groupIDColumn != "sources.id")
+      return;
+
+    let sourceID = this._rows[this._tree.currentIndex].groupID;
+
+    SnowlDatastore.dbConnection.beginTransaction();
+    try {
+      SnowlDatastore.dbConnection.executeSimpleSQL("DELETE FROM metadata WHERE messageID IN (SELECT id FROM messages WHERE sourceID = " + sourceID + ")");
+      SnowlDatastore.dbConnection.executeSimpleSQL("DELETE FROM parts WHERE messageID IN (SELECT id FROM messages WHERE sourceID = " + sourceID + ")");
+      SnowlDatastore.dbConnection.executeSimpleSQL("DELETE FROM messages WHERE sourceID = " + sourceID);
+      SnowlDatastore.dbConnection.executeSimpleSQL("DELETE FROM sources WHERE id = " + sourceID);
+      SnowlDatastore.dbConnection.commitTransaction();
+    }
+    catch(ex) {
+      SnowlDatastore.dbConnection.rollbackTransaction();
+      throw ex;
+    }
+
+    this._obsSvc.notifyObservers(null, "sources:changed", null);
+    this._obsSvc.notifyObservers(null, "messages:changed", null);
   }
 
 };