[all] Add updateFeed() method

This commit is contained in:
Alberto Mardegan 2015-04-09 21:56:03 +03:00
parent 19caad3bb1
commit ba910a2e1b

View file

@ -101,6 +101,7 @@ function initState(showAll) {
'feeditemstar': false,
'feeditemunread': false,
'feeditemrss': false,
'updatefeed': false,
};
responsesPending = {
@ -112,6 +113,7 @@ function initState(showAll) {
'feeditemstar': false,
'feeditemunread': false,
'feeditemrss': false,
'updatefeed': false,
};
// Set default values given as parameters
@ -691,6 +693,57 @@ function process_updateFeedItems(callback, httpreq) {
}
}
/**
* Update the feed on the server.
* @param {int} The id of the feed whose items should be updated.
* @param {function} A callback function with parameters boolean (indicating
* success) and string (an optional error message).
*/
function updateFeed(feedId, callback) {
trace(2, "Update feed: " + feedId);
if (responsesPending['updatefeed']) {
return;
}
// needs to be logged in
if (!state['token']) {
requestsPending['updatefeed'] = true;
processPendingRequests(callback);
return;
}
responsesPending['updatefeed'] = true;
var params = {
'op': 'updateFeed',
'sid': state['token'],
'feed_id': feedId
}
networkCall(params, function(http) { process_updateFeed(callback, http) });
}
/** @private */
function process_updateFeed(callback, httpreq) {
var response = process_readyState(httpreq);
responsesPending['updatefeed'] = false;
if (!response.successful) {
trace(1, "Update feed: " + response.errorMessage);
if (callback) {
callback(false, response.errorMessage);
}
return;
}
if (!processPendingRequests(callback) && callback) {
// This action is complete (as there's no other requests to do)
// Fire callback saying all ok
callback(true);
}
}
/**
* Mark specified feed as read.
* @param {int} The id of the feed which should be marked as read.