summaryrefslogtreecommitdiff
path: root/fetchpostsaction.cpp
diff options
context:
space:
mode:
authorJavier S. Pedro <maemo@javispedro.com>2013-04-04 01:15:54 +0200
committerJavier S. Pedro <maemo@javispedro.com>2013-04-04 01:15:54 +0200
commit3c88a76b1be759d13097810877d6e990b3371726 (patch)
treedd5627700ef12be7c55d9f3ceda5a9575691a337 /fetchpostsaction.cpp
parent723e0e7f37636379f76008582dca459490b845f4 (diff)
downloadtapasboard-3c88a76b1be759d13097810877d6e990b3371726.tar.gz
tapasboard-3c88a76b1be759d13097810877d6e990b3371726.zip
implement refresh action
Diffstat (limited to 'fetchpostsaction.cpp')
-rw-r--r--fetchpostsaction.cpp26
1 files changed, 24 insertions, 2 deletions
diff --git a/fetchpostsaction.cpp b/fetchpostsaction.cpp
index 0e4284b..2493aa3 100644
--- a/fetchpostsaction.cpp
+++ b/fetchpostsaction.cpp
@@ -3,6 +3,7 @@
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlQuery>
+#include "global.h"
#include "board.h"
#include "xmlrpcinterface.h"
#include "xmlrpcreply.h"
@@ -18,7 +19,15 @@ bool FetchPostsAction::isSupersetOf(Action *action) const
FetchPostsAction *other = qobject_cast<FetchPostsAction*>(action);
if (other) {
if (other->_topicId == _topicId) {
- if (_start <= other->_start && _end >= other->_end) {
+ if (_end == FetchAllPosts) {
+ // If this is fetching all posts, then this is a superset
+ // of every other action... except those that also fetch all.
+ return other->_end != FetchAllPosts;
+ } else if (other->_end == FetchAllPosts) {
+ // If the other action fetches all posts, this cannot be a
+ // superset
+ return false;
+ } else if (_start <= other->_start && _end >= other->_end) {
return true;
}
}
@@ -28,8 +37,15 @@ bool FetchPostsAction::isSupersetOf(Action *action) const
void FetchPostsAction::execute()
{
+ int end = _end;
+ if (end == FetchAllPosts) {
+ // Fetch posts in blocks of size 50.
+ end = _start + MAX_TOPIC_PAGE_SIZE;
+ // After finishing this action, a new one will be enqueued with the next 50.
+ }
+
_call = _board->service()->asyncCall("get_thread",
- QString::number(_topicId), _start, _end);
+ QString::number(_topicId), _start, end);
_call->setParent(this);
connect(_call, SIGNAL(finished(XmlRpcPendingCall*)), SLOT(handleFinishedCall()));
}
@@ -84,6 +100,12 @@ void FetchPostsAction::handleFinishedCall()
_board->notifyTopicPostsChanged(_topicId,
_start, _start + posts.size() - 1);
}
+ if (_end == FetchAllPosts && posts.size() == MAX_TOPIC_PAGE_SIZE) {
+ // Ok, let's prepare to fetch the next block of posts because
+ // there are probably more of them
+ int start = _start + MAX_TOPIC_PAGE_SIZE;
+ _board->enqueueAction(new FetchPostsAction(_topicId, start, FetchAllPosts, _board));
+ }
} else {
qWarning() << "Could not fetch posts";
// TODO emit error ...