Mercurial > snowl
annotate extension/modules/feed.js @ 116:cb8bbdf99268
getNewMessages -> refresh
author | Myk Melez <myk@mozilla.org> |
---|---|
date | Sun, 01 Jun 2008 17:52:37 -0700 |
parents | 9556a63bfbda |
children | 31fedd0b1466 |
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 |
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
|
22 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
|
23 // 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
|
24 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
|
25 } |
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
|
26 |
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
|
27 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
|
28 __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
|
29 |
115
9556a63bfbda
make all snowl feeds share a logger
Myk Melez <myk@mozilla.org>
parents:
114
diff
changeset
|
30 _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
|
31 |
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
|
32 // 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
|
33 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
|
34 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
|
35 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
|
36 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
|
37 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
|
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 |
116 | 40 refresh: function() { |
14 | 41 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(); |
42 | |
43 request.QueryInterface(Ci.nsIDOMEventTarget); | |
44 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
|
45 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
|
46 request.addEventListener("error", function(e) { t.onRefreshError(e) }, false); |
14 | 47 |
48 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
|
49 |
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 // 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
|
51 // 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
|
52 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
|
53 |
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
|
54 request.open("GET", this.machineURI.spec, true); |
14 | 55 request.send(null); |
56 }, | |
57 | |
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 onRefreshLoad: function(aEvent) { |
14 | 59 let request = aEvent.target; |
60 | |
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
|
61 // 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
|
62 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
|
63 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
|
64 |
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 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
|
66 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
|
67 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
|
68 parser.parseFromString(request.responseText, request.channel.URI); |
14 | 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 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
|
72 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
|
73 aEvent.target.statusText + " " + aEvent.target.responseText.length); |
14 | 74 }, |
75 | |
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
|
76 onRefreshResult: function(aResult) { |
14 | 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 | |
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
|
81 let feed = aResult.doc.QueryInterface(Components.interfaces.nsIFeed); |
14 | 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) { | |
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
|
100 this._log.warn(this.name + " couldn't retrieve a message: " + ex); |
14 | 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) { |
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
|
107 //this._log.info(this.name + " has message " + externalID); |
104
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 { |
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
|
110 this._log.info(this.name + " 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 } | |
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
|
127 |
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
|
128 // 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
|
129 this._obsSvc.notifyObservers(null, "messages:changed", null); |
14 | 130 }, |
131 | |
132 /** | |
133 * Add a message to the datastore for the given feed entry. | |
134 * | |
135 * @param aEntry {nsIFeedEntry} the feed entry | |
84
915e41848f6d
rename universalID to externalID
Myk Melez <myk@mozilla.org>
parents:
76
diff
changeset
|
136 * @param aExternalID {string} the external ID of the feed entry |
14 | 137 */ |
84
915e41848f6d
rename universalID to externalID
Myk Melez <myk@mozilla.org>
parents:
76
diff
changeset
|
138 addMessage: function(aEntry, aExternalID) { |
14 | 139 // Combine the first author's name and email address into a single string |
140 // that we'll use as the author of the message. | |
141 let author = null; | |
142 if (aEntry.authors.length > 0) { | |
143 let firstAuthor = aEntry.authors.queryElementAt(0, Ci.nsIFeedPerson); | |
144 let name = firstAuthor.name; | |
145 let email = firstAuthor.email; | |
146 if (name) { | |
147 author = name; | |
148 if (email) | |
149 author += " <" + email + ">"; | |
150 } | |
151 else if (email) | |
152 author = email; | |
153 } | |
154 | |
155 // Convert the publication date/time string into a JavaScript Date object. | |
156 let timestamp = aEntry.published ? new Date(aEntry.published) : null; | |
157 | |
85
f5161c834622
store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents:
84
diff
changeset
|
158 // 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
|
159 |
f5161c834622
store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents:
84
diff
changeset
|
160 // FIXME: handle titles that contain markup or are missing. |
84
915e41848f6d
rename universalID to externalID
Myk Melez <myk@mozilla.org>
parents:
76
diff
changeset
|
161 let messageID = this.addSimpleMessage(this.id, aExternalID, |
915e41848f6d
rename universalID to externalID
Myk Melez <myk@mozilla.org>
parents:
76
diff
changeset
|
162 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
|
163 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
|
164 |
f5161c834622
store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents:
84
diff
changeset
|
165 // 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
|
166 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
|
167 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
|
168 (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
|
169 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
|
170 } |
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 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
|
173 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
|
174 (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
|
175 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
|
176 } |
14 | 177 |
178 // Add metadata. | |
179 let fields = aEntry.QueryInterface(Ci.nsIFeedContainer). | |
180 fields.QueryInterface(Ci.nsIPropertyBag).enumerator; | |
181 while (fields.hasMoreElements()) { | |
182 let field = fields.getNext().QueryInterface(Ci.nsIProperty); | |
183 | |
184 if (field.name == "authors") { | |
185 let values = field.value.QueryInterface(Ci.nsIArray).enumerate(); | |
186 while (values.hasMoreElements()) { | |
187 let value = values.getNext().QueryInterface(Ci.nsIFeedPerson); | |
188 // FIXME: store people records in a separate table with individual | |
189 // columns for each person attribute (i.e. name, email, url)? | |
190 this.addMetadatum(messageID, | |
191 "atom:author", | |
192 value.name && value.email ? value.name + "<" + value.email + ">" | |
193 : value.name ? value.name : value.email); | |
194 } | |
195 } | |
196 | |
197 else if (field.name == "links") { | |
198 let values = field.value.QueryInterface(Ci.nsIArray).enumerate(); | |
199 while (values.hasMoreElements()) { | |
200 let value = values.getNext().QueryInterface(Ci.nsIPropertyBag2); | |
201 // FIXME: store link records in a separate table with individual | |
202 // colums for each link attribute (i.e. href, type, rel, title)? | |
203 this.addMetadatum(messageID, | |
204 "atom:link_" + value.get("rel"), | |
205 value.get("href")); | |
206 } | |
207 } | |
208 | |
209 // For some reason, the values of certain simple fields (like RSS2 guid) | |
210 // are property bags containing the value instead of the value itself. | |
211 // For those, we need to unwrap the extra layer. This strange behavior | |
212 // has been filed as bug 427907. | |
213 else if (typeof field.value == "object") { | |
214 if (field.value instanceof Ci.nsIPropertyBag2) { | |
215 let value = field.value.QueryInterface(Ci.nsIPropertyBag2).get(field.name); | |
216 this.addMetadatum(messageID, field.name, value); | |
217 } | |
218 else if (field.value instanceof Ci.nsIArray) { | |
219 let values = field.value.QueryInterface(Ci.nsIArray).enumerate(); | |
220 while (values.hasMoreElements()) { | |
221 let value = values.getNext().QueryInterface(Ci.nsIPropertyBag2); | |
222 this.addMetadatum(messageID, field.name, value.get(field.name)); | |
223 } | |
224 } | |
225 } | |
226 | |
227 else | |
228 this.addMetadatum(messageID, field.name, field.value); | |
229 } | |
230 | |
231 return messageID; | |
232 }, | |
233 | |
234 /** | |
235 * Convert a string to an array of character codes. | |
236 * | |
237 * @param string {string} the string to convert | |
238 * @returns {array} the array of character codes | |
239 */ | |
240 stringToArray: function(string) { | |
241 var array = []; | |
242 for (let i = 0; i < string.length; i++) | |
243 array.push(string.charCodeAt(i)); | |
244 return array; | |
245 }, | |
246 | |
247 /** | |
248 * Given an entry, generate an ID for it based on a hash of its link, | |
249 * published, and title attributes. Useful for uniquely identifying entries | |
250 * that don't provide their own IDs. | |
251 * | |
252 * @param entry {nsIFeedEntry} the entry for which to generate an ID | |
253 * @returns {string} an ID for the entry | |
254 */ | |
255 generateID: function(entry) { | |
256 let hasher = Cc["@mozilla.org/security/hash;1"]. | |
257 createInstance(Ci.nsICryptoHash); | |
258 hasher.init(Ci.nsICryptoHash.SHA1); | |
259 let identity = this.stringToArray(entry.link.spec + entry.published + entry.title.text); | |
260 hasher.update(identity, identity.length); | |
261 return "urn:" + hasher.finish(true); | |
262 }, | |
263 | |
264 // FIXME: Make the rest of this stuff be part of a superclass from which | |
265 // this class is derived. | |
266 | |
267 /** | |
268 * Get the internal ID of the message with the given external ID. | |
269 * | |
270 * @param aExternalID {string} | |
271 * the external ID of the message | |
272 * | |
273 * @returns {number} | |
274 * the internal ID of the message, or undefined if the message | |
275 * doesn't exist | |
276 */ | |
277 getInternalIDForExternalID: function(aExternalID) { | |
278 return SnowlDatastore.selectInternalIDForExternalID(aExternalID); | |
279 }, | |
280 | |
281 /** | |
282 * Add a message with a single part to the datastore. | |
283 * | |
284 * @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
|
285 * @param aExternalID {string} the external ID of the message |
14 | 286 * @param aSubject {string} the title of the message |
287 * @param aAuthor {string} the author of the message | |
288 * @param aTimestamp {Date} the date/time at which the message was sent | |
289 * @param aLink {nsIURI} a link to the content of the message, | |
290 * if the content is hosted on a server | |
291 * | |
292 * @returns {integer} the internal ID of the newly-created message | |
293 */ | |
84
915e41848f6d
rename universalID to externalID
Myk Melez <myk@mozilla.org>
parents:
76
diff
changeset
|
294 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
|
295 aTimestamp, aLink) { |
14 | 296 // Convert the timestamp to milliseconds-since-epoch, which is how we store |
297 // it in the datastore. | |
298 let timestamp = aTimestamp ? aTimestamp.getTime() : null; | |
299 | |
300 // Convert the link to its string spec, which is how we store it | |
301 // in the datastore. | |
302 let link = aLink ? aLink.spec : null; | |
303 | |
304 let messageID = | |
84
915e41848f6d
rename universalID to externalID
Myk Melez <myk@mozilla.org>
parents:
76
diff
changeset
|
305 SnowlDatastore.insertMessage(aSourceID, aExternalID, aSubject, aAuthor, |
14 | 306 timestamp, link); |
307 | |
85
f5161c834622
store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents:
84
diff
changeset
|
308 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
|
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 |
f5161c834622
store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents:
84
diff
changeset
|
311 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
|
312 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
|
313 "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
|
314 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
|
315 ); |
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.__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
|
317 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
|
318 }, |
14 | 319 |
85
f5161c834622
store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents:
84
diff
changeset
|
320 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
|
321 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.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
|
323 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
|
324 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
|
325 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
|
326 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
|
327 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
|
328 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
|
329 |
f5161c834622
store summaries in addition to content and display them in the river view
Myk Melez <myk@mozilla.org>
parents:
84
diff
changeset
|
330 return SnowlDatastore.dbConnection.lastInsertRowID; |
14 | 331 }, |
332 | |
333 addMetadatum: function(aMessageID, aAttributeName, aValue) { | |
334 // FIXME: speed this up by caching the list of known attributes. | |
335 let attributeID = SnowlDatastore.selectAttributeID(aAttributeName) | |
336 || SnowlDatastore.insertAttribute(aAttributeName); | |
337 SnowlDatastore.insertMetadatum(aMessageID, attributeID, aValue); | |
338 }, | |
339 | |
340 /** | |
341 * Reset the last refreshed time for the given source to the current time. | |
342 * | |
343 * XXX should this be setLastRefreshed and take a time parameter | |
344 * to set the last refreshed time to? | |
345 * | |
346 * aSource {SnowlMessageSource} the source for which to set the time | |
347 */ | |
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
|
348 // FIXME: make this a setter for the lastRefreshed property. |
14 | 349 resetLastRefreshed: function() { |
350 let stmt = SnowlDatastore.createStatement("UPDATE sources SET lastRefreshed = :lastRefreshed WHERE id = :id"); | |
351 stmt.params.lastRefreshed = new Date().getTime(); | |
352 stmt.params.id = this.id; | |
353 stmt.execute(); | |
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 }, |
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 |
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
|
356 // 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
|
357 // 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
|
358 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
|
359 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
|
360 |
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 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
|
362 |
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 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
|
364 |
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
|
365 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
|
366 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
|
367 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
|
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 request = request.QueryInterface(Ci.nsIXMLHttpRequest); |
106
2a08b4a82802
integrate OPML import into the sidebar
Myk Melez <myk@mozilla.org>
parents:
104
diff
changeset
|
370 |
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
|
371 // 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
|
372 // 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
|
373 request.overrideMimeType("text/plain"); |
2a08b4a82802
integrate OPML import into the sidebar
Myk Melez <myk@mozilla.org>
parents:
104
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 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
|
376 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
|
377 }, |
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
|
378 |
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
|
379 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
|
380 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
|
381 |
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
|
382 // 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
|
383 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
|
384 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
|
385 |
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
|
386 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
|
387 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
|
388 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
|
389 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
|
390 }, |
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 |
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
|
392 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
|
393 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
|
394 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
|
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 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
|
398 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
|
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 // 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
|
401 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
|
402 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
|
403 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
|
404 |
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
|
405 // 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
|
406 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
|
407 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
|
408 "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
|
409 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
|
410 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
|
411 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
|
412 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
|
413 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
|
414 } |
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
|
415 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
|
416 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
|
417 } |
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
|
418 |
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
|
419 // 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
|
420 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
|
421 |
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
|
422 // 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
|
423 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
|
424 |
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
|
425 // 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
|
426 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
|
427 } |
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
|
428 |
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
|
429 }; |