Mercurial > snowl
changeset 380:6916b17a0536
Automated merge with http://hg.toolness.com/snowl/
author | Myk Melez <myk@mozilla.org> |
---|---|
date | Sat, 08 Nov 2008 10:31:05 -0800 |
parents | 7b162afc05cc |
children | 88287a633755 |
files | modules/feed.js modules/service.js modules/twitter.js |
diffstat | 3 files changed, 27 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/modules/feed.js Fri Nov 07 18:32:41 2008 -0800 +++ b/modules/feed.js Sat Nov 08 10:31:05 2008 -0800 @@ -57,6 +57,7 @@ Cu.import("resource://snowl/modules/identity.js"); Cu.import("resource://snowl/modules/message.js"); Cu.import("resource://snowl/modules/utils.js"); +Cu.import("resource://snowl/modules/service.js"); // nsIFeedTextConstruct::type to media type mappings. const mediaTypes = { html: "text/html", @@ -233,7 +234,7 @@ statusText = request.statusText; } catch(ex) {} - + this._log.error("onRefreshError: " + request.status + " (" + statusText + ")"); }, @@ -644,3 +645,5 @@ } }; + +SnowlService.addAccountType(SnowlFeed);
--- a/modules/service.js Fri Nov 07 18:32:41 2008 -0800 +++ b/modules/service.js Sat Nov 08 10:31:05 2008 -0800 @@ -50,8 +50,6 @@ // modules that are Snowl-specific Cu.import("resource://snowl/modules/datastore.js"); -Cu.import("resource://snowl/modules/feed.js"); -Cu.import("resource://snowl/modules/twitter.js"); Cu.import("resource://snowl/modules/source.js"); Cu.import("resource://snowl/modules/target.js"); Cu.import("resource://snowl/modules/utils.js"); @@ -211,6 +209,15 @@ } }, + _accountTypeConstructors: {}, + addAccountType: function(constructor) { +this._log.info("add account type for " + constructor.name); + if (constructor in this._accountTypeConstructors) + this._log.warn("constructor for " + constructor.name + + "already exists"); + this._accountTypeConstructors[constructor.name] = constructor; + }, + get _getAccountsStatement() { delete this._getAccountsStatement; return this._getAccountsStatement = SnowlDatastore.createStatement( @@ -225,21 +232,18 @@ while (this._getAccountsStatement.step()) { let row = this._getAccountsStatement.row; - let type; - try { - type = eval(row.type); - } - catch(ex) { - this._log.error("error getting " + row.name + ": " + ex); + let constructor = this._accountTypeConstructors[row.type]; + if (!constructor) { + this._log.error("no constructor for type " + row.type); continue; } - accounts.push(new type(row.id, - row.name, - URI.get(row.machineURI), - URI.get(row.humanURI), - SnowlDateUtils.julianToJSDate(row.lastRefreshed), - row.importance)); + accounts.push(new constructor(row.id, + row.name, + URI.get(row.machineURI), + URI.get(row.humanURI), + SnowlDateUtils.julianToJSDate(row.lastRefreshed), + row.importance)); } } finally {
--- a/modules/twitter.js Fri Nov 07 18:32:41 2008 -0800 +++ b/modules/twitter.js Sat Nov 08 10:31:05 2008 -0800 @@ -57,6 +57,7 @@ Cu.import("resource://snowl/modules/identity.js"); Cu.import("resource://snowl/modules/message.js"); Cu.import("resource://snowl/modules/utils.js"); +Cu.import("resource://snowl/modules/service.js"); const NAME = "Twitter"; const MACHINE_URI = URI.get("https://twitter.com"); @@ -278,7 +279,7 @@ statusText = request.statusText; } catch(ex) {} - + this._log.error("onSubscribeError: " + request.status + " (" + statusText + ")"); Observers.notify(this, "snowl:subscribe:connect:end", request.status); @@ -345,7 +346,7 @@ statusText = request.statusText; } catch(ex) {} - + this._log.error("onRefreshError: " + request.status + " (" + statusText + ")"); }, @@ -645,3 +646,5 @@ } }; + +SnowlService.addAccountType(SnowlTwitter);