comparison extension/modules/feed.js @ 121:110b9b8aed1f

only notify observers that messages have changed if they have
author Myk Melez <myk@mozilla.org>
date Sun, 08 Jun 2008 21:50:05 -0700
parents 3c16d71594e5
children 7d13369f7d01
comparison
equal deleted inserted replaced
120:4dc7b2eb4aa6 121:110b9b8aed1f
92 this.lastRefreshed = new Date(); 92 this.lastRefreshed = new Date();
93 93
94 let feed = aResult.doc.QueryInterface(Components.interfaces.nsIFeed); 94 let feed = aResult.doc.QueryInterface(Components.interfaces.nsIFeed);
95 95
96 let currentMessageIDs = []; 96 let currentMessageIDs = [];
97 let messagesChanged = false;
97 98
98 SnowlDatastore.dbConnection.beginTransaction(); 99 SnowlDatastore.dbConnection.beginTransaction();
99 try { 100 try {
100 for (let i = 0; i < feed.items.length; i++) { 101 for (let i = 0; i < feed.items.length; i++) {
101 let entry = feed.items.queryElementAt(i, Ci.nsIFeedEntry); 102 let entry = feed.items.queryElementAt(i, Ci.nsIFeedEntry);
116 117
117 let internalID = this._getInternalIDForExternalID(externalID); 118 let internalID = this._getInternalIDForExternalID(externalID);
118 if (internalID) 119 if (internalID)
119 continue; 120 continue;
120 121
122 messagesChanged = true;
121 this._log.info(this.name + " adding message " + externalID); 123 this._log.info(this.name + " adding message " + externalID);
122 internalID = this._addMessage(entry, externalID); 124 internalID = this._addMessage(entry, externalID);
123 currentMessageIDs.push(internalID); 125 currentMessageIDs.push(internalID);
124 } 126 }
125 127
126 // Update the current flag. 128 // Update the current flag.
129 // XXX Should this affect whether or not messages have changed?
127 SnowlDatastore.dbConnection.executeSimpleSQL("UPDATE messages SET current = 0 WHERE sourceID = " + this.id); 130 SnowlDatastore.dbConnection.executeSimpleSQL("UPDATE messages SET current = 0 WHERE sourceID = " + this.id);
128 SnowlDatastore.dbConnection.executeSimpleSQL("UPDATE messages SET current = 1 WHERE id IN (" + currentMessageIDs.join(", ") + ")"); 131 SnowlDatastore.dbConnection.executeSimpleSQL("UPDATE messages SET current = 1 WHERE id IN (" + currentMessageIDs.join(", ") + ")");
129 132
130 SnowlDatastore.dbConnection.commitTransaction(); 133 SnowlDatastore.dbConnection.commitTransaction();
131 } 134 }
132 catch(ex) { 135 catch(ex) {
133 SnowlDatastore.dbConnection.rollbackTransaction(); 136 SnowlDatastore.dbConnection.rollbackTransaction();
134 throw ex; 137 throw ex;
135 } 138 }
136 139
137 // FIXME: only do this if something has actually changed. 140 if (messagesChanged)
138 this._obsSvc.notifyObservers(null, "messages:changed", null); 141 this._obsSvc.notifyObservers(null, "messages:changed", null);
139 }, 142 },
140 143
141 /** 144 /**
142 * Add a message to the datastore for the given feed entry. 145 * Add a message to the datastore for the given feed entry.
143 * 146 *