Mercurial > snowl
changeset 61:eda164b40007
add the source name to messages in the river view; required creating a SnowlSource object that SnowlMessage objects reference
author | Myk Melez <myk@mozilla.org> |
---|---|
date | Thu, 08 May 2008 13:38:53 -0700 |
parents | 0477cba8b12d |
children | c1c11fddba76 |
files | extension/modules/RiverWriter.js extension/modules/datastore.js extension/modules/message.js extension/modules/source.js |
diffstat | 4 files changed, 64 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/extension/modules/RiverWriter.js Thu May 08 11:50:53 2008 -0700 +++ b/extension/modules/RiverWriter.js Thu May 08 13:38:53 2008 -0700 @@ -41,6 +41,8 @@ * * ***** END LICENSE BLOCK ***** */ +// FIXME: make this part of river.js instead of a separate file. + const EXPORTED_SYMBOLS = ["SnowlRiverWriter"]; const Cc = Components.classes; @@ -299,6 +301,10 @@ // If the entry has a title, make it a link if (entry.subject) { var a = this._document.createElementNS(HTML_NS, "a"); + a.appendChild(this._document.createTextNode(entry.source.title)); + a.appendChild(this._document.createTextNode(": ")); + a.appendChild(this._document.createTextNode(entry.author)); + a.appendChild(this._document.createTextNode(": ")); a.appendChild(this._document.createTextNode(entry.subject)); // Entries are not required to have links, so entry.link can be null.
--- a/extension/modules/datastore.js Thu May 08 11:50:53 2008 -0700 +++ b/extension/modules/datastore.js Thu May 08 13:38:53 2008 -0700 @@ -45,6 +45,7 @@ "id INTEGER PRIMARY KEY", // FIXME: rename this 'link' "url TEXT NOT NULL", + // FIXME: rename this "name" "title TEXT NOT NULL", "lastRefreshed INTEGER", ]
--- a/extension/modules/message.js Thu May 08 11:50:53 2008 -0700 +++ b/extension/modules/message.js Thu May 08 13:38:53 2008 -0700 @@ -6,6 +6,7 @@ const Cu = Components.utils; Cu.import("resource://snowl/modules/datastore.js"); +Cu.import("resource://snowl/modules/source.js"); function SnowlMessage(aID, aSubject, aAuthor, aLink, aTimestamp, aRead) { this.id = aID; @@ -36,11 +37,10 @@ }, _content: null, + get content() { - if (this._content) { - dump(this.id + " has content " + this._content.type + " " + this._content.text.length + "\n"); + if (this._content) return this._content; - } try { this._contentStatement.params.messageID = this.id; @@ -60,6 +60,41 @@ set content(newValue) { this._content = newValue; + }, + + get _sourceStatement() { + let statement = SnowlDatastore.createStatement( + "SELECT sources.id, sources.url, sources.title " + + "FROM messages JOIN sources ON messages.sourceID = sources.id " + + "WHERE messages.id = :messageID" + ); + this.__defineGetter__("_sourceStatement", function() { return statement }); + return this._sourceStatement; + }, + + _source: null, + + get source() { + if (!this._source) { + try { + this._sourceStatement.params.messageID = this.id; + if (this._sourceStatement.step()) + // FIXME: get this from the snowl service and make the service cache + // sources so we don't create a new instance of the source object + // for every message. + this._source = new SnowlSource(this._sourceStatement.row.id, + this._sourceStatement.row.url, + this._sourceStatement.row.title); + } +catch(ex) { + dump(ex + "\n"); +} + finally { + this._sourceStatement.reset(); + } + } + + return this._source; } };
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extension/modules/source.js Thu May 08 13:38:53 2008 -0700 @@ -0,0 +1,19 @@ +const EXPORTED_SYMBOLS = ["SnowlSource"]; + +const Cc = Components.classes; +const Ci = Components.interfaces; +const Cr = Components.results; +const Cu = Components.utils; + +function SnowlSource(aID, aURL, aTitle) { + this.id = aID; + this.url = aURL; + this.title = aTitle; +} + +SnowlSource.prototype = { + id: null, + // FIXME: make this an nsIURI. + url: null, + title: null +};