Mercurial > snowl
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 |
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 | 2 |
3 const Cc = Components.classes; | |
4 const Ci = Components.interfaces; | |
5 const Cr = Components.results; | |
6 const Cu = Components.utils; | |
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 | 15 |
16 var SnowlFeedClient = { | |
17 // XXX Make this take a feed ID once it stores the list of subscribed feeds | |
18 // in the datastore. | |
19 refresh: function(aFeedURL) { | |
20 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(); | |
21 | |
22 request.QueryInterface(Ci.nsIDOMEventTarget); | |
23 let t = this; | |
24 request.addEventListener("load", function(aEvent) { t.onLoad(aEvent) }, false); | |
25 request.addEventListener("error", function(aEvent) { t.onError(aEvent) }, false); | |
26 | |
27 request.QueryInterface(Ci.nsIXMLHttpRequest); | |
28 request.open("GET", aFeedURL, true); | |
29 request.send(null); | |
30 }, | |
31 | |
32 onLoad: function(aEvent) { | |
33 let request = aEvent.target; | |
34 | |
35 if (request.responseText.length > 0) { | |
36 let parser = Cc["@mozilla.org/feed-processor;1"]. | |
37 createInstance(Ci.nsIFeedProcessor); | |
38 parser.listener = new SnowlFeed(request.channel.originalURI); | |
39 parser.parseFromString(request.responseText, request.channel.URI); | |
40 } | |
41 }, | |
42 | |
43 onError: function(aEvent) { | |
44 // FIXME: figure out what to do here. | |
21 | 45 Log4Moz.Service.getLogger("Snowl.FeedClient").error("loading feed " + aEvent.target.channel.originalURI.spec); |
14 | 46 } |
47 }; | |
48 | |
49 function SnowlFeed(aID, aURL, aTitle) { | |
50 this.id = aID; | |
51 this.url = aURL; | |
52 this.title = aTitle; | |
53 | |
54 this._log = Log4Moz.Service.getLogger("Snowl.Feed"); | |
55 } | |
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 | 59 SnowlFeed.prototype = { |
60 id: null, | |
61 url: null, | |
62 title: null, | |
63 | |
64 _log: null, | |
65 | |
66 QueryInterface: function(aIID) { | |
67 if (aIID.equals(Ci.nsIFeedResultListener) || | |
68 aIID.equals(Ci.nsISupports)) | |
69 return this; | |
70 | |
71 throw Cr.NS_ERROR_NO_INTERFACE; | |
72 }, | |
73 | |
74 // nsIFeedResultListener | |
75 | |
76 handleResult: function(result) { | |
77 // Now that we know we successfully downloaded the feed and obtained | |
78 // a result from it, update the "last refreshed" timestamp. | |
79 this.resetLastRefreshed(this); | |
80 | |
81 let feed = result.doc.QueryInterface(Components.interfaces.nsIFeed); | |
82 | |
83 let currentMessages = []; | |
84 | |
85 SnowlDatastore.dbConnection.beginTransaction(); | |
86 try { | |
87 for (let i = 0; i < feed.items.length; i++) { | |
88 let entry = feed.items.queryElementAt(i, Ci.nsIFeedEntry); | |
89 //entry.QueryInterface(Ci.nsIFeedContainer); | |
90 | |
91 // Figure out the ID for the entry, then check if the entry has already | |
92 // been retrieved. If we can't figure out the entry's ID, then we skip | |
93 // the entry, since its ID is the only way for us to know whether or not | |
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 | 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 | 98 } |
99 catch(ex) { | |
100 this._log.warn(this.title + " couldn't retrieve a message: " + ex); | |
101 continue; | |
102 } | |
103 | |
84
915e41848f6d
rename universalID to externalID
Myk Melez <myk@mozilla.org>
parents:
76
diff
changeset
|
104 let internalID = this.getInternalIDForExternalID(externalID); |
14 | 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 | 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 | 112 } |
113 | |
114 currentMessages.push(internalID); | |
115 } | |
116 | |
117 // Update the current flag. | |
118 SnowlDatastore.dbConnection.executeSimpleSQL("UPDATE messages SET current = 0 WHERE sourceID = " + this.id); | |
119 SnowlDatastore.dbConnection.executeSimpleSQL("UPDATE messages SET current = 1 WHERE sourceID = " + this.id + " AND id IN (" + currentMessages.join(", ") + ")"); | |
120 | |
121 SnowlDatastore.dbConnection.commitTransaction(); | |
122 } | |
123 catch(ex) { | |
124 SnowlDatastore.dbConnection.rollbackTransaction(); | |
125 throw ex; | |
126 } | |
127 }, | |
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 | 131 |
132 getNewMessages: function() { | |
133 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(); | |
134 | |
135 request.QueryInterface(Ci.nsIDOMEventTarget); | |
136 // FIXME: just pass "this" and make this implement nsIDOMEventListener. | |
137 let t = this; | |
138 request.addEventListener("load", function(aEvent) { t.onLoad(aEvent) }, false); | |
139 request.addEventListener("error", function(aEvent) { t.onError(aEvent) }, false); | |
140 | |
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 | 143 request.open("GET", this.url, true); |
144 request.send(null); | |
145 }, | |
146 | |
147 onLoad: function(aEvent) { | |
148 let request = aEvent.target; | |
149 | |
150 if (request.responseText.length > 0) { | |
151 let parser = Cc["@mozilla.org/feed-processor;1"]. | |
152 createInstance(Ci.nsIFeedProcessor); | |
153 parser.listener = this; | |
154 parser.parseFromString(request.responseText, request.channel.URI); | |
155 } | |
156 }, | |
157 | |
158 onError: function(aEvent) { | |
159 // FIXME: figure out what to do here. | |
160 this._log.error("loading feed " + aEvent.target.channel.originalURI); | |
161 }, | |
162 | |
163 /** | |
164 * Add a message to the datastore for the given feed entry. | |
165 * | |
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 | 168 */ |
84
915e41848f6d
rename universalID to externalID
Myk Melez <myk@mozilla.org>
parents:
76
diff
changeset
|
169 addMessage: function(aEntry, aExternalID) { |
14 | 170 // Combine the first author's name and email address into a single string |
171 // that we'll use as the author of the message. | |
172 let author = null; | |
173 if (aEntry.authors.length > 0) { | |
174 let firstAuthor = aEntry.authors.queryElementAt(0, Ci.nsIFeedPerson); | |
175 let name = firstAuthor.name; | |
176 let email = firstAuthor.email; | |
177 if (name) { | |
178 author = name; | |
179 if (email) | |
180 author += " <" + email + ">"; | |
181 } | |
182 else if (email) | |
183 author = email; | |
184 } | |
185 | |
186 // Convert the publication date/time string into a JavaScript Date object. | |
187 let timestamp = aEntry.published ? new Date(aEntry.published) : null; | |
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 | 208 |
209 // Add metadata. | |
210 let fields = aEntry.QueryInterface(Ci.nsIFeedContainer). | |
211 fields.QueryInterface(Ci.nsIPropertyBag).enumerator; | |
212 while (fields.hasMoreElements()) { | |
213 let field = fields.getNext().QueryInterface(Ci.nsIProperty); | |
214 | |
215 if (field.name == "authors") { | |
216 let values = field.value.QueryInterface(Ci.nsIArray).enumerate(); | |
217 while (values.hasMoreElements()) { | |
218 let value = values.getNext().QueryInterface(Ci.nsIFeedPerson); | |
219 // FIXME: store people records in a separate table with individual | |
220 // columns for each person attribute (i.e. name, email, url)? | |
221 this.addMetadatum(messageID, | |
222 "atom:author", | |
223 value.name && value.email ? value.name + "<" + value.email + ">" | |
224 : value.name ? value.name : value.email); | |
225 } | |
226 } | |
227 | |
228 else if (field.name == "links") { | |
229 let values = field.value.QueryInterface(Ci.nsIArray).enumerate(); | |
230 while (values.hasMoreElements()) { | |
231 let value = values.getNext().QueryInterface(Ci.nsIPropertyBag2); | |
232 // FIXME: store link records in a separate table with individual | |
233 // colums for each link attribute (i.e. href, type, rel, title)? | |
234 this.addMetadatum(messageID, | |
235 "atom:link_" + value.get("rel"), | |
236 value.get("href")); | |
237 } | |
238 } | |
239 | |
240 // For some reason, the values of certain simple fields (like RSS2 guid) | |
241 // are property bags containing the value instead of the value itself. | |
242 // For those, we need to unwrap the extra layer. This strange behavior | |
243 // has been filed as bug 427907. | |
244 else if (typeof field.value == "object") { | |
245 if (field.value instanceof Ci.nsIPropertyBag2) { | |
246 let value = field.value.QueryInterface(Ci.nsIPropertyBag2).get(field.name); | |
247 this.addMetadatum(messageID, field.name, value); | |
248 } | |
249 else if (field.value instanceof Ci.nsIArray) { | |
250 let values = field.value.QueryInterface(Ci.nsIArray).enumerate(); | |
251 while (values.hasMoreElements()) { | |
252 let value = values.getNext().QueryInterface(Ci.nsIPropertyBag2); | |
253 this.addMetadatum(messageID, field.name, value.get(field.name)); | |
254 } | |
255 } | |
256 } | |
257 | |
258 else | |
259 this.addMetadatum(messageID, field.name, field.value); | |
260 } | |
261 | |
262 return messageID; | |
263 }, | |
264 | |
265 /** | |
266 * Convert a string to an array of character codes. | |
267 * | |
268 * @param string {string} the string to convert | |
269 * @returns {array} the array of character codes | |
270 */ | |
271 stringToArray: function(string) { | |
272 var array = []; | |
273 for (let i = 0; i < string.length; i++) | |
274 array.push(string.charCodeAt(i)); | |
275 return array; | |
276 }, | |
277 | |
278 /** | |
279 * Given an entry, generate an ID for it based on a hash of its link, | |
280 * published, and title attributes. Useful for uniquely identifying entries | |
281 * that don't provide their own IDs. | |
282 * | |
283 * @param entry {nsIFeedEntry} the entry for which to generate an ID | |
284 * @returns {string} an ID for the entry | |
285 */ | |
286 generateID: function(entry) { | |
287 let hasher = Cc["@mozilla.org/security/hash;1"]. | |
288 createInstance(Ci.nsICryptoHash); | |
289 hasher.init(Ci.nsICryptoHash.SHA1); | |
290 let identity = this.stringToArray(entry.link.spec + entry.published + entry.title.text); | |
291 hasher.update(identity, identity.length); | |
292 return "urn:" + hasher.finish(true); | |
293 }, | |
294 | |
295 // FIXME: Make the rest of this stuff be part of a superclass from which | |
296 // this class is derived. | |
297 | |
298 /** | |
299 * Get the internal ID of the message with the given external ID. | |
300 * | |
301 * @param aExternalID {string} | |
302 * the external ID of the message | |
303 * | |
304 * @returns {number} | |
305 * the internal ID of the message, or undefined if the message | |
306 * doesn't exist | |
307 */ | |
308 getInternalIDForExternalID: function(aExternalID) { | |
309 return SnowlDatastore.selectInternalIDForExternalID(aExternalID); | |
310 }, | |
311 | |
312 /** | |
313 * Add a message with a single part to the datastore. | |
314 * | |
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 | 317 * @param aSubject {string} the title of the message |
318 * @param aAuthor {string} the author of the message | |
319 * @param aTimestamp {Date} the date/time at which the message was sent | |
320 * @param aLink {nsIURI} a link to the content of the message, | |
321 * if the content is hosted on a server | |
322 * | |
323 * @returns {integer} the internal ID of the newly-created message | |
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 | 327 // Convert the timestamp to milliseconds-since-epoch, which is how we store |
328 // it in the datastore. | |
329 let timestamp = aTimestamp ? aTimestamp.getTime() : null; | |
330 | |
331 // Convert the link to its string spec, which is how we store it | |
332 // in the datastore. | |
333 let link = aLink ? aLink.spec : null; | |
334 | |
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 | 337 timestamp, link); |
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 | 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 | 362 }, |
363 | |
364 addMetadatum: function(aMessageID, aAttributeName, aValue) { | |
365 // FIXME: speed this up by caching the list of known attributes. | |
366 let attributeID = SnowlDatastore.selectAttributeID(aAttributeName) | |
367 || SnowlDatastore.insertAttribute(aAttributeName); | |
368 SnowlDatastore.insertMetadatum(aMessageID, attributeID, aValue); | |
369 }, | |
370 | |
371 /** | |
372 * Reset the last refreshed time for the given source to the current time. | |
373 * | |
374 * XXX should this be setLastRefreshed and take a time parameter | |
375 * to set the last refreshed time to? | |
376 * | |
377 * aSource {SnowlMessageSource} the source for which to set the time | |
378 */ | |
379 resetLastRefreshed: function() { | |
380 let stmt = SnowlDatastore.createStatement("UPDATE sources SET lastRefreshed = :lastRefreshed WHERE id = :id"); | |
381 stmt.params.lastRefreshed = new Date().getTime(); | |
382 stmt.params.id = this.id; | |
383 stmt.execute(); | |
384 } | |
385 | |
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 }; |