Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/bandwagon/components/bandwagon-service.js
diff options
context:
space:
mode:
Diffstat (limited to 'bandwagon/components/bandwagon-service.js')
-rw-r--r--bandwagon/components/bandwagon-service.js492
1 files changed, 346 insertions, 146 deletions
diff --git a/bandwagon/components/bandwagon-service.js b/bandwagon/components/bandwagon-service.js
index 3a773fc..7ddb6b6 100644
--- a/bandwagon/components/bandwagon-service.js
+++ b/bandwagon/components/bandwagon-service.js
@@ -14,11 +14,11 @@
* The Original Code is bandwagon.
*
* The Initial Developer of the Original Code is
- * David McNamara.
+ * Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2008
* the Initial Developer. All Rights Reserved.
*
- * Contributor(s):
+ * Contributor(s): David McNamara
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@@ -48,6 +48,7 @@ const ExtensionsManager = Cc["@mozilla.org/extensions/manager;1"];
const Storage = Cc["@mozilla.org/storage/service;1"];
const DirectoryService = Cc["@mozilla.org/file/directory_service;1"];
const ObserverService = Cc["@mozilla.org/observer-service;1"];
+const CookieManager = Cc["@mozilla.org/cookiemanager;1"];
const nsIWindowMediator = Ci.nsIWindowMediator;
const nsITimer = Ci.nsITimer;
@@ -56,6 +57,7 @@ const mozIStorageService = Ci.mozIStorageService;
const nsIProperties = Ci.nsIProperties;
const nsIFile = Ci.nsIFile;
const nsIObserverService = Ci.nsIObserverService;
+const nsICookieManager = Ci.nsICookieManager;
var Bandwagon;
@@ -68,16 +70,17 @@ function BandwagonService()
BandwagonService.prototype = {
- feeds: {},
+ collections: {},
_initialized: false,
_service: null,
- _feedUpdateObservers: [],
- _feedListChangeObservers: [],
+ _collectionUpdateObservers: [],
+ _collectionListChangeObservers: [],
_storageConnection: null,
- _feedFactory: null,
- _feedUpdateTimer: null,
+ _collectionFactory: null,
+ _collectionUpdateTimer: null,
_bwObserver: null,
+ _serviceDocument: null,
init: function()
{
@@ -103,9 +106,10 @@ BandwagonService.prototype = {
this._service = new Bandwagon.RPC.Service();
this._service.registerLogger(Bandwagon.Logger);
- this._service.registerObserver(this._getFeedObserver);
+ this._service.registerObserver(this._getCollectionObserver);
+ this._service.registerObserver(this._getServiceDocumentObserver);
- this.registerFeedUpdateObserver(this._feedUpdateObserver);
+ this.registerCollectionUpdateObserver(this._collectionUpdateObserver);
// init sqlite storage (also creating tables in sqlite if needed). create factory objects.
@@ -119,15 +123,24 @@ BandwagonService.prototype = {
this.firstrun();
}
- // storage initialized, tables created - open the feeds
+ // storage initialized, tables created - open the collections
- var storageFeeds = this._feedFactory.openFeeds();
+ var storageCollections = this._collectionFactory.openCollections();
- for (var id in storageFeeds)
+ for (var id in storageCollections)
{
- this.feeds[id] = storageFeeds[id];
- this.feeds[id].setAllNotified();
- Bandwagon.Logger.debug("opened feed from storage: " + id);
+ this.collections[id] = storageCollections[id];
+ this.collections[id].setAllNotified();
+ Bandwagon.Logger.debug("opened collection from storage: " + id);
+ }
+
+ this._serviceDocument = this._collectionFactory.openServiceDocument();
+ this._service._serviceDocument = this._serviceDocument;
+
+ if (!this._serviceDocument)
+ {
+ // no service document in storage, we never had it or we've lost it - go fetch it
+ this.updateCollectionsList();
}
// start the update timer
@@ -147,10 +160,10 @@ BandwagonService.prototype = {
}
};
- this._feedUpdateTimer = Timer.createInstance(nsITimer);
- this._feedUpdateTimer.init(
+ this._collectionUpdateTimer = Timer.createInstance(nsITimer);
+ this._collectionUpdateTimer.init(
this._bwObserver,
- (Bandwagon.Preferences.getPreference("debug")?30*1000:Bandwagon.FEED_UPDATE_TIMER_DELAY*1000),
+ (Bandwagon.Preferences.getPreference("debug")?30*1000:Bandwagon.COLLECTION_UPDATE_TIMER_DELAY*1000),
nsITimer.TYPE_REPEATING_SLACK
);
@@ -169,7 +182,7 @@ BandwagonService.prototype = {
uninit: function()
{
- this._feedUpdateTimer = null;
+ this._collectionUpdateTimer = null;
this.commitAll();
},
@@ -205,14 +218,14 @@ BandwagonService.prototype = {
Bandwagon.Logger.debug("Will autopublish extension '" + willAutopublishExtensions[i].id + "'...");
// publish willAutopublishExtensions[i]
- for (var id in bandwagonService.feeds)
+ for (var id in bandwagonService.collections)
{
- var feed = bandwagonService.feeds[id];
+ var collection = bandwagonService.collections[id];
- if (!feed.autoPublish)
+ if (!collection.autoPublish)
continue;
- Bandwagon.Logger.debug("...to feed '" + feed.url + "'");
+ Bandwagon.Logger.debug("...to collection '" + collection.resourceURL + "'");
var extension =
{
@@ -220,7 +233,7 @@ BandwagonService.prototype = {
name: willAutopublishExtensions[i].name
}
- bandwagonService.publishToFeed(extension, feed, "", null);
+ bandwagonService.publishToCollection(extension, collection, "", null);
}
// add to autopublish
@@ -231,13 +244,13 @@ BandwagonService.prototype = {
}
},
- _getFeedObserver: function(event)
+ _getCollectionObserver: function(event)
{
- Bandwagon.Logger.info("in _getFeedObserver()");
+ Bandwagon.Logger.info("in _getCollectionObserver()");
- if (event.getType() == Bandwagon.RPC.Constants.BANDWAGON_RPC_EVENT_TYPE_BANDWAGON_RPC_GET_FEED_COMPLETE)
+ if (event.getType() == Bandwagon.RPC.Constants.BANDWAGON_RPC_EVENT_TYPE_BANDWAGON_RPC_GET_COLLECTION_COMPLETE)
{
- var feed = event.feed;
+ var collection = event.collection;
if (event.isError())
{
@@ -246,84 +259,169 @@ BandwagonService.prototype = {
}
else
{
- if (feed != null && feed.url != null)
+ if (collection != null && collection.resourceURL != null)
{
- Bandwagon.Logger.info("Finished getting updates for feed '" + feed.url + "'");
- bandwagonService.feeds[feed.url] = feed;
+ Bandwagon.Logger.info("Finished getting updates for collection '" + collection.resourceURL + "'");
+ bandwagonService.collections[collection.resourceURL] = collection;
}
}
// we want to notify the observers even if there's been an error
- bandwagonService._notifyFeedUpdateObservers(feed);
+ bandwagonService._notifyCollectionUpdateObservers(collection);
}
},
- _notifyFeedUpdateObservers: function(feed)
+ _getServiceDocumentObserver: function(event)
{
- Bandwagon.Logger.debug("Notifying feed update observers");
+ Bandwagon.Logger.info("in _getServiceDocumentObserver()");
- for (var i=0; i<bandwagonService._feedUpdateObservers.length; i++)
+ if (event.getType() == Bandwagon.RPC.Constants.BANDWAGON_RPC_EVENT_TYPE_BANDWAGON_RPC_GET_SERVICE_DOCUMENT_COMPLETE)
{
- if (bandwagonService._feedUpdateObservers[i])
+ if (event.isError())
{
- bandwagonService._feedUpdateObservers[i](feed);
+ Bandwagon.Logger.error("Could not update collections list: " + event.getError().toString());
+ }
+ else
+ {
+ bandwagonService._serviceDocument = event.serviceDocument;
+ bandwagonService._service._serviceDocument = bandwagonService._serviceDocument;
+
+ var collections = bandwagonService._serviceDocument.collections;
+
+ Bandwagon.Logger.debug("Updating collections list: saw " + collections.length + " collections");
+
+ for (var id in bandwagonService.collections)
+ {
+ var isStaleCollection = true;
+
+ for (var jd in collections)
+ {
+ if (bandwagonService.collections[id].equals(collections[jd]))
+ {
+ isStaleCollection = false;
+ break;
+ }
+ }
+
+ if (isStaleCollection)
+ {
+ Bandwagon.Logger.debug("Updating collections list: removing stale collection: " + bandwagonService.collections[id].toString());
+
+ bandwagonService.deleteCollection(bandwagonService.collections[id]);
+ }
+ }
+
+ for (var id in collections)
+ {
+ var collection = collections[id];
+
+ if (bandwagonService.collections[collection.resourceURL])
+ {
+ // we have already added this collection
+ }
+ else
+ {
+ // this is a new collection
+ Bandwagon.Logger.debug("Updating collections list: adding new collection: " + collection.toString());
+
+ bandwagonService.collections[collection.resourceURL] = collection;
+
+ bandwagonService.forceCheckForUpdates(collection);
+ }
+ }
+
+ bandwagonService._notifyListChangeObservers();
+
+ if (Bandwagon.COMMIT_NOW)
+ bandwagonService.commitAll();
}
}
},
- registerFeedUpdateObserver: function(observer)
+ _notifyCollectionUpdateObservers: function(collection)
{
- Bandwagon.Logger.debug("Registering feed update observer");
- this._feedUpdateObservers.push(observer);
+ Bandwagon.Logger.debug("Notifying collection update observers");
+
+ for (var i=0; i<bandwagonService._collectionUpdateObservers.length; i++)
+ {
+ if (bandwagonService._collectionUpdateObservers[i])
+ {
+ bandwagonService._collectionUpdateObservers[i](collection);
+ }
+ }
},
- unregisterFeedUpdateObserver: function(observer)
+ registerCollectionUpdateObserver: function(observer)
{
- Bandwagon.Logger.debug("Unregistering feed update observer");
+ Bandwagon.Logger.debug("Registering collection update observer");
+ this._collectionUpdateObservers.push(observer);
+ },
- for (var i=0; i<this._feedUpdateObservers.length; i++)
+ unregisterCollectionUpdateObserver: function(observer)
+ {
+ Bandwagon.Logger.debug("Unregistering collection update observer");
+
+ for (var i=0; i<this._collectionUpdateObservers.length; i++)
{
- if (this._feedUpdateObservers[i] == observer)
+ if (this._collectionUpdateObservers[i] == observer)
{
- delete this._feedUpdateObservers[i];
+ delete this._collectionUpdateObservers[i];
}
}
},
_notifyListChangeObservers: function()
{
- Bandwagon.Logger.debug("Notifying feed list change observers");
+ Bandwagon.Logger.debug("Notifying collection list change observers");
- for (var i=0; i<bandwagonService._feedListChangeObservers.length; i++)
+ for (var i=0; i<bandwagonService._collectionListChangeObservers.length; i++)
{
- if (bandwagonService._feedListChangeObservers[i])
+ if (bandwagonService._collectionListChangeObservers[i])
{
- bandwagonService._feedListChangeObservers[i]();
+ bandwagonService._collectionListChangeObservers[i]();
}
}
},
- registerFeedListChangeObserver: function(observer)
+ registerCollectionListChangeObserver: function(observer)
{
- Bandwagon.Logger.debug("Registering feed list change observer");
- this._feedListChangeObservers.push(observer);
+ Bandwagon.Logger.debug("Registering collection list change observer");
+ this._collectionListChangeObservers.push(observer);
},
- unregisterFeedListChangeObserver: function(observer)
+ unregisterCollectionListChangeObserver: function(observer)
{
- Bandwagon.Logger.debug("Unregistering feed list change observer");
+ Bandwagon.Logger.debug("Unregistering collection list change observer");
- for (var i=0; i<this._feedListChangeObservers.length; i++)
+ for (var i=0; i<this._collectionListChangeObservers.length; i++)
{
- if (this._feedListChangeObservers[i] == observer)
+ if (this._collectionListChangeObservers[i] == observer)
{
- delete this._feedListChangeObservers[i];
+ delete this._collectionListChangeObservers[i];
}
}
},
- checkForUpdates: function(feed)
+ updateCollectionsList: function()
+ {
+ Bandwagon.Logger.debug("Updating collections list...");
+
+ this.updateServiceDocument();
+ },
+
+ updateServiceDocument: function()
+ {
+ if (!this.isAMOAuthenticated())
+ {
+ Bandwagon.Logger.debug("Not authenticated in AMO");
+ return;
+ }
+
+ this._service.getServiceDocument();
+ },
+
+ checkForUpdates: function(collection)
{
var doCheck = false;
var now = new Date();
@@ -334,15 +432,15 @@ BandwagonService.prototype = {
// so a check must be due
doCheck = true;
}
- else if (feed.updateInterval > 0)
+ else if (collection.updateInterval > 0)
{
var dateLastCheck = null;
var dateNextCheck = null;
- if (feed.dateLastCheck != null)
+ if (collection.dateLastCheck != null)
{
- dateLastCheck = feed.dateLastCheck;
- dateNextCheck = new Date(dateLastCheck.getTime() + feed.updateInterval*1000);
+ dateLastCheck = collection.dateLastCheck;
+ dateNextCheck = new Date(dateLastCheck.getTime() + collection.updateInterval*1000);
}
else
{
@@ -357,14 +455,14 @@ BandwagonService.prototype = {
}
else
{
- Bandwagon.Logger.warn(feed.url + ": no global update interval nor feed update interval -- won't update");
+ Bandwagon.Logger.warn(collection.resourceURL + ": no global update interval nor collection update interval -- won't update");
}
if (doCheck)
{
- this._service.getFeed(feed);
+ this._service.getCollection(collection);
- feed.dateLastCheck = now;
+ collection.dateLastCheck = now;
}
},
@@ -388,65 +486,76 @@ BandwagonService.prototype = {
}
}
- for (var id in this.feeds)
+ for (var id in this.collections)
{
- var feed = this.feeds[id];
+ var collection = this.collections[id];
- this.checkForUpdates(feed);
+ this.checkForUpdates(collection);
}
Bandwagon.Preferences.setPreference("updateall.datelastcheck", now.getTime()/1000);
},
- forceCheckForUpdates: function(feed)
+ forceCheckForUpdates: function(collection)
{
- this._service.getFeed(feed);
- feed.dateLastCheck = new Date();
+ this._service.getCollection(collection);
+ collection.dateLastCheck = new Date();
},
forceCheckAllForUpdates: function()
{
- for (var id in this.feeds)
+ for (var id in this.collections)
{
- var feed = this.feeds[id];
- this.forceCheckForUpdates(feed);
+ var collection = this.collections[id];
+ this.forceCheckForUpdates(collection);
}
},
- subscribe: function(feed)
+ forceCheckAllForUpdatesAndUpdateCollectionsList: function()
{
- feed.preview = false;
- feed.setAllNotified();
+ this.forceCheckAllForUpdates();
+ this.updateCollectionsList();
+ },
+
+ /** OBSOLETE
+ subscribe: function(collection)
+ {
+ collection.preview = false;
+ collection.setAllNotified();
- this._service.subscribeFeed(feed);
+ this._service.subscribeCollection(collection);
},
+ */
- unsubscribe: function(feed)
+ /** OBSOLETE
+ unsubscribe: function(collection)
{
- this._service.unsubscribeFeed(feed);
+ this._service.unsubscribeCollection(collection);
},
+ */
firstrun: function()
{
- Bandwagon.Logger.info("This is bandwagon's firstrun");
-
- // set up and save default feeds
+ Bandwagon.Logger.info("This is bandwagon's firstrun. Welcome!");
- this._addDefaultFeed(Bandwagon.DEFAULT_FEED1_URL, Bandwagon.DEFAULT_FEED1_NAME);
- this._addDefaultFeed("http://www.33eels.com/clients/briks/bandwagon/testfeed.xml", "test feed");
+ // set up and save default collections
- // check for cookie to see if we have to add a feed like that
-
- var addFeedCookieValue = Bandwagon.Util.getCookie(Bandwagon.MAGIC_ADD_FEED_COOKIE_HOST, Bandwagon.MAGIC_ADD_FEED_COOKIE_NAME);
-
- if (addFeedCookieValue)
+ // FIXME temporarily disabling this
+ //this._addDefaultCollection(Bandwagon.DEFAULT_COLLECTION1_URL, Bandwagon.DEFAULT_COLLECTION1_NAME);
+ //this._addDefaultCollection("http://www.33eels.com/clients/briks/bandwagon/testcollection.xml", "test collection");
+
+ /** OBSOLETE
+ // check for cookie to see if we have to add a collection like that
+ var addCollectionCookieValue = Bandwagon.Util.getCookie(Bandwagon.MAGIC_ADD_COLLECTION_COOKIE_HOST, Bandwagon.MAGIC_ADD_COLLECTION_COOKIE_NAME);
+ if (addCollectionCookieValue)
{
- Bandwagon.Logger.info("Found magic 'add feed' cookie. Adding the feed '" + addFeedCookieValue + "'.");
- this.addPreviewFeed(addFeedCookieValue);
+ Bandwagon.Logger.info("Found magic 'add collection' cookie. Adding the collection '" + addCollectionCookieValue + "'.");
+ this.addPreviewCollection(addCollectionCookieValue);
// TODO we don't have to because we're in firstrun, but should we delete cookie to be neat?
}
+ */
// the last check date is now
@@ -458,75 +567,117 @@ BandwagonService.prototype = {
Bandwagon.Controller.BrowserOverlay.openFirstRunLandingPage();
},
- _addDefaultFeed: function(url, name)
+ _addDefaultCollection: function(url, name)
{
- var feed = this._feedFactory.newFeed();
- feed.url = url;
- feed.name = name;
- feed.showNotifications = false;
+ var collection = this._collectionFactory.newCollection();
+ collection.resourceURL = url;
+ collection.name = name;
+ collection.showNotifications = false;
- this.feeds[feed.url] = feed;
+ this.collections[collection.resourceURL] = collection;
if (Bandwagon.COMMIT_NOW)
- this.commit(feed);
+ this.commit(collection);
- this.forceCheckForUpdates(feed);
- this.subscribe(feed);
+ this.forceCheckForUpdates(collection);
+ this.subscribe(collection);
},
- addPreviewFeed: function(url)
+ /** OBSOLETE
+ addPreviewCollection: function(url)
{
- var feed = this._feedFactory.newFeed();
- feed.url = url;
- feed.preview = true;
- this.feeds[feed.url] = feed;
+ var collection = this._collectionFactory.newCollection();
+ collection.resourceURL = url;
+ collection.preview = true;
+ this.collections[collection.resourceURL] = collection;
- this.forceCheckForUpdates(feed);
+ this.forceCheckForUpdates(collection);
bandwagonService._notifyListChangeObservers();
- return feed;
+ return collection;
},
+ */
uninstall: function()
{
// TODO
},
- commit: function(feed)
+ commit: function(collection)
{
- if (!bandwagonService._feedFactory)
+ if (!bandwagonService._collectionFactory)
return;
- if (feed.preview)
+ /** OBSOLETE
+ if (collection.preview)
return;
+ */
- Bandwagon.Logger.debug("In commit() with feed: " + feed.url);
+ Bandwagon.Logger.debug("In commit() with collection: " + collection.resourceURL);
- bandwagonService._feedFactory.commitFeed(feed);
+ bandwagonService._collectionFactory.commitCollection(collection);
},
commitAll: function()
{
Bandwagon.Logger.debug("In commitAll()");
- for (var id in bandwagonService.feeds)
+ for (var id in bandwagonService.collections)
{
- var feed = bandwagonService.feeds[id];
+ var collection = bandwagonService.collections[id];
- this.commit(feed);
+ this.commit(collection);
}
+
+ if (bandwagonService._serviceDocument)
+ bandwagonService._collectionFactory.commitServiceDocument(bandwagonService._serviceDocument);
+ },
+
+ removeAddonFromCollection: function(guid, collection)
+ {
+ Bandwagon.Logger.debug("In removeAddonFromCollection()");
+
+ this._service.removeAddonFromCollection(guid, collection);
+ },
+
+ newCollection: function(collection, callback)
+ {
+ Bandwagon.Logger.debug("In newCollection()");
+
+ /*
+ var internalCallback = function(event)
+ {
+ if (!event.isError())
+ {
+ var collection = event.collection;
+
+ bandwagonService.collections[collection.resourceURL] = collection;
+ //bandwagonService._notifyCollectionUpdateObservers(collection);
+ bandwagonService._notifyListChangeObservers();
+ }
+
+ if (callback)
+ {
+ callback(event);
+ }
+ }
+
+ this._service.newCollection(collection, internalCallback);
+ */
+
+ this._service.newCollection(collection, callback);
},
- deleteFeed: function(feed)
+ deleteCollection: function(collection)
{
- this._feedFactory.deleteFeed(feed);
+ this._collectionFactory.deleteCollection(collection);
- for (var id in bandwagonService.feeds)
+ for (var id in bandwagonService.collections)
{
- if (feed.equals(bandwagonService.feeds[id]))
+ if (collection.equals(bandwagonService.collections[id]))
{
- delete bandwagonService.feeds[id];
+ delete bandwagonService.collections[id];
bandwagonService._notifyListChangeObservers();
@@ -535,25 +686,25 @@ BandwagonService.prototype = {
}
},
- getFeedItemsPerPage: function(feed)
+ getAddonsPerPage: function(collection)
{
- // returns the global feed items per page, if enabled. otherwise, this feed's feed items per page.
+ // returns the global collection items per page, if enabled. otherwise, this collection's collection items per page.
- var feedItemsPerPage;
+ var addonsPerPage;
- if (Bandwagon.Preferences.getPreference("feeditemsperpage.enabled"))
+ if (Bandwagon.Preferences.getPreference("addonsperpage.enabled"))
{
- feedItemsPerPage = Bandwagon.Preferences.getPreference("feeditemsperpage");
+ addonsPerPage = Bandwagon.Preferences.getPreference("addonsperpage");
}
else
{
- feedItemsPerPage = feed.feedItemsPerPage;
+ addonsPerPage = collection.addonsPerPage;
}
- if (feedItemsPerPage<1)
- feedItemsPerPage = 1;
+ if (addonsPerPage<1)
+ addonsPerPage = 1;
- return feedItemsPerPage;
+ return addonsPerPage;
},
getPreviouslySharedEmailAddresses: function()
@@ -563,6 +714,9 @@ BandwagonService.prototype = {
addPreviouslySharedEmailAddress: function(emailAddress)
{
+ emailAddress = emailAddress.replace(/^\s+/, "");
+ emailAddress = emailAddress.replace(/\s+$/, "");
+
var previouslySharedEmailAddresses = this.getPreviouslySharedEmailAddresses();
for (var i=0; i<previouslySharedEmailAddresses.length; i++)
@@ -578,9 +732,19 @@ BandwagonService.prototype = {
Bandwagon.Preferences.setPreferenceList("publish.shared.emails", previouslySharedEmailAddresses);
},
- publishToFeed: function(extension, feed, personalNote, callback)
+ addPreviouslySharedEmailAddresses: function(commaSeparatedEmailAddresses)
{
- this._service.publishToFeed(extension, feed, personalNote, callback);
+ var bits = commaSeparatedEmailAddresses.split(",");
+
+ for (var i=0; i<bits.length; i++)
+ {
+ this.addPreviouslySharedEmailAddress(bits[i]);
+ }
+ },
+
+ publishToCollection: function(extension, collection, personalNote, callback)
+ {
+ this._service.publishToCollection(extension, collection, personalNote, callback);
},
shareToEmail: function(extension, emailAddress, personalNote, callback)
@@ -588,36 +752,56 @@ BandwagonService.prototype = {
this._service.shareToEmail(extension, emailAddress, personalNote, callback);
},
- _feedUpdateObserver: function(feed)
+ isAMOAuthenticated: function()
{
- // called when a feed is updated
+ var cm = CookieManager.getService(nsICookieManager);
+
+ var iterator = cm.enumerator;
- // if there are new items, notify the user if notifications are enabled for this user and it's not a preview of a feed
+ while (iterator.hasMoreElements())
+ {
+ var cookie = iterator.getNext();
- Bandwagon.Logger.debug("in _feedUpdateObserver() with feed '" + feed + "', unnotified feed items = " + feed.getUnnotifiedFeedItems().length)
+ if (cookie instanceof Ci.nsICookie)
+ {
+ if (cookie.host == Bandwagon.AMO_AUTH_COOKIE_HOST && cookie.name == Bandwagon.AMO_AUTH_COOKIE_NAME)
+ return true;
+ }
+ }
+
+ return false;
+ },
+
+ _collectionUpdateObserver: function(collection)
+ {
+ // called when a collection is updated
+
+ // if there are new items, notify the user if notifications are enabled for this user and it's not a preview of a collection
+
+ Bandwagon.Logger.debug("in _collectionUpdateObserver() with collection '" + collection + "', unnotified collection items = " + collection.getUnnotifiedAddons().length)
var globalShowNotifications = Bandwagon.Preferences.getPreference("notifyall.enabled");
- if (feed.getUnnotifiedFeedItems().length > 0 && (feed.showNotifications || globalShowNotifications) && !feed.preview)
+ if (collection.getUnnotifiedAddons().length > 0 && (collection.showNotifications || globalShowNotifications) && !collection.preview)
{
var browserWindow = WindowMediator.getService(nsIWindowMediator).getMostRecentWindow("navigator:browser");
if (browserWindow)
{
- browserWindow.Bandwagon.Controller.BrowserOverlay.showNewFeedItemsAlert(feed);
+ browserWindow.Bandwagon.Controller.BrowserOverlay.showNewAddonsAlert(collection);
}
else
{
Bandwagon.Logger.error("Can't find a browser window to notify the user");
}
- feed.setAllNotified();
+ collection.setAllNotified();
}
- // commit the feed
+ // commit the collection
if (Bandwagon.COMMIT_NOW)
- bandwagonService.commit(feed);
+ bandwagonService.commit(collection);
},
_initStorage: function()
@@ -644,7 +828,7 @@ BandwagonService.prototype = {
return;
}
- this._feedFactory = new Bandwagon.Factory.FeedFactory(this._storageConnection);
+ this._collectionFactory = new Bandwagon.Factory.CollectionFactory(this._storageConnection);
this._initStorageTables();
},
@@ -659,7 +843,12 @@ BandwagonService.prototype = {
try
{
this._storageConnection.executeSimpleSQL(
- "CREATE TABLE IF NOT EXISTS feeds "
+ "CREATE TABLE IF NOT EXISTS serviceDocument "
+ + "(emailResourceURL TEXT NOT NULL, "
+ + "collectionListResourceURL TEXT NOT NULL)"
+ );
+ this._storageConnection.executeSimpleSQL(
+ "CREATE TABLE IF NOT EXISTS collections "
+ "(id INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "url TEXT NOT NULL UNIQUE, "
+ "name TEXT NOT NULL, "
@@ -670,12 +859,18 @@ BandwagonService.prototype = {
+ "showNotifications INTEGER NOT NULL, "
+ "autoPublish INTEGER NOT NULL, "
+ "active INTEGER NOT NULL DEFAULT 1, "
- + "feedItemsPerPage INTEGER NOT NULL)"
+ + "addonsPerPage INTEGER NOT NULL, "
+ + "creator TEXT, "
+ + "listed INTEGER NOT NULL DEFAULT 1, "
+ + "writable INTEGER NOT NULL DEFAULT 0, "
+ + "subscribed INTEGER NOT NULL DEFAULT 1, "
+ + "lastModified INTEGER, "
+ + "addonsResourceURL TEXT)"
);
this._storageConnection.executeSimpleSQL(
- "CREATE TABLE IF NOT EXISTS feedItems "
+ "CREATE TABLE IF NOT EXISTS collectionsAddons "
+ "(id INTEGER PRIMARY KEY AUTOINCREMENT, "
- + "feed INTEGER NOT NULL, "
+ + "collection INTEGER NOT NULL, "
+ "addon INTEGER NOT NULL, "
+ "read INTEGER NOT NULL DEFAULT 0)"
);
@@ -724,6 +919,11 @@ BandwagonService.prototype = {
+ "comment TEXT NOT NULL, "
+ "author TEXT NOT NULL)"
);
+ this._storageConnection.executeSimpleSQL(
+ "CREATE TABLE IF NOT EXISTS addonAuthors "
+ + "(addon INTEGER NOT NULL, "
+ + "author TEXT NOT NULL)"
+ );
}
catch (e)
{