From 3c88a76b1be759d13097810877d6e990b3371726 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Thu, 4 Apr 2013 01:15:54 +0200 Subject: implement refresh action --- fetchpostsaction.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'fetchpostsaction.cpp') diff --git a/fetchpostsaction.cpp b/fetchpostsaction.cpp index 0e4284b..2493aa3 100644 --- a/fetchpostsaction.cpp +++ b/fetchpostsaction.cpp @@ -3,6 +3,7 @@ #include #include +#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(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 ... -- cgit v1.2.3