Bug #251242 --> Adding a new feed through the subscription UI should not block the UI while we do the initial

feed download.
This commit is contained in:
scott%scott-macgregor.org 2004-07-13 20:34:51 +00:00
Родитель 8d64f85ae4
Коммит b9188f69f7
2 изменённых файлов: 52 добавлений и 38 удалений

Просмотреть файл

@ -23,6 +23,8 @@ function Feed(resource) {
this.request = null;
this.downloadCallback = null;
this.items = new Array();
return this;
@ -49,9 +51,7 @@ Feed.prototype.name getter = function() {
return name;
}
Feed.prototype.download = function(async, parseItems) {
// Whether or not to download the feed asynchronously.
async = async == null ? true : async ? true : false;
Feed.prototype.download = function(parseItems, aCallback) {
// Whether or not to parse items when downloading and parsing the feed.
// Defaults to true, but setting to false is useful for obtaining
@ -59,17 +59,16 @@ Feed.prototype.download = function(async, parseItems) {
this.parseItems = parseItems == null ? true : parseItems ? true : false;
this.request = new XMLHttpRequest();
this.request.open("GET", this.url, async);
this.request.open("GET", this.url, true);
this.downloadCallback = aCallback; // may be null
// var loadgroup = this.request.channel.loadgroup;
this.request.overrideMimeType("text/xml");
if (async) {
this.request.onload = Feed.onDownloaded;
this.request.onerror = Feed.onDownloadError;
gFzFeedCache[this.url] = this;
}
this.request.onload = Feed.onDownloaded;
this.request.onerror = Feed.onDownloadError;
gFzFeedCache[this.url] = this;
this.request.send(null);
if (!async) {
this.parse();
}
}
Feed.onDownloaded = function(event) {
@ -80,6 +79,9 @@ Feed.onDownloaded = function(event) {
if (!feed)
throw("error after downloading " + url + ": couldn't retrieve feed from request");
feed.parse();
if (feed.downloadCallback)
feed.downloadCallback(feed);
}
Feed.onDownloadError = function(event) {
@ -88,7 +90,11 @@ Feed.onDownloadError = function(event) {
var url = request.channel.originalURI.spec;
var feed = gFzFeedCache[url];
if (feed)
{
debug(feed.title + " download failed");
if (feed.downloadCallback)
feed.downloadCallback(nsnull);
}
throw("error downloading feed " + url);
}

Просмотреть файл

@ -29,6 +29,39 @@ function openFeedEditor(feedProperties)
{
window.openDialog('feed-properties.xul', 'feedproperties', 'modal,titlebar,chrome,center', feedProperties);
return feedProperties;
}
function finishedDownloadingFeed(feed)
{
// feed is null if our attempt to parse the feed failed
if (feed)
{
debug("after download, feed name = " + feed.name + "\n");
var server = getIncomingServer();
var folder;
try {
var folder = server.rootMsgFolder.getChildNamed(feed.name);
}
catch(e) {
// If we're here, it's probably because the folder doesn't exist yet,
// so create it.
debug("folder for new feed " + feed.name + " doesn't exist; creating");
debug("creating " + feed.name + "as child of " + server.rootMsgFolder + "\n");
server.rootMsgFolder.createSubfolder(feed.name, getMessageWindow());
folder = server.rootMsgFolder.FindSubFolder(feed.name);
var msgdb = folder.getMsgDatabase(null);
var folderInfo = msgdb.dBFolderInfo;
folderInfo.setCharPtrProperty("feedUrl", feed.url);
}
// XXX This should be something like "subscribe to feed".
debug ("feed name = " + feed.name + "\n");
addFeed(feed.url, feed.name, null, folder); // add feed flushes the subscription database
// download the feed items now that we have a folder
feed.download();
}
}
function doAdd() {
@ -52,32 +85,7 @@ function doAdd() {
var itemResource = rdf.GetResource(feedProperties.feedLocation);
feed = new Feed(itemResource);
feed.download(false, false);
debug("after download, feed name = " + feed.name + "\n");
var server = getIncomingServer();
var folder;
try {
var folder = server.rootMsgFolder.getChildNamed(feed.name);
}
catch(e) {
// If we're here, it's probably because the folder doesn't exist yet,
// so create it.
debug("folder for new feed " + feed.name + " doesn't exist; creating");
debug("creating " + feed.name + "as child of " + server.rootMsgFolder + "\n");
server.rootMsgFolder.createSubfolder(feed.name, getMessageWindow());
folder = server.rootMsgFolder.FindSubFolder(feed.name);
var msgdb = folder.getMsgDatabase(null);
var folderInfo = msgdb.dBFolderInfo;
folderInfo.setCharPtrProperty("feedUrl", feedProperties.feedLocation);
}
// XXX This should be something like "subscribe to feed".
dump ("feed name = " + feed.name + "\n");
addFeed(feedProperties.feedLocation, feed.name, null, folder); // add feed flushes the subscription database
// now download it for real, now that we have a folder.
feed.download();
feed.download(false, finishedDownloadingFeed);
}
function doEdit() {