[all] Add updateFeed() method
This commit is contained in:
parent
19caad3bb1
commit
ba910a2e1b
1 changed files with 53 additions and 0 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue