Mercurial > snowl
annotate extension/modules/feed.js @ 118:3c16d71594e5
some code cleanup
author | Myk Melez <myk@mozilla.org> |
---|---|
date | Sun, 01 Jun 2008 18:16:50 -0700 |
parents | 31fedd0b1466 |
children | 110b9b8aed1f |
rev | line source |
---|---|
112
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
1 EXPORTED_SYMBOLS = ["SnowlFeed"]; |
14 | 2 |
3 const Cc = Components.classes; | |
4 const Ci = Components.interfaces; | |
5 const Cr = Components.results; | |
6 const Cu = Components.utils; | |
7 | |
114 | 8 Cu.import("resource://snowl/modules/log4moz.js"); |
9 Cu.import("resource://snowl/modules/datastore.js"); | |
10 Cu.import("resource://snowl/modules/URI.js"); | |
11 Cu.import("resource://snowl/modules/source.js"); | |
12 | |
85
f5161c834622
store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents:
84
diff
changeset
|
13 // 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
|
14 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
|
15 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
|
16 |
113
f633d4f1fefa
make mediaTypes a constant rather than a property of the SnowlFeed object
Myk Melez <myk@mozilla.org>
parents:
112
diff
changeset
|
17 // nsIFeedTextConstruct::type to media type mappings. |
f633d4f1fefa
make mediaTypes a constant rather than a property of the SnowlFeed object
Myk Melez <myk@mozilla.org>
parents:
112
diff
changeset
|
18 const mediaTypes = { html: "text/html", |
f633d4f1fefa
make mediaTypes a constant rather than a property of the SnowlFeed object
Myk Melez <myk@mozilla.org>
parents:
112
diff
changeset
|
19 xhtml: "application/xhtml+xml", |
f633d4f1fefa
make mediaTypes a constant rather than a property of the SnowlFeed object
Myk Melez <myk@mozilla.org>
parents:
112
diff
changeset
|
20 text: "text/plain" }; |
f633d4f1fefa
make mediaTypes a constant rather than a property of the SnowlFeed object
Myk Melez <myk@mozilla.org>
parents:
112
diff
changeset
|
21 |
118 | 22 /** |
23 * Convert a string to an array of character codes. | |
24 * | |
25 * @param string {string} the string to convert | |
26 * @returns {array} the array of character codes | |
27 */ | |
28 function stringToArray(string) { | |
29 var array = []; | |
30 for (let i = 0; i < string.length; i++) | |
31 array.push(string.charCodeAt(i)); | |
32 return array; | |
33 } | |
34 | |
112
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
35 function SnowlFeed(aID, aName, aMachineURI, aHumanURI, aLastRefreshed, aImportance) { |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
36 // Call the superclass's constructor to initialize the new instance. |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
37 SnowlSource.call(this, aID, aName, aMachineURI, aHumanURI, aLastRefreshed, aImportance); |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
38 } |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
39 |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
40 SnowlFeed.prototype = { |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
41 __proto__: SnowlSource.prototype, |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
42 |
115
9556a63bfbda
make all snowl feeds share a logger
Myk Melez <myk@mozilla.org>
parents:
114
diff
changeset
|
43 _log: Log4Moz.Service.getLogger("Snowl.Feed"), |
112
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
44 |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
45 // Observer Service |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
46 get _obsSvc() { |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
47 let obsSvc = Cc["@mozilla.org/observer-service;1"]. |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
48 getService(Ci.nsIObserverService); |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
49 this.__defineGetter__("_obsSvc", function() { return obsSvc }); |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
50 return this._obsSvc; |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
51 }, |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
52 |
116 | 53 refresh: function() { |
14 | 54 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(); |
55 | |
56 request.QueryInterface(Ci.nsIDOMEventTarget); | |
57 let t = this; | |
112
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
58 request.addEventListener("load", function(e) { t.onRefreshLoad(e) }, false); |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
59 request.addEventListener("error", function(e) { t.onRefreshError(e) }, false); |
14 | 60 |
61 request.QueryInterface(Ci.nsIXMLHttpRequest); | |
112
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
62 |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
63 // The feed processor is going to parse the XML, so override the MIME type |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
64 // in order to turn off parsing by XMLHttpRequest itself. |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
65 request.overrideMimeType("text/plain"); |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
66 |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
67 request.open("GET", this.machineURI.spec, true); |
14 | 68 request.send(null); |
69 }, | |
70 | |
112
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
71 onRefreshLoad: function(aEvent) { |
14 | 72 let request = aEvent.target; |
73 | |
112
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
74 // XXX What's the right way to handle this? |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
75 if (request.responseText.length == 0) |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
76 throw("feed contains no data"); |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
77 |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
78 let parser = Cc["@mozilla.org/feed-processor;1"]. |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
79 createInstance(Ci.nsIFeedProcessor); |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
80 parser.listener = { t: this, handleResult: function(r) { this.t.onRefreshResult(r) } }; |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
81 parser.parseFromString(request.responseText, request.channel.URI); |
14 | 82 }, |
83 | |
112
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
84 onRefreshError: function(aEvent) { |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
85 this._log.error("onRefreshError: " + aEvent.target.status + " " + |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
86 aEvent.target.statusText + " " + aEvent.target.responseText.length); |
14 | 87 }, |
88 | |
112
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
89 onRefreshResult: function(aResult) { |
14 | 90 // Now that we know we successfully downloaded the feed and obtained |
91 // a result from it, update the "last refreshed" timestamp. | |
117
31fedd0b1466
refactor resetLastRefreshed into a lastRefreshed getter
Myk Melez <myk@mozilla.org>
parents:
116
diff
changeset
|
92 this.lastRefreshed = new Date(); |
14 | 93 |
112
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
94 let feed = aResult.doc.QueryInterface(Components.interfaces.nsIFeed); |
14 | 95 |
118 | 96 let currentMessageIDs = []; |
14 | 97 |
98 SnowlDatastore.dbConnection.beginTransaction(); | |
99 try { | |
100 for (let i = 0; i < feed.items.length; i++) { | |
101 let entry = feed.items.queryElementAt(i, Ci.nsIFeedEntry); | |
102 //entry.QueryInterface(Ci.nsIFeedContainer); | |
103 | |
104 // Figure out the ID for the entry, then check if the entry has already | |
105 // been retrieved. If we can't figure out the entry's ID, then we skip | |
106 // the entry, since its ID is the only way for us to know whether or not | |
107 // it has already been retrieved. | |
84
915e41848f6d
rename universalID to externalID
Myk Melez <myk@mozilla.org>
parents:
76
diff
changeset
|
108 let externalID; |
14 | 109 try { |
118 | 110 externalID = entry.id || this._generateID(entry); |
14 | 111 } |
112 catch(ex) { | |
118 | 113 this._log.warn("couldn't retrieve a message: " + ex); |
14 | 114 continue; |
115 } | |
116 | |
118 | 117 let internalID = this._getInternalIDForExternalID(externalID); |
118 if (internalID) | |
119 continue; | |
14 | 120 |
118 | 121 this._log.info(this.name + " adding message " + externalID); |
122 internalID = this._addMessage(entry, externalID); | |
123 currentMessageIDs.push(internalID); | |
14 | 124 } |
125 | |
126 // Update the current flag. | |
127 SnowlDatastore.dbConnection.executeSimpleSQL("UPDATE messages SET current = 0 WHERE sourceID = " + this.id); | |
118 | 128 SnowlDatastore.dbConnection.executeSimpleSQL("UPDATE messages SET current = 1 WHERE id IN (" + currentMessageIDs.join(", ") + ")"); |
14 | 129 |
130 SnowlDatastore.dbConnection.commitTransaction(); | |
131 } | |
132 catch(ex) { | |
133 SnowlDatastore.dbConnection.rollbackTransaction(); | |
134 throw ex; | |
135 } | |
112
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
136 |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
137 // FIXME: only do this if something has actually changed. |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
138 this._obsSvc.notifyObservers(null, "messages:changed", null); |
14 | 139 }, |
140 | |
141 /** | |
142 * Add a message to the datastore for the given feed entry. | |
143 * | |
144 * @param aEntry {nsIFeedEntry} the feed entry | |
84
915e41848f6d
rename universalID to externalID
Myk Melez <myk@mozilla.org>
parents:
76
diff
changeset
|
145 * @param aExternalID {string} the external ID of the feed entry |
14 | 146 */ |
118 | 147 _addMessage: function(aEntry, aExternalID) { |
14 | 148 // Combine the first author's name and email address into a single string |
149 // that we'll use as the author of the message. | |
150 let author = null; | |
151 if (aEntry.authors.length > 0) { | |
152 let firstAuthor = aEntry.authors.queryElementAt(0, Ci.nsIFeedPerson); | |
153 let name = firstAuthor.name; | |
154 let email = firstAuthor.email; | |
155 if (name) { | |
156 author = name; | |
157 if (email) | |
158 author += " <" + email + ">"; | |
159 } | |
160 else if (email) | |
161 author = email; | |
162 } | |
163 | |
164 // Convert the publication date/time string into a JavaScript Date object. | |
165 let timestamp = aEntry.published ? new Date(aEntry.published) : null; | |
166 | |
85
f5161c834622
store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents:
84
diff
changeset
|
167 // FIXME: handle titles that contain markup or are missing. |
84
915e41848f6d
rename universalID to externalID
Myk Melez <myk@mozilla.org>
parents:
76
diff
changeset
|
168 let messageID = this.addSimpleMessage(this.id, aExternalID, |
915e41848f6d
rename universalID to externalID
Myk Melez <myk@mozilla.org>
parents:
76
diff
changeset
|
169 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
|
170 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
|
171 |
f5161c834622
store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents:
84
diff
changeset
|
172 // 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
|
173 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
|
174 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
|
175 (aEntry.content.base ? aEntry.content.base.spec : null), |
113
f633d4f1fefa
make mediaTypes a constant rather than a property of the SnowlFeed object
Myk Melez <myk@mozilla.org>
parents:
112
diff
changeset
|
176 aEntry.content.lang, mediaTypes[aEntry.content.type]); |
85
f5161c834622
store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents:
84
diff
changeset
|
177 } |
f5161c834622
store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents:
84
diff
changeset
|
178 |
f5161c834622
store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents:
84
diff
changeset
|
179 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
|
180 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
|
181 (aEntry.summary.base ? aEntry.summary.base.spec : null), |
113
f633d4f1fefa
make mediaTypes a constant rather than a property of the SnowlFeed object
Myk Melez <myk@mozilla.org>
parents:
112
diff
changeset
|
182 aEntry.summary.lang, mediaTypes[aEntry.summary.type]); |
85
f5161c834622
store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents:
84
diff
changeset
|
183 } |
14 | 184 |
185 // Add metadata. | |
186 let fields = aEntry.QueryInterface(Ci.nsIFeedContainer). | |
187 fields.QueryInterface(Ci.nsIPropertyBag).enumerator; | |
188 while (fields.hasMoreElements()) { | |
189 let field = fields.getNext().QueryInterface(Ci.nsIProperty); | |
190 | |
191 if (field.name == "authors") { | |
192 let values = field.value.QueryInterface(Ci.nsIArray).enumerate(); | |
193 while (values.hasMoreElements()) { | |
194 let value = values.getNext().QueryInterface(Ci.nsIFeedPerson); | |
195 // FIXME: store people records in a separate table with individual | |
196 // columns for each person attribute (i.e. name, email, url)? | |
118 | 197 this._addMetadatum(messageID, |
198 "atom:author", | |
199 value.name && value.email ? value.name + "<" + value.email + ">" | |
200 : value.name ? value.name : value.email); | |
14 | 201 } |
202 } | |
203 | |
204 else if (field.name == "links") { | |
205 let values = field.value.QueryInterface(Ci.nsIArray).enumerate(); | |
206 while (values.hasMoreElements()) { | |
207 let value = values.getNext().QueryInterface(Ci.nsIPropertyBag2); | |
208 // FIXME: store link records in a separate table with individual | |
209 // colums for each link attribute (i.e. href, type, rel, title)? | |
118 | 210 this._addMetadatum(messageID, |
211 "atom:link_" + value.get("rel"), | |
212 value.get("href")); | |
14 | 213 } |
214 } | |
215 | |
216 // For some reason, the values of certain simple fields (like RSS2 guid) | |
217 // are property bags containing the value instead of the value itself. | |
218 // For those, we need to unwrap the extra layer. This strange behavior | |
219 // has been filed as bug 427907. | |
220 else if (typeof field.value == "object") { | |
221 if (field.value instanceof Ci.nsIPropertyBag2) { | |
222 let value = field.value.QueryInterface(Ci.nsIPropertyBag2).get(field.name); | |
118 | 223 this._addMetadatum(messageID, field.name, value); |
14 | 224 } |
225 else if (field.value instanceof Ci.nsIArray) { | |
226 let values = field.value.QueryInterface(Ci.nsIArray).enumerate(); | |
227 while (values.hasMoreElements()) { | |
228 let value = values.getNext().QueryInterface(Ci.nsIPropertyBag2); | |
118 | 229 this._addMetadatum(messageID, field.name, value.get(field.name)); |
14 | 230 } |
231 } | |
232 } | |
233 | |
234 else | |
118 | 235 this._addMetadatum(messageID, field.name, field.value); |
14 | 236 } |
237 | |
238 return messageID; | |
239 }, | |
240 | |
241 /** | |
242 * Given an entry, generate an ID for it based on a hash of its link, | |
243 * published, and title attributes. Useful for uniquely identifying entries | |
244 * that don't provide their own IDs. | |
245 * | |
246 * @param entry {nsIFeedEntry} the entry for which to generate an ID | |
247 * @returns {string} an ID for the entry | |
248 */ | |
118 | 249 _generateID: function(entry) { |
14 | 250 let hasher = Cc["@mozilla.org/security/hash;1"]. |
251 createInstance(Ci.nsICryptoHash); | |
252 hasher.init(Ci.nsICryptoHash.SHA1); | |
118 | 253 let identity = stringToArray(entry.link.spec + entry.published + entry.title.text); |
14 | 254 hasher.update(identity, identity.length); |
255 return "urn:" + hasher.finish(true); | |
256 }, | |
257 | |
258 // FIXME: Make the rest of this stuff be part of a superclass from which | |
259 // this class is derived. | |
260 | |
261 /** | |
262 * Get the internal ID of the message with the given external ID. | |
263 * | |
264 * @param aExternalID {string} | |
265 * the external ID of the message | |
266 * | |
267 * @returns {number} | |
268 * the internal ID of the message, or undefined if the message | |
269 * doesn't exist | |
270 */ | |
118 | 271 _getInternalIDForExternalID: function(aExternalID) { |
14 | 272 return SnowlDatastore.selectInternalIDForExternalID(aExternalID); |
273 }, | |
274 | |
275 /** | |
276 * Add a message with a single part to the datastore. | |
277 * | |
278 * @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
|
279 * @param aExternalID {string} the external ID of the message |
14 | 280 * @param aSubject {string} the title of the message |
281 * @param aAuthor {string} the author of the message | |
282 * @param aTimestamp {Date} the date/time at which the message was sent | |
283 * @param aLink {nsIURI} a link to the content of the message, | |
284 * if the content is hosted on a server | |
285 * | |
286 * @returns {integer} the internal ID of the newly-created message | |
287 */ | |
84
915e41848f6d
rename universalID to externalID
Myk Melez <myk@mozilla.org>
parents:
76
diff
changeset
|
288 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
|
289 aTimestamp, aLink) { |
14 | 290 // Convert the timestamp to milliseconds-since-epoch, which is how we store |
291 // it in the datastore. | |
292 let timestamp = aTimestamp ? aTimestamp.getTime() : null; | |
293 | |
294 // Convert the link to its string spec, which is how we store it | |
295 // in the datastore. | |
296 let link = aLink ? aLink.spec : null; | |
297 | |
298 let messageID = | |
84
915e41848f6d
rename universalID to externalID
Myk Melez <myk@mozilla.org>
parents:
76
diff
changeset
|
299 SnowlDatastore.insertMessage(aSourceID, aExternalID, aSubject, aAuthor, |
14 | 300 timestamp, link); |
301 | |
85
f5161c834622
store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents:
84
diff
changeset
|
302 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
|
303 }, |
f5161c834622
store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents:
84
diff
changeset
|
304 |
f5161c834622
store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents:
84
diff
changeset
|
305 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
|
306 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
|
307 "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
|
308 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
|
309 ); |
f5161c834622
store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents:
84
diff
changeset
|
310 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
|
311 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
|
312 }, |
14 | 313 |
85
f5161c834622
store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents:
84
diff
changeset
|
314 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
|
315 aMediaType) { |
f5161c834622
store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents:
84
diff
changeset
|
316 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
|
317 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
|
318 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
|
319 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
|
320 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
|
321 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
|
322 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
|
323 |
f5161c834622
store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents:
84
diff
changeset
|
324 return SnowlDatastore.dbConnection.lastInsertRowID; |
14 | 325 }, |
326 | |
118 | 327 _addMetadatum: function(aMessageID, aAttributeName, aValue) { |
14 | 328 // FIXME: speed this up by caching the list of known attributes. |
329 let attributeID = SnowlDatastore.selectAttributeID(aAttributeName) | |
330 || SnowlDatastore.insertAttribute(aAttributeName); | |
331 SnowlDatastore.insertMetadatum(aMessageID, attributeID, aValue); | |
332 }, | |
333 | |
112
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
334 // FIXME: make this accept a callback to which it reports on its progress |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
335 // so we can provide feedback to the user in subscription interfaces. |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
336 subscribe: function() { |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
337 this._log.info("subscribing to " + this.name + " <" + this.machineURI.spec + ">"); |
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
|
338 |
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
|
339 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
|
340 |
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
|
341 request = request.QueryInterface(Ci.nsIDOMEventTarget); |
112
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
342 |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
343 let t = this; |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
344 request.addEventListener("load", function(e) { t.onSubscribeLoad(e) }, false); |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
345 request.addEventListener("error", function(e) { t.onSubscribeError(e) }, false); |
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
|
346 |
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
|
347 request = request.QueryInterface(Ci.nsIXMLHttpRequest); |
106
2a08b4a82802
integrate OPML import into the sidebar
Myk Melez <myk@mozilla.org>
parents:
104
diff
changeset
|
348 |
112
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
349 // The feed processor is going to parse the XML, so override the MIME type |
106
2a08b4a82802
integrate OPML import into the sidebar
Myk Melez <myk@mozilla.org>
parents:
104
diff
changeset
|
350 // 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
|
351 request.overrideMimeType("text/plain"); |
2a08b4a82802
integrate OPML import into the sidebar
Myk Melez <myk@mozilla.org>
parents:
104
diff
changeset
|
352 |
112
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
353 request.open("GET", this.machineURI.spec, true); |
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
|
354 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
|
355 }, |
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
|
356 |
112
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
357 onSubscribeLoad: function(aEvent) { |
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
|
358 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
|
359 |
112
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
360 // XXX What's the right way to handle this? |
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
|
361 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
|
362 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
|
363 |
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
|
364 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
|
365 createInstance(Ci.nsIFeedProcessor); |
112
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
366 parser.listener = { t: this, handleResult: function(r) { this.t.onSubscribeResult(r) } }; |
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
|
367 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
|
368 }, |
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
|
369 |
112
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
370 onSubscribeError: function(aEvent) { |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
371 this._log.error("onSubscribeError: " + aEvent.target.status + " " + |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
372 aEvent.target.statusText + " " + aEvent.target.responseText.length); |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
373 }, |
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
|
374 |
112
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
375 onSubscribeResult: function(aResult) { |
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
|
376 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
|
377 |
112
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
378 // Extract the name (if we don't already have one) and human URI from the feed. |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
379 if (!this.name) |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
380 this.name = feed.title.plainText(); |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
381 this.humanURI = feed.link; |
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
|
382 |
112
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
383 // Add the source to the database. |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
384 let statement = |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
385 SnowlDatastore.createStatement("INSERT INTO sources (name, machineURI, humanURI) " + |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
386 "VALUES (:name, :machineURI, :humanURI)"); |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
387 try { |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
388 statement.params.name = this.name; |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
389 statement.params.machineURI = this.machineURI.spec; |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
390 statement.params.humanURI = this.humanURI.spec; |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
391 statement.step(); |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
392 } |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
393 finally { |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
394 statement.reset(); |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
395 } |
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
|
396 |
112
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
397 // Extract the ID of the source from the newly-created database record. |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
398 this.id = SnowlDatastore.dbConnection.lastInsertRowID; |
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
|
399 |
112
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
400 // Let observers know about the new 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
|
401 this._obsSvc.notifyObservers(null, "sources:changed", null); |
112
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
402 |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
403 // Refresh the feed to import all its items. |
754441ddeaa3
combine the SnowlFeed and SnowlFeedSubscriber objects, and make it inherit from SnowlSource; also, remove the obsolete SnowlFeedClient
Myk Melez <myk@mozilla.org>
parents:
108
diff
changeset
|
404 this.onRefreshResult(aResult); |
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 } |
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 }; |