Mercurial > snowl
changeset 260:f88055405aee
make all messages received in the same refresh have the same received datetime, and support multiple sort properties when sorting a collection
author | Myk Melez <myk@mozilla.org> |
---|---|
date | Mon, 25 Aug 2008 17:33:13 -0700 |
parents | 531f02f9bc9f |
children | a7aada4427b7 |
files | content/list.js modules/collection.js modules/datastore.js modules/feed.js modules/twitter.js |
diffstat | 5 files changed, 36 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/content/list.js Fri Aug 22 18:23:26 2008 -0700 +++ b/content/list.js Mon Aug 25 17:33:13 2008 -0700 @@ -572,7 +572,7 @@ let order = (direction == "ascending" ? 1 : -1); // Perform the sort. - this._collection.sort(property, order); + this._collection.sort([property], order); } };
--- a/modules/collection.js Fri Aug 22 18:23:26 2008 -0700 +++ b/modules/collection.js Mon Aug 25 17:33:13 2008 -0700 @@ -79,6 +79,8 @@ this.groupHomeURLColumn = groupHomeURLColumn; this.groupIconURLColumn = groupIconURLColumn; this._filters = filters || []; + + this.sortProperty = ["timestamp"]; } SnowlCollection.prototype = { @@ -229,7 +231,9 @@ //**************************************************************************// // Retrieval - sortProperty: "timestamp", + // sortProperty gets set to its default value in the constructor + // since the default is an array which would be a singleton if defined here. + sortProperty: null, sortOrder: 1, _messages: null, @@ -338,25 +342,22 @@ return statement; }, - sort: function(aProperty, aOrder) { - this.sortProperty = aProperty; + sort: function(aProperties, aOrder) { + this.sortProperty = aProperties; this.sortOrder = aOrder; + // Fall back on subject. + // XXX Should we let callers make this decision? + if (aProperties[aProperties.length - 1] != "subject") + aProperties.push("subject"); + let compare = function(a, b) { - if (prepareObjectForComparison(a[aProperty]) > - prepareObjectForComparison(b[aProperty])) - return 1 * aOrder; - if (prepareObjectForComparison(a[aProperty]) < - prepareObjectForComparison(b[aProperty])) - return -1 * aOrder; - - // Fall back on the "subject" aProperty. - if (aProperty != "subject") { - if (prepareObjectForComparison(a.subject) > - prepareObjectForComparison(b.subject)) + for each (let property in aProperties) { + if (prepareObjectForComparison(a[property]) > + prepareObjectForComparison(b[property])) return 1 * aOrder; - if (prepareObjectForComparison(a.subject) < - prepareObjectForComparison(b.subject)) + if (prepareObjectForComparison(a[property]) < + prepareObjectForComparison(b[property])) return -1 * aOrder; }
--- a/modules/datastore.js Fri Aug 22 18:23:26 2008 -0700 +++ b/modules/datastore.js Mon Aug 25 17:33:13 2008 -0700 @@ -463,20 +463,22 @@ * @param aExternalID {string} the external ID of the message * @param aSubject {string} the title of the message * @param aAuthorID {string} the author of the message - * @param aTimestamp {Date} the date/time at which the message was sent + * @param aTimestamp {Date} the date/time when the message was sent + * @param aReceived {Date} the date/time when the message was received * @param aLink {nsIURI} a link to the content of the message, * if the content is hosted on a server * * @returns {integer} the ID of the newly-created record */ - insertMessage: function(aSourceID, aExternalID, aSubject, aAuthorID, aTimestamp, aLink) { + insertMessage: function(aSourceID, aExternalID, aSubject, aAuthorID, aTimestamp, aReceived, aLink) { this._insertMessageStatement.params.sourceID = aSourceID; this._insertMessageStatement.params.externalID = aExternalID; this._insertMessageStatement.params.subject = aSubject; this._insertMessageStatement.params.authorID = aAuthorID; let timestamp = aTimestamp ? SnowlUtils.jsToJulianDate(aTimestamp) : null; this._insertMessageStatement.params.timestamp = timestamp; - this._insertMessageStatement.params.received = SnowlUtils.jsToJulianDate(new Date()); + let received = aReceived ? SnowlUtils.jsToJulianDate(aReceived) : null; + this._insertMessageStatement.params.received = received; this._insertMessageStatement.params.link = aLink; this._insertMessageStatement.execute();
--- a/modules/feed.js Fri Aug 22 18:23:26 2008 -0700 +++ b/modules/feed.js Mon Aug 25 17:33:13 2008 -0700 @@ -271,7 +271,7 @@ messagesChanged = true; this._log.info(this.name + " adding message " + externalID); - internalID = this._addMessage(feed, entry, externalID); + internalID = this._addMessage(feed, entry, externalID, this.lastRefreshed); currentMessageIDs.push(internalID); } @@ -299,8 +299,9 @@ * @param aFeed {nsIFeed} the feed * @param aEntry {nsIFeedEntry} the entry * @param aExternalID {string} the external ID of the entry + * @param aReceived {Date} when the message was received */ - _addMessage: function(aFeed, aEntry, aExternalID) { + _addMessage: function(aFeed, aEntry, aExternalID, aReceived) { let authorID = null; let authors = (aEntry.authors.length > 0) ? aEntry.authors : (aFeed.authors.length > 0) ? aFeed.authors @@ -335,7 +336,7 @@ // FIXME: handle titles that contain markup or are missing. let messageID = this.addSimpleMessage(this.id, aExternalID, aEntry.title.text, authorID, - timestamp, aEntry.link); + timestamp, aReceived, aEntry.link); // Add parts if (aEntry.content) { @@ -456,14 +457,14 @@ * @returns {integer} the internal ID of the newly-created message */ addSimpleMessage: function(aSourceID, aExternalID, aSubject, aAuthorID, - aTimestamp, aLink) { + aTimestamp, aReceived, aLink) { // Convert the link to its string spec, which is how we store it // in the datastore. let link = aLink ? aLink.spec : null; let messageID = SnowlDatastore.insertMessage(aSourceID, aExternalID, aSubject, aAuthorID, - aTimestamp, link); + aTimestamp, aReceived, link); return messageID; },
--- a/modules/twitter.js Fri Aug 22 18:23:26 2008 -0700 +++ b/modules/twitter.js Mon Aug 25 17:33:13 2008 -0700 @@ -363,7 +363,7 @@ messagesChanged = true; this._log.info(this.name + " adding message " + externalID); - internalID = this._addMessage(message); + internalID = this._addMessage(message, this.lastRefreshed); currentMessages.push(internalID); } @@ -387,7 +387,7 @@ Observers.notify(this, "snowl:subscribe:get:end", null); }, - _addMessage: function(message) { + _addMessage: function(message, aReceived) { // We store the message text as both the subject and the content so that // the content shows up in the Subject column of the list view. // FIXME: make the list view automatically display some of the content @@ -409,7 +409,7 @@ let timestamp = new Date(message.created_at); // Add the message. - let messageID = this.addSimpleMessage(this.id, message.id, subject, authorID, timestamp, null); + let messageID = this.addSimpleMessage(this.id, message.id, subject, authorID, timestamp, aReceived, null); // Add the message's content. this.addPart(messageID, PART_TYPE_CONTENT, message.text, null, null, "text/plain"); @@ -457,21 +457,22 @@ * @param aExternalID {string} the external ID of the message * @param aSubject {string} the title of the message * @param aAuthorID {string} the author of the message - * @param aTimestamp {Date} the date/time at which the message was sent + * @param aTimestamp {Date} the date/time when the message was sent + * @param aReceived {Date} the date/time when the message was received * @param aLink {nsIURI} a link to the content of the message, * if the content is hosted on a server * * @returns {integer} the internal ID of the newly-created message */ addSimpleMessage: function(aSourceID, aExternalID, aSubject, aAuthorID, - aTimestamp, aLink) { + aTimestamp, aReceived, aLink) { // Convert the link to its string spec, which is how we store it // in the datastore. let link = aLink ? aLink.spec : null; let messageID = SnowlDatastore.insertMessage(aSourceID, aExternalID, aSubject, aAuthorID, - aTimestamp, link); + aTimestamp, aReceived, link); return messageID; },