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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
2
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
3 const Cc = Components.classes;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
4 const Ci = Components.interfaces;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
5 const Cr = Components.results;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
6 const Cu = Components.utils;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
7
114
5669c7260ce3 import stuff first
Myk Melez <myk@mozilla.org>
parents: 113
diff changeset
8 Cu.import("resource://snowl/modules/log4moz.js");
5669c7260ce3 import stuff first
Myk Melez <myk@mozilla.org>
parents: 113
diff changeset
9 Cu.import("resource://snowl/modules/datastore.js");
5669c7260ce3 import stuff first
Myk Melez <myk@mozilla.org>
parents: 113
diff changeset
10 Cu.import("resource://snowl/modules/URI.js");
5669c7260ce3 import stuff first
Myk Melez <myk@mozilla.org>
parents: 113
diff changeset
11 Cu.import("resource://snowl/modules/source.js");
5669c7260ce3 import stuff first
Myk Melez <myk@mozilla.org>
parents: 113
diff changeset
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
cb8bbdf99268 getNewMessages -> refresh
Myk Melez <myk@mozilla.org>
parents: 115
diff changeset
40 refresh: function() {
14
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
41 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance();
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
42
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
43 request.QueryInterface(Ci.nsIDOMEventTarget);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
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
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
47
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
48 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
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
55 request.send(null);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
56 },
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
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
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
59 let request = aEvent.target;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
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
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
69 },
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
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
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
74 },
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
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
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
77 // Now that we know we successfully downloaded the feed and obtained
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
78 // a result from it, update the "last refreshed" timestamp.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
79 this.resetLastRefreshed(this);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
80
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
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
82
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
83 let currentMessages = [];
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
84
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
85 SnowlDatastore.dbConnection.beginTransaction();
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
86 try {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
87 for (let i = 0; i < feed.items.length; i++) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
88 let entry = feed.items.queryElementAt(i, Ci.nsIFeedEntry);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
89 //entry.QueryInterface(Ci.nsIFeedContainer);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
90
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
91 // Figure out the ID for the entry, then check if the entry has already
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
92 // been retrieved. If we can't figure out the entry's ID, then we skip
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
93 // the entry, since its ID is the only way for us to know whether or not
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
94 // it has already been retrieved.
84
915e41848f6d rename universalID to externalID
Myk Melez <myk@mozilla.org>
parents: 76
diff changeset
95 let externalID;
14
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
96 try {
84
915e41848f6d rename universalID to externalID
Myk Melez <myk@mozilla.org>
parents: 76
diff changeset
97 externalID = entry.id || this.generateID(entry);
14
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
98 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
99 catch(ex) {
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
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
101 continue;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
102 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
103
84
915e41848f6d rename universalID to externalID
Myk Melez <myk@mozilla.org>
parents: 76
diff changeset
104 let internalID = this.getInternalIDForExternalID(externalID);
14
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
105
104
fe71ec6097f5 fix notification that sources and messages have changed after importing from OPML
Myk Melez <myk@mozilla.org>
parents: 85
diff changeset
106 if (internalID) {
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
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
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
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
112 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
113
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
114 currentMessages.push(internalID);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
115 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
116
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
117 // Update the current flag.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
118 SnowlDatastore.dbConnection.executeSimpleSQL("UPDATE messages SET current = 0 WHERE sourceID = " + this.id);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
119 SnowlDatastore.dbConnection.executeSimpleSQL("UPDATE messages SET current = 1 WHERE sourceID = " + this.id + " AND id IN (" + currentMessages.join(", ") + ")");
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
120
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
121 SnowlDatastore.dbConnection.commitTransaction();
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
122 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
123 catch(ex) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
124 SnowlDatastore.dbConnection.rollbackTransaction();
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
125 throw ex;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
126 }
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
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
130 },
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
131
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
132 /**
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
133 * Add a message to the datastore for the given feed entry.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
134 *
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
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
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
137 */
84
915e41848f6d rename universalID to externalID
Myk Melez <myk@mozilla.org>
parents: 76
diff changeset
138 addMessage: function(aEntry, aExternalID) {
14
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
139 // Combine the first author's name and email address into a single string
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
140 // that we'll use as the author of the message.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
141 let author = null;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
142 if (aEntry.authors.length > 0) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
143 let firstAuthor = aEntry.authors.queryElementAt(0, Ci.nsIFeedPerson);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
144 let name = firstAuthor.name;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
145 let email = firstAuthor.email;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
146 if (name) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
147 author = name;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
148 if (email)
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
149 author += " <" + email + ">";
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
150 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
151 else if (email)
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
152 author = email;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
153 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
154
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
155 // Convert the publication date/time string into a JavaScript Date object.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
156 let timestamp = aEntry.published ? new Date(aEntry.published) : null;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
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
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
177
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
178 // Add metadata.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
179 let fields = aEntry.QueryInterface(Ci.nsIFeedContainer).
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
180 fields.QueryInterface(Ci.nsIPropertyBag).enumerator;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
181 while (fields.hasMoreElements()) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
182 let field = fields.getNext().QueryInterface(Ci.nsIProperty);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
183
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
184 if (field.name == "authors") {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
185 let values = field.value.QueryInterface(Ci.nsIArray).enumerate();
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
186 while (values.hasMoreElements()) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
187 let value = values.getNext().QueryInterface(Ci.nsIFeedPerson);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
188 // FIXME: store people records in a separate table with individual
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
189 // columns for each person attribute (i.e. name, email, url)?
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
190 this.addMetadatum(messageID,
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
191 "atom:author",
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
192 value.name && value.email ? value.name + "<" + value.email + ">"
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
193 : value.name ? value.name : value.email);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
194 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
195 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
196
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
197 else if (field.name == "links") {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
198 let values = field.value.QueryInterface(Ci.nsIArray).enumerate();
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
199 while (values.hasMoreElements()) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
200 let value = values.getNext().QueryInterface(Ci.nsIPropertyBag2);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
201 // FIXME: store link records in a separate table with individual
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
202 // colums for each link attribute (i.e. href, type, rel, title)?
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
203 this.addMetadatum(messageID,
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
204 "atom:link_" + value.get("rel"),
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
205 value.get("href"));
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
206 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
207 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
208
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
209 // For some reason, the values of certain simple fields (like RSS2 guid)
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
210 // are property bags containing the value instead of the value itself.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
211 // For those, we need to unwrap the extra layer. This strange behavior
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
212 // has been filed as bug 427907.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
213 else if (typeof field.value == "object") {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
214 if (field.value instanceof Ci.nsIPropertyBag2) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
215 let value = field.value.QueryInterface(Ci.nsIPropertyBag2).get(field.name);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
216 this.addMetadatum(messageID, field.name, value);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
217 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
218 else if (field.value instanceof Ci.nsIArray) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
219 let values = field.value.QueryInterface(Ci.nsIArray).enumerate();
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
220 while (values.hasMoreElements()) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
221 let value = values.getNext().QueryInterface(Ci.nsIPropertyBag2);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
222 this.addMetadatum(messageID, field.name, value.get(field.name));
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
223 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
224 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
225 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
226
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
227 else
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
228 this.addMetadatum(messageID, field.name, field.value);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
229 }
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
230
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
231 return messageID;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
232 },
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
233
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
234 /**
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
235 * Convert a string to an array of character codes.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
236 *
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
237 * @param string {string} the string to convert
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
238 * @returns {array} the array of character codes
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
239 */
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
240 stringToArray: function(string) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
241 var array = [];
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
242 for (let i = 0; i < string.length; i++)
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
243 array.push(string.charCodeAt(i));
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
244 return array;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
245 },
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
246
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
247 /**
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
248 * Given an entry, generate an ID for it based on a hash of its link,
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
249 * published, and title attributes. Useful for uniquely identifying entries
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
250 * that don't provide their own IDs.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
251 *
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
252 * @param entry {nsIFeedEntry} the entry for which to generate an ID
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
253 * @returns {string} an ID for the entry
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
254 */
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
255 generateID: function(entry) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
256 let hasher = Cc["@mozilla.org/security/hash;1"].
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
257 createInstance(Ci.nsICryptoHash);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
258 hasher.init(Ci.nsICryptoHash.SHA1);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
259 let identity = this.stringToArray(entry.link.spec + entry.published + entry.title.text);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
260 hasher.update(identity, identity.length);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
261 return "urn:" + hasher.finish(true);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
262 },
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
263
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
264 // FIXME: Make the rest of this stuff be part of a superclass from which
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
265 // this class is derived.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
266
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
267 /**
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
268 * Get the internal ID of the message with the given external ID.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
269 *
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
270 * @param aExternalID {string}
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
271 * the external ID of the message
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
272 *
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
273 * @returns {number}
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
274 * the internal ID of the message, or undefined if the message
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
275 * doesn't exist
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
276 */
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
277 getInternalIDForExternalID: function(aExternalID) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
278 return SnowlDatastore.selectInternalIDForExternalID(aExternalID);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
279 },
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
280
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
281 /**
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
282 * Add a message with a single part to the datastore.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
283 *
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
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
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
286 * @param aSubject {string} the title of the message
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
287 * @param aAuthor {string} the author of the message
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
288 * @param aTimestamp {Date} the date/time at which the message was sent
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
289 * @param aLink {nsIURI} a link to the content of the message,
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
290 * if the content is hosted on a server
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
291 *
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
292 * @returns {integer} the internal ID of the newly-created message
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
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
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
296 // Convert the timestamp to milliseconds-since-epoch, which is how we store
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
297 // it in the datastore.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
298 let timestamp = aTimestamp ? aTimestamp.getTime() : null;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
299
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
300 // Convert the link to its string spec, which is how we store it
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
301 // in the datastore.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
302 let link = aLink ? aLink.spec : null;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
303
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
304 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
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
306 timestamp, link);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
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
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
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
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
331 },
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
332
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
333 addMetadatum: function(aMessageID, aAttributeName, aValue) {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
334 // FIXME: speed this up by caching the list of known attributes.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
335 let attributeID = SnowlDatastore.selectAttributeID(aAttributeName)
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
336 || SnowlDatastore.insertAttribute(aAttributeName);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
337 SnowlDatastore.insertMetadatum(aMessageID, attributeID, aValue);
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
338 },
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
339
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
340 /**
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
341 * Reset the last refreshed time for the given source to the current time.
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
342 *
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
343 * XXX should this be setLastRefreshed and take a time parameter
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
344 * to set the last refreshed time to?
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
345 *
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
346 * aSource {SnowlMessageSource} the source for which to set the time
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
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
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
349 resetLastRefreshed: function() {
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
350 let stmt = SnowlDatastore.createStatement("UPDATE sources SET lastRefreshed = :lastRefreshed WHERE id = :id");
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
351 stmt.params.lastRefreshed = new Date().getTime();
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
352 stmt.params.id = this.id;
74f775701774 refresh sources once per hour
Myk Melez <myk@mozilla.org>
parents:
diff changeset
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 };