Mercurial > ambnews-firefox
changeset 10:f07bf657f483
Display of Vanilla forum threads is better now; fixed some display bugs; updated TODOs; documented more code.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Fri, 22 Aug 2008 10:02:50 -0700 |
parents | 61687c1c0ce8 |
children | f259d52d361e |
files | TODO ambnews/content/ambnews.js ambnews/content/blank.js |
diffstat | 3 files changed, 53 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/TODO Thu Aug 21 21:08:44 2008 -0700 +++ b/TODO Fri Aug 22 10:02:50 2008 -0700 @@ -6,5 +6,8 @@ * Allow user to star and un-star bookmarks from about:news. * Show tabs, recently closed tabs? Not exactly news-like... * Prioritize news from open tabs? -* Have Vanilla threads show better info * Show less information for lower-priority feeds +* Keep track of what's been clicked on/viewed, politely alert + reader to new content. +* Consider prioritizing based on 'frecency' (see MDC). +* Don't just take pages into account, also take domains into account.
--- a/ambnews/content/ambnews.js Thu Aug 21 21:08:44 2008 -0700 +++ b/ambnews/content/ambnews.js Fri Aug 22 10:02:50 2008 -0700 @@ -13,8 +13,10 @@ if (text) { var resultListener = { handleResult: function resultListener_handleResult(aResult) { + var nsIFeed = aResult.doc; + if (!nsIFeed) + return; feed = {}; - var nsIFeed = aResult.doc; var Ci = Components.interfaces; nsIFeed.QueryInterface(Ci.nsIFeed); feed.link = nsIFeed.link;
--- a/ambnews/content/blank.js Thu Aug 21 21:08:44 2008 -0700 +++ b/ambnews/content/blank.js Fri Aug 22 10:02:50 2008 -0700 @@ -4,31 +4,44 @@ var historyService = Cc["@mozilla.org/browser/nav-history-service;1"] .getService(Ci.nsINavHistoryService); - // no query parameters will get all history - // XXX default sorting is... ? + // No query parameters will get all history. var options = historyService.getNewQueryOptions(); options.resultType = options.RESULTS_AS_URI; options.sortingMode = options.SORT_BY_VISITCOUNT_DESCENDING; - // no query parameters will return everything + // No query parameters will return everything. var query = historyService.getNewQuery(); query.annotation = "ambnews/feed"; - // execute the query + // Execute the query. var result = historyService.executeQuery(query, options); var root = result.root; root.containerOpen = true; + // Index of the feed number that we're looking at. var childNum = 0; + + // Number of feeds we've shown so far. var childrenShown = 0; + + // Maximum numer of feeds we'll show. var maxChildrenToShow = 20; + + // Hashtable that keeps track of what feeds we've shown so far, + // holding both URLs and feed titles. The keys for the values are + // irrelevant; we're just using a hashtable for quick lookup. var shownFeeds = {}; + // TODO: Consider using JS 1.7 generators/coroutines instead of + // the following closures. + + // This function fetches the next feed and then displays it. function getNextFeed() { if (childrenShown == maxChildrenToShow || childNum == root.childCount) { + // We're done! Close our query result container. root.containerOpen = false; } else { var annSvc = AmbNews.__getAnnSvc(); @@ -37,27 +50,48 @@ "ambnews/feed"); childNum++; if (feedUri in shownFeeds) { + // We've already shown this feed, skip to the next one. getNextFeed(); } else { shownFeeds[feedUri] = true; childrenShown++; - AmbNews.getFeed(feedUri, onFeed); + AmbNews.getFeed(feedUri, displayFeed); } } } - function onFeed(feed) { - var text = ""; + // This function displays the given feed. + function displayFeed(feed) { + if (feed && feed.title.text in shownFeeds) + // We've already shown this feed, skip to the next one. + feed = null; if (feed) { + shownFeeds[feed.title.text] = true; + var text = ""; var entriesToShow = 4; + var useAuthor = false; if (feed.entries.length < entriesToShow) entriesToShow = feed.entries.length; + if (entriesToShow > 1 && + feed.entries[0].title.text == feed.entries[1].title.text) + // The feed's entries all have the same title, so display + // author information instead. This is used for Vanilla + // thread feeds. + useAuthor = true; var feedLink = feed.link ? feed.link.spec : ""; text += ('<div class="feed"><div class="feed-title"><a ' + 'href="' + feedLink + '">' + feed.title.text + '</a></div><ul>'); for (var i = 0; i < entriesToShow; i++) { var entryTitle = feed.entries[i].title.text; + if (useAuthor) { + // TODO: Gross, XPCOM cruft. This should be passed to our + // function as a normal JS Array. + entryTitle = feed.entries[i].authors.queryElementAt( + 0, + Components.interfaces.nsIFeedPerson + ).name; + } if (entryTitle.length > 100) { entryTitle = entryTitle.slice(0, 100) + '\u2026'; } @@ -67,10 +101,11 @@ entryTitle + '</a></li>'); } text += '</ul></div>'; - } else - text = "An error occurred."; - //$("#content").append(text); - $(text).hide().fadeIn("slow", getNextFeed).appendTo("#content"); + $(text).hide().fadeIn("slow", getNextFeed).appendTo("#content"); + } else { + // We're skipping this feed, so just process the next one. + window.setTimeout(getNextFeed, 10); + } } getNextFeed();