annotate extension/modules/feed.js @ 108:ec5e374be495

show favicons in the subscriptions sidebar
author Myk Melez <myk@mozilla.org>
date Mon, 19 May 2008 00:01:05 -0700
parents 2a08b4a82802
children 754441ddeaa3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
76
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
1 EXPORTED_SYMBOLS = ["SnowlFeed", "SnowlFeedSubscriber"];
14
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
2
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
3 const Cc = Components.classes;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
4 const Ci = Components.interfaces;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
5 const Cr = Components.results;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
6 const Cu = Components.utils;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
7
85
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
8 // FIXME: factor this out into a common file.
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
9 const PART_TYPE_CONTENT = 1;
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
10 const PART_TYPE_SUMMARY = 2;
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
11
45
a3811857c5dc register the resource alias to the top-level directory rather than the modules directory for consistency with resource://gre/modules/ URLs and so we can use it to load resources from elsewhere in the extension later; this means converting chrome://snowl/module.js URLs into chrome://snowl/modules/module.js URLs
Myk Melez <myk@mozilla.org>
parents: 21
diff changeset
12 Cu.import("resource://snowl/modules/log4moz.js");
a3811857c5dc register the resource alias to the top-level directory rather than the modules directory for consistency with resource://gre/modules/ URLs and so we can use it to load resources from elsewhere in the extension later; this means converting chrome://snowl/module.js URLs into chrome://snowl/modules/module.js URLs
Myk Melez <myk@mozilla.org>
parents: 21
diff changeset
13 Cu.import("resource://snowl/modules/datastore.js");
85
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
14 Cu.import("resource://snowl/modules/URI.js");
14
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
15
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
16 var SnowlFeedClient = {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
17 // XXX Make this take a feed ID once it stores the list of subscribed feeds
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
18 // in the datastore.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
19 refresh: function(aFeedURL) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
20 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance();
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
21
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
22 request.QueryInterface(Ci.nsIDOMEventTarget);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
23 let t = this;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
24 request.addEventListener("load", function(aEvent) { t.onLoad(aEvent) }, false);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
25 request.addEventListener("error", function(aEvent) { t.onError(aEvent) }, false);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
26
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
27 request.QueryInterface(Ci.nsIXMLHttpRequest);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
28 request.open("GET", aFeedURL, true);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
29 request.send(null);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
30 },
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
31
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
32 onLoad: function(aEvent) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
33 let request = aEvent.target;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
34
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
35 if (request.responseText.length > 0) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
36 let parser = Cc["@mozilla.org/feed-processor;1"].
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
37 createInstance(Ci.nsIFeedProcessor);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
38 parser.listener = new SnowlFeed(request.channel.originalURI);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
39 parser.parseFromString(request.responseText, request.channel.URI);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
40 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
41 },
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
42
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
43 onError: function(aEvent) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
44 // FIXME: figure out what to do here.
21
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 14
diff changeset
45 Log4Moz.Service.getLogger("Snowl.FeedClient").error("loading feed " + aEvent.target.channel.originalURI.spec);
14
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
46 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
47 };
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
48
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
49 function SnowlFeed(aID, aURL, aTitle) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
50 this.id = aID;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
51 this.url = aURL;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
52 this.title = aTitle;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
53
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
54 this._log = Log4Moz.Service.getLogger("Snowl.Feed");
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
55 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
56
75
877a7694445f update the sources table schema, changing the title column to name and differentiating between machine-processable and human-readable URIs
Myk Melez <myk@mozilla.org>
parents: 45
diff changeset
57 // FIXME: make this a subclass of SnowlSource.
877a7694445f update the sources table schema, changing the title column to name and differentiating between machine-processable and human-readable URIs
Myk Melez <myk@mozilla.org>
parents: 45
diff changeset
58
14
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
59 SnowlFeed.prototype = {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
60 id: null,
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
61 url: null,
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
62 title: null,
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
63
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
64 _log: null,
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
65
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
66 QueryInterface: function(aIID) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
67 if (aIID.equals(Ci.nsIFeedResultListener) ||
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
68 aIID.equals(Ci.nsISupports))
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
69 return this;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
70
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
71 throw Cr.NS_ERROR_NO_INTERFACE;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
72 },
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
73
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
74 // nsIFeedResultListener
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
75
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
76 handleResult: function(result) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
77 // Now that we know we successfully downloaded the feed and obtained
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
78 // a result from it, update the "last refreshed" timestamp.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
79 this.resetLastRefreshed(this);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
80
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
81 let feed = result.doc.QueryInterface(Components.interfaces.nsIFeed);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
82
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
83 let currentMessages = [];
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
84
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
85 SnowlDatastore.dbConnection.beginTransaction();
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
86 try {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
87 for (let i = 0; i < feed.items.length; i++) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
88 let entry = feed.items.queryElementAt(i, Ci.nsIFeedEntry);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
89 //entry.QueryInterface(Ci.nsIFeedContainer);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
90
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
91 // Figure out the ID for the entry, then check if the entry has already
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
92 // been retrieved. If we can't figure out the entry's ID, then we skip
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
93 // the entry, since its ID is the only way for us to know whether or not
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
94 // it has already been retrieved.
84
915e41848f6d rename universalID to externalID
Myk Melez <myk@mozilla.org>
parents: 76
diff changeset
95 let externalID;
14
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
96 try {
84
915e41848f6d rename universalID to externalID
Myk Melez <myk@mozilla.org>
parents: 76
diff changeset
97 externalID = entry.id || this.generateID(entry);
14
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
98 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
99 catch(ex) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
100 this._log.warn(this.title + " couldn't retrieve a message: " + ex);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
101 continue;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
102 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
103
84
915e41848f6d rename universalID to externalID
Myk Melez <myk@mozilla.org>
parents: 76
diff changeset
104 let internalID = this.getInternalIDForExternalID(externalID);
14
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
105
104
fe71ec6097f5 fix notification that sources and messages have changed after importing from OPML
Myk Melez <myk@mozilla.org>
parents: 85
diff changeset
106 if (internalID) {
fe71ec6097f5 fix notification that sources and messages have changed after importing from OPML
Myk Melez <myk@mozilla.org>
parents: 85
diff changeset
107 //this._log.info(this.title + " has message " + externalID);
fe71ec6097f5 fix notification that sources and messages have changed after importing from OPML
Myk Melez <myk@mozilla.org>
parents: 85
diff changeset
108 }
14
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
109 else {
108
ec5e374be495 show favicons in the subscriptions sidebar
Myk Melez <myk@mozilla.org>
parents: 106
diff changeset
110 this._log.info(this.title + " adding message " + externalID);
84
915e41848f6d rename universalID to externalID
Myk Melez <myk@mozilla.org>
parents: 76
diff changeset
111 internalID = this.addMessage(entry, externalID);
14
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
112 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
113
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
114 currentMessages.push(internalID);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
115 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
116
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
117 // Update the current flag.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
118 SnowlDatastore.dbConnection.executeSimpleSQL("UPDATE messages SET current = 0 WHERE sourceID = " + this.id);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
119 SnowlDatastore.dbConnection.executeSimpleSQL("UPDATE messages SET current = 1 WHERE sourceID = " + this.id + " AND id IN (" + currentMessages.join(", ") + ")");
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
120
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
121 SnowlDatastore.dbConnection.commitTransaction();
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
122 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
123 catch(ex) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
124 SnowlDatastore.dbConnection.rollbackTransaction();
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
125 throw ex;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
126 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
127 },
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
128
85
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
129 // nsIFeedTextConstruct::type to media type mappings.
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
130 mediaTypes: { html: "text/html", xhtml: "application/xhtml+xml", text: "text/plain" },
14
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
131
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
132 getNewMessages: function() {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
133 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance();
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
134
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
135 request.QueryInterface(Ci.nsIDOMEventTarget);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
136 // FIXME: just pass "this" and make this implement nsIDOMEventListener.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
137 let t = this;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
138 request.addEventListener("load", function(aEvent) { t.onLoad(aEvent) }, false);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
139 request.addEventListener("error", function(aEvent) { t.onError(aEvent) }, false);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
140
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
141 request.QueryInterface(Ci.nsIXMLHttpRequest);
104
fe71ec6097f5 fix notification that sources and messages have changed after importing from OPML
Myk Melez <myk@mozilla.org>
parents: 85
diff changeset
142 //dump("about to getNewMessages for " + this.url + "\n");
14
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
143 request.open("GET", this.url, true);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
144 request.send(null);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
145 },
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
146
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
147 onLoad: function(aEvent) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
148 let request = aEvent.target;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
149
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
150 if (request.responseText.length > 0) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
151 let parser = Cc["@mozilla.org/feed-processor;1"].
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
152 createInstance(Ci.nsIFeedProcessor);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
153 parser.listener = this;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
154 parser.parseFromString(request.responseText, request.channel.URI);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
155 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
156 },
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
157
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
158 onError: function(aEvent) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
159 // FIXME: figure out what to do here.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
160 this._log.error("loading feed " + aEvent.target.channel.originalURI);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
161 },
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
162
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
163 /**
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
164 * Add a message to the datastore for the given feed entry.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
165 *
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
166 * @param aEntry {nsIFeedEntry} the feed entry
84
915e41848f6d rename universalID to externalID
Myk Melez <myk@mozilla.org>
parents: 76
diff changeset
167 * @param aExternalID {string} the external ID of the feed entry
14
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
168 */
84
915e41848f6d rename universalID to externalID
Myk Melez <myk@mozilla.org>
parents: 76
diff changeset
169 addMessage: function(aEntry, aExternalID) {
14
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
170 // Combine the first author's name and email address into a single string
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
171 // that we'll use as the author of the message.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
172 let author = null;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
173 if (aEntry.authors.length > 0) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
174 let firstAuthor = aEntry.authors.queryElementAt(0, Ci.nsIFeedPerson);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
175 let name = firstAuthor.name;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
176 let email = firstAuthor.email;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
177 if (name) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
178 author = name;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
179 if (email)
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
180 author += " <" + email + ">";
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
181 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
182 else if (email)
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
183 author = email;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
184 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
185
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
186 // Convert the publication date/time string into a JavaScript Date object.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
187 let timestamp = aEntry.published ? new Date(aEntry.published) : null;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
188
85
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
189 // FIXME: wrap all queries that add the message into a transaction?
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
190
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
191 // FIXME: handle titles that contain markup or are missing.
84
915e41848f6d rename universalID to externalID
Myk Melez <myk@mozilla.org>
parents: 76
diff changeset
192 let messageID = this.addSimpleMessage(this.id, aExternalID,
915e41848f6d rename universalID to externalID
Myk Melez <myk@mozilla.org>
parents: 76
diff changeset
193 aEntry.title.text, author,
85
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
194 timestamp, aEntry.link);
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
195
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
196 // Add parts
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
197 if (aEntry.content) {
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
198 this.addPart(messageID, PART_TYPE_CONTENT, aEntry.content.text,
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
199 (aEntry.content.base ? aEntry.content.base.spec : null),
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
200 aEntry.content.lang, this.mediaTypes[aEntry.content.type]);
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
201 }
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
202
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
203 if (aEntry.summary) {
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
204 this.addPart(messageID, PART_TYPE_SUMMARY, aEntry.summary.text,
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
205 (aEntry.summary.base ? aEntry.summary.base.spec : null),
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
206 aEntry.summary.lang, this.mediaTypes[aEntry.summary.type]);
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
207 }
14
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
208
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
209 // Add metadata.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
210 let fields = aEntry.QueryInterface(Ci.nsIFeedContainer).
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
211 fields.QueryInterface(Ci.nsIPropertyBag).enumerator;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
212 while (fields.hasMoreElements()) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
213 let field = fields.getNext().QueryInterface(Ci.nsIProperty);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
214
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
215 if (field.name == "authors") {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
216 let values = field.value.QueryInterface(Ci.nsIArray).enumerate();
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
217 while (values.hasMoreElements()) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
218 let value = values.getNext().QueryInterface(Ci.nsIFeedPerson);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
219 // FIXME: store people records in a separate table with individual
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
220 // columns for each person attribute (i.e. name, email, url)?
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
221 this.addMetadatum(messageID,
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
222 "atom:author",
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
223 value.name && value.email ? value.name + "<" + value.email + ">"
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
224 : value.name ? value.name : value.email);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
225 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
226 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
227
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
228 else if (field.name == "links") {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
229 let values = field.value.QueryInterface(Ci.nsIArray).enumerate();
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
230 while (values.hasMoreElements()) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
231 let value = values.getNext().QueryInterface(Ci.nsIPropertyBag2);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
232 // FIXME: store link records in a separate table with individual
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
233 // colums for each link attribute (i.e. href, type, rel, title)?
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
234 this.addMetadatum(messageID,
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
235 "atom:link_" + value.get("rel"),
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
236 value.get("href"));
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
237 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
238 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
239
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
240 // For some reason, the values of certain simple fields (like RSS2 guid)
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
241 // are property bags containing the value instead of the value itself.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
242 // For those, we need to unwrap the extra layer. This strange behavior
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
243 // has been filed as bug 427907.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
244 else if (typeof field.value == "object") {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
245 if (field.value instanceof Ci.nsIPropertyBag2) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
246 let value = field.value.QueryInterface(Ci.nsIPropertyBag2).get(field.name);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
247 this.addMetadatum(messageID, field.name, value);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
248 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
249 else if (field.value instanceof Ci.nsIArray) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
250 let values = field.value.QueryInterface(Ci.nsIArray).enumerate();
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
251 while (values.hasMoreElements()) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
252 let value = values.getNext().QueryInterface(Ci.nsIPropertyBag2);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
253 this.addMetadatum(messageID, field.name, value.get(field.name));
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
254 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
255 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
256 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
257
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
258 else
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
259 this.addMetadatum(messageID, field.name, field.value);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
260 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
261
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
262 return messageID;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
263 },
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
264
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
265 /**
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
266 * Convert a string to an array of character codes.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
267 *
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
268 * @param string {string} the string to convert
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
269 * @returns {array} the array of character codes
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
270 */
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
271 stringToArray: function(string) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
272 var array = [];
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
273 for (let i = 0; i < string.length; i++)
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
274 array.push(string.charCodeAt(i));
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
275 return array;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
276 },
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
277
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
278 /**
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
279 * Given an entry, generate an ID for it based on a hash of its link,
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
280 * published, and title attributes. Useful for uniquely identifying entries
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
281 * that don't provide their own IDs.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
282 *
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
283 * @param entry {nsIFeedEntry} the entry for which to generate an ID
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
284 * @returns {string} an ID for the entry
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
285 */
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
286 generateID: function(entry) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
287 let hasher = Cc["@mozilla.org/security/hash;1"].
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
288 createInstance(Ci.nsICryptoHash);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
289 hasher.init(Ci.nsICryptoHash.SHA1);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
290 let identity = this.stringToArray(entry.link.spec + entry.published + entry.title.text);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
291 hasher.update(identity, identity.length);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
292 return "urn:" + hasher.finish(true);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
293 },
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
294
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
295 // FIXME: Make the rest of this stuff be part of a superclass from which
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
296 // this class is derived.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
297
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
298 /**
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
299 * Get the internal ID of the message with the given external ID.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
300 *
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
301 * @param aExternalID {string}
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
302 * the external ID of the message
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
303 *
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
304 * @returns {number}
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
305 * the internal ID of the message, or undefined if the message
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
306 * doesn't exist
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
307 */
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
308 getInternalIDForExternalID: function(aExternalID) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
309 return SnowlDatastore.selectInternalIDForExternalID(aExternalID);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
310 },
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
311
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
312 /**
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
313 * Add a message with a single part to the datastore.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
314 *
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
315 * @param aSourceID {integer} the record ID of the message source
84
915e41848f6d rename universalID to externalID
Myk Melez <myk@mozilla.org>
parents: 76
diff changeset
316 * @param aExternalID {string} the external ID of the message
14
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
317 * @param aSubject {string} the title of the message
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
318 * @param aAuthor {string} the author of the message
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
319 * @param aTimestamp {Date} the date/time at which the message was sent
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
320 * @param aLink {nsIURI} a link to the content of the message,
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
321 * if the content is hosted on a server
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
322 *
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
323 * @returns {integer} the internal ID of the newly-created message
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
324 */
84
915e41848f6d rename universalID to externalID
Myk Melez <myk@mozilla.org>
parents: 76
diff changeset
325 addSimpleMessage: function(aSourceID, aExternalID, aSubject, aAuthor,
85
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
326 aTimestamp, aLink) {
14
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
327 // Convert the timestamp to milliseconds-since-epoch, which is how we store
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
328 // it in the datastore.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
329 let timestamp = aTimestamp ? aTimestamp.getTime() : null;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
330
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
331 // Convert the link to its string spec, which is how we store it
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
332 // in the datastore.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
333 let link = aLink ? aLink.spec : null;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
334
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
335 let messageID =
84
915e41848f6d rename universalID to externalID
Myk Melez <myk@mozilla.org>
parents: 76
diff changeset
336 SnowlDatastore.insertMessage(aSourceID, aExternalID, aSubject, aAuthor,
14
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
337 timestamp, link);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
338
85
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
339 return messageID;
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
340 },
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
341
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
342 get _addPartStatement() {
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
343 let statement = SnowlDatastore.createStatement(
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
344 "INSERT INTO parts(messageID, partType, content, baseURI, languageCode, mediaType) \
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
345 VALUES (:messageID, :partType, :content, :baseURI, :languageCode, :mediaType)"
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
346 );
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
347 this.__defineGetter__("_addPartStatement", function() { return statement });
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
348 return this._addPartStatement;
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
349 },
14
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
350
85
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
351 addPart: function(aMessageID, aPartType, aContent, aBaseURI, aLanguageCode,
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
352 aMediaType) {
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
353 this._addPartStatement.params.messageID = aMessageID;
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
354 this._addPartStatement.params.partType = aPartType;
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
355 this._addPartStatement.params.content = aContent;
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
356 this._addPartStatement.params.baseURI = aBaseURI;
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
357 this._addPartStatement.params.languageCode = aLanguageCode;
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
358 this._addPartStatement.params.mediaType = aMediaType;
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
359 this._addPartStatement.execute();
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
360
f5161c834622 store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents: 84
diff changeset
361 return SnowlDatastore.dbConnection.lastInsertRowID;
14
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
362 },
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
363
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
364 addMetadatum: function(aMessageID, aAttributeName, aValue) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
365 // FIXME: speed this up by caching the list of known attributes.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
366 let attributeID = SnowlDatastore.selectAttributeID(aAttributeName)
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
367 || SnowlDatastore.insertAttribute(aAttributeName);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
368 SnowlDatastore.insertMetadatum(aMessageID, attributeID, aValue);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
369 },
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
370
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
371 /**
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
372 * Reset the last refreshed time for the given source to the current time.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
373 *
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
374 * XXX should this be setLastRefreshed and take a time parameter
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
375 * to set the last refreshed time to?
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
376 *
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
377 * aSource {SnowlMessageSource} the source for which to set the time
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
378 */
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
379 resetLastRefreshed: function() {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
380 let stmt = SnowlDatastore.createStatement("UPDATE sources SET lastRefreshed = :lastRefreshed WHERE id = :id");
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
381 stmt.params.lastRefreshed = new Date().getTime();
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
382 stmt.params.id = this.id;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
383 stmt.execute();
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
384 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
385
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
386 };
76
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
387
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
388 // XXX Should we make this part of the Feed object?
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
389 // FIXME: make this accept a callback to which it reports on its progress
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
390 // so we can provide feedback to the user in subscription interfaces.
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
391 function SnowlFeedSubscriber(aURI, aName) {
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
392 this.uri = aURI;
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
393 this.name = aName;
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
394 }
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
395
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
396 SnowlFeedSubscriber.prototype = {
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
397 uri: null,
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
398 name: null,
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
399
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
400 // Observer Service
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
401 get _obsSvc() {
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
402 let obsSvc = Cc["@mozilla.org/observer-service;1"].
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
403 getService(Ci.nsIObserverService);
104
fe71ec6097f5 fix notification that sources and messages have changed after importing from OPML
Myk Melez <myk@mozilla.org>
parents: 85
diff changeset
404 this.__defineGetter__("_obsSvc", function() { return obsSvc });
76
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
405 return this._obsSvc;
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
406 },
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
407
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
408 QueryInterface: function(aIID) {
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
409 if (aIID.equals(Ci.nsIDOMEventListener) ||
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
410 aIID.equals(Ci.nsIFeedResultListener) ||
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
411 aIID.equals(Ci.nsISupports))
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
412 return this;
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
413
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
414 throw Cr.NS_ERROR_NO_INTERFACE;
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
415 },
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
416
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
417 subscribe: function() {
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
418 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance();
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
419
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
420 request = request.QueryInterface(Ci.nsIDOMEventTarget);
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
421 request.addEventListener("load", this, false);
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
422 request.addEventListener("error", this, false);
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
423
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
424 request = request.QueryInterface(Ci.nsIXMLHttpRequest);
106
2a08b4a82802 integrate OPML import into the sidebar
Myk Melez <myk@mozilla.org>
parents: 104
diff changeset
425
2a08b4a82802 integrate OPML import into the sidebar
Myk Melez <myk@mozilla.org>
parents: 104
diff changeset
426 // The feed processor is going to parse the XML, so set the MIME type
2a08b4a82802 integrate OPML import into the sidebar
Myk Melez <myk@mozilla.org>
parents: 104
diff changeset
427 // in order to turn off parsing by XMLHttpRequest itself.
2a08b4a82802 integrate OPML import into the sidebar
Myk Melez <myk@mozilla.org>
parents: 104
diff changeset
428 request.overrideMimeType("text/plain");
2a08b4a82802 integrate OPML import into the sidebar
Myk Melez <myk@mozilla.org>
parents: 104
diff changeset
429
76
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
430 request.open("GET", this.uri.spec, true);
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
431 request.send(null);
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
432 },
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
433
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
434 // nsIDOMEventListener
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
435
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
436 handleEvent: function(aEvent) {
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
437 switch(aEvent.type) {
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
438 case "load":
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
439 this.onLoad(aEvent);
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
440 break;
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
441 case "error":
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
442 this.onError(aEvent);
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
443 break;
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
444 }
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
445 },
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
446
106
2a08b4a82802 integrate OPML import into the sidebar
Myk Melez <myk@mozilla.org>
parents: 104
diff changeset
447 onError: function(aEvent) {
2a08b4a82802 integrate OPML import into the sidebar
Myk Melez <myk@mozilla.org>
parents: 104
diff changeset
448 dump("XMLHTTPRequest.onError for " + this.name + " <" + this.uri.spec + ">: " + aEvent.target.status + " " + aEvent.target.statusText + " " + aEvent.target.responseText.length + "\n");
2a08b4a82802 integrate OPML import into the sidebar
Myk Melez <myk@mozilla.org>
parents: 104
diff changeset
449 },
2a08b4a82802 integrate OPML import into the sidebar
Myk Melez <myk@mozilla.org>
parents: 104
diff changeset
450
76
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
451 onLoad: function(aEvent) {
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
452 let request = aEvent.target;
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
453
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
454 // FIXME: notify the user about the problem.
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
455 if (request.responseText.length == 0)
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
456 throw("feed contains no data");
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
457
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
458 let parser = Cc["@mozilla.org/feed-processor;1"].
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
459 createInstance(Ci.nsIFeedProcessor);
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
460 parser.listener = this;
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
461 parser.parseFromString(request.responseText, request.channel.URI);
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
462 },
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
463
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
464 // nsIFeedResultListener
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
465
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
466 handleResult: function(aResult) {
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
467 let feed = aResult.doc.QueryInterface(Components.interfaces.nsIFeed);
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
468
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
469 // Subscribe to the feed.
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
470 let name = this.name || feed.title.plainText();
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
471 let statement = SnowlDatastore.createStatement("INSERT INTO sources (name, machineURI, humanURI) VALUES (:name, :machineURI, :humanURI)");
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
472 statement.params.name = name;
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
473 statement.params.machineURI = this.uri.spec;
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
474 statement.params.humanURI = feed.link.spec;
104
fe71ec6097f5 fix notification that sources and messages have changed after importing from OPML
Myk Melez <myk@mozilla.org>
parents: 85
diff changeset
475 //dump("subscribing to " + name + " <" + this.uri.spec + ">\n");
76
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
476 statement.step();
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
477
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
478 let id = SnowlDatastore.dbConnection.lastInsertRowID;
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
479
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
480 // Now refresh the feed to import all its items.
104
fe71ec6097f5 fix notification that sources and messages have changed after importing from OPML
Myk Melez <myk@mozilla.org>
parents: 85
diff changeset
481 //dump("refreshing " + this.uri.spec + "\n");
76
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
482 let feed2 = new SnowlFeed(id, this.uri.spec, name);
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
483 feed2.handleResult(aResult);
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
484
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
485 this._obsSvc.notifyObservers(null, "sources:changed", null);
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
486 this._obsSvc.notifyObservers(null, "messages:changed", null);
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
487 }
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
488
1cbd4c5a511b link the source name to the human URI if available; add a new SnowlFeedSubscriber object that can handle subscribing to feeds from various interfaces and which sets the human URI if available; make the OPML importer use the new SnowlFeedSubscriber object
Myk Melez <myk@mozilla.org>
parents: 75
diff changeset
489 };