Mercurial > snowl
changeset 320:b09b7f436e1a
only show a week's worth of messages, and group them by date, in the stream view
author | Myk Melez <myk@mozilla.org> |
---|---|
date | Sun, 12 Oct 2008 21:27:12 -0700 |
parents | a6cafdade667 |
children | 74793fa72460 |
files | content/stream.js modules/utils.js |
diffstat | 2 files changed, 56 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/content/stream.js Fri Oct 10 18:12:16 2008 -0700 +++ b/content/stream.js Sun Oct 12 21:27:12 2008 -0700 @@ -159,6 +159,15 @@ this._document = this._window.document; this._collection = new SnowlCollection(); + + // Only show a week's worth of messages. + this._collection.constraints.push({ + expression: "received > (julianday('now', 'start of day') - 6)", + parameters: {} + }); + + // FIXME: make this both received and sent so messages received at the same + // time show up in the correct order. this._collection.sortProperties = ["received"]; this._collection.sortOrder = -1; this._collection.sort(); @@ -325,8 +334,14 @@ { name: "The Future", epoch: Number.MAX_VALUE }, { name: "Today", epoch: SnowlUtils.today }, { name: "Yesterday", epoch: SnowlUtils.yesterday }, + { name: SnowlUtils.twoDaysAgo.name, epoch: SnowlUtils.twoDaysAgo.epoch }, + { name: SnowlUtils.threeDaysAgo.name, epoch: SnowlUtils.threeDaysAgo.epoch }, + { name: SnowlUtils.fourDaysAgo.name, epoch: SnowlUtils.fourDaysAgo.epoch }, + { name: SnowlUtils.fiveDaysAgo.name, epoch: SnowlUtils.fiveDaysAgo.epoch }, + { name: SnowlUtils.sixDaysAgo.name, epoch: SnowlUtils.sixDaysAgo.epoch }, { name: "Older", epoch: 0 } ]; + let groupIndex = 0; for (let i = 0; i < this._collection.messages.length; ++i) {
--- a/modules/utils.js Fri Oct 10 18:12:16 2008 -0700 +++ b/modules/utils.js Sun Oct 12 21:27:12 2008 -0700 @@ -41,6 +41,8 @@ const Cr = Components.results; const Cu = Components.utils; +let msInDay = (1000 * 60 * 60 * 24); + let SnowlUtils = { jsToJulianDate: function(date) { // Divide by 1000 to get seconds since Unix epoch, divide by 86400 @@ -64,6 +66,17 @@ getService(Ci.nsIScriptableDateFormat); }, + // FIXME: make this localizable. + days: { + 0: "Sunday", + 1: "Monday", + 2: "Tuesday", + 3: "Wednesday", + 4: "Thursday", + 5: "Friday", + 6: "Saturday" + }, + get today() { let sometimeToday = new Date(); return new Date(sometimeToday.getFullYear(), @@ -71,6 +84,9 @@ sometimeToday.getDate()); }, + // FIXME: accommodate daylight savings time, which could cause + // these calculations to be incorrect at times. + get tomorrow() { let sometimeTomorrow = new Date(new Date() + (1000 * 60 * 60 * 24)); return new Date(sometimeTomorrow.getFullYear(), @@ -85,6 +101,31 @@ sometimeYesterday.getDate()); }, + twoDaysAgo: { + get epoch() { return new Date(SnowlUtils.today - (msInDay * 2)) }, + get name() { return SnowlUtils.days[this.epoch.getDay()] } + }, + + threeDaysAgo: { + get epoch() { return new Date(SnowlUtils.today - (msInDay * 3)) }, + get name() { return SnowlUtils.days[this.epoch.getDay()] } + }, + + fourDaysAgo: { + get epoch() { return new Date(SnowlUtils.today - (msInDay * 4)) }, + get name() { return SnowlUtils.days[this.epoch.getDay()] } + }, + + fiveDaysAgo: { + get epoch() { return new Date(SnowlUtils.today - (msInDay * 5)) }, + get name() { return SnowlUtils.days[this.epoch.getDay()] } + }, + + sixDaysAgo: { + get epoch() { return new Date(SnowlUtils.today - (msInDay * 6)) }, + get name() { return SnowlUtils.days[this.epoch.getDay()] } + }, + /** * Formats a date for human consumption using the date formatting service * for locale-specific formatting along with some additional smarts for more