Merge branch 'server-update' into ubuntu
This commit is contained in:
commit
5cedf98aaa
2 changed files with 76 additions and 0 deletions
|
|
@ -29,6 +29,7 @@ ListModel {
|
|||
property variant feed
|
||||
property int continuation: 0
|
||||
property bool hasMoreItems: false
|
||||
property bool requestServerUpdate: false
|
||||
|
||||
property var categories
|
||||
|
||||
|
|
@ -36,7 +37,25 @@ ListModel {
|
|||
signal itemPublishedChanged(variant item)
|
||||
signal itemStarChanged(variant item)
|
||||
|
||||
onFeedChanged: requestServerUpdate = false
|
||||
|
||||
function update() {
|
||||
if (requestServerUpdate) {
|
||||
var ttrss = rootWindow.getTTRSS();
|
||||
ttrss.updateFeed(feed.feedId,
|
||||
function(successful, errorMessage) {
|
||||
if (successful) {
|
||||
requestServerUpdate = false;
|
||||
}
|
||||
doUpdate();
|
||||
});
|
||||
} else {
|
||||
doUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
/** @private */
|
||||
function doUpdate() {
|
||||
var ttrss = rootWindow.getTTRSS();
|
||||
ttrss.updateFeedItems(feed.feedId, feed.isCat, continuation,
|
||||
function(successful, errorMessage) {
|
||||
|
|
@ -132,6 +151,10 @@ ListModel {
|
|||
} else {
|
||||
hasMoreItems = false
|
||||
}
|
||||
|
||||
if (!hasMoreItems) {
|
||||
requestServerUpdate = true
|
||||
}
|
||||
}
|
||||
|
||||
function getSelectedItem() {
|
||||
|
|
|
|||
|
|
@ -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