summaryrefslogtreecommitdiff
path: root/fetchtopicsaction.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fetchtopicsaction.cpp')
-rw-r--r--fetchtopicsaction.cpp47
1 files changed, 37 insertions, 10 deletions
diff --git a/fetchtopicsaction.cpp b/fetchtopicsaction.cpp
index 4617280..1c6cc86 100644
--- a/fetchtopicsaction.cpp
+++ b/fetchtopicsaction.cpp
@@ -10,8 +10,9 @@
#include "xmlrpcreply.h"
#include "fetchtopicsaction.h"
-FetchTopicsAction::FetchTopicsAction(int forumId, int start, int end, Board *board) :
- Action(board), _forumId(forumId), _start(start), _end(end)
+FetchTopicsAction::FetchTopicsAction(int forumId, Board::TopicType type,
+ int start, int end, Board *board) :
+ Action(board), _forumId(forumId), _type(type), _start(start), _end(end)
{
}
@@ -19,7 +20,7 @@ bool FetchTopicsAction::isSupersetOf(Action *action) const
{
FetchTopicsAction *other = qobject_cast<FetchTopicsAction*>(action);
if (other) {
- if (other->_forumId == _forumId) {
+ if (other->_forumId == _forumId && other->_type == _type) {
if (_end == FetchAllTopics) {
// If this is fetching all topics, then this is a superset
// of every other action... except those that also fetch all
@@ -48,8 +49,27 @@ void FetchTopicsAction::execute()
// After finishing this action, a new one will be enqueued with the next 50.
}
- _call = _board->service()->asyncCall("get_topic",
- QString::number(_forumId), _start, end);
+ switch (_type) {
+ case Board::Normal:
+ _call = _board->service()->asyncCall("get_topic",
+ QString::number(_forumId),
+ _start, end);
+ break;
+ case Board::Sticky:
+ _call = _board->service()->asyncCall("get_topic",
+ QString::number(_forumId),
+ _start, end,
+ QString("TOP"));
+ break;
+ case Board::Announcement:
+ _call = _board->service()->asyncCall("get_topic",
+ QString::number(_forumId),
+ _start, end,
+ QString("ANN"));
+ break;
+ }
+ Q_ASSERT(_call);
+
_call->setParent(this);
connect(_call, SIGNAL(finished(XmlRpcPendingCall*)), SLOT(handleFinishedCall()));
}
@@ -77,8 +97,8 @@ void FetchTopicsAction::handleFinishedCall()
int position = _start;
QSqlQuery query(db);
- query.prepare("INSERT OR REPLACE INTO topics (forum_id, topic_id, topic_title, topic_author_id, topic_author_name, is_subscribed, is_closed, icon_url, last_reply_time, reply_number, new_post, position, last_update_time) "
- "VALUES (:forum_id, :topic_id, :topic_title, :topic_author_id, :topic_author_name, :is_subscribed, :is_closed, :icon_url, :last_reply_time, :reply_number, :new_post, :position, :last_update_time)");
+ query.prepare("INSERT OR REPLACE INTO topics (forum_id, topic_id, topic_type, topic_title, topic_author_id, topic_author_name, is_subscribed, is_closed, icon_url, last_reply_time, reply_number, new_post, position, last_update_time) "
+ "VALUES (:forum_id, :topic_id, :topic_type, :topic_title, :topic_author_id, :topic_author_name, :is_subscribed, :is_closed, :icon_url, :last_reply_time, :reply_number, :new_post, :position, :last_update_time)");
foreach (const QVariant& topic_v, topics) {
@@ -99,6 +119,7 @@ void FetchTopicsAction::handleFinishedCall()
query.bindValue(":forum_id", forum_id);
query.bindValue(":topic_id", topic_id);
+ query.bindValue(":topic_type", _type);
query.bindValue(":topic_title", decodeTopicText(topic["topic_title"]));
query.bindValue(":topic_author_id", topic["topic_author_id"].toInt());
query.bindValue(":topic_author_name", decodeTopicText(topic["topic_author_name"]));
@@ -128,8 +149,11 @@ void FetchTopicsAction::handleFinishedCall()
if (eof) {
// Service did not return as many topics as we expected, thus we
// can safely delete any topics after the current position.
- query.prepare("DELETE FROM topics WHERE forum_id = :forum_id AND position >= :position");
+ query.prepare("DELETE FROM topics "
+ "WHERE forum_id = :forum_id AND topic_type = :topic_type "
+ " AND position >= :position");
query.bindValue(":forum_id", _forumId);
+ query.bindValue(":topic_type", _type);
query.bindValue(":position", position);
if (query.exec()) {
position += query.numRowsAffected(); // Advance the position counter
@@ -173,7 +197,7 @@ void FetchTopicsAction::handleFinishedCall()
db.commit();
if (position > _start) {
- _board->notifyForumTopicsChanged(_forumId,
+ _board->notifyForumTopicsChanged(_forumId, _type,
_start, position - 1);
}
if (_end == FetchAllTopics && !eof) {
@@ -181,6 +205,7 @@ void FetchTopicsAction::handleFinishedCall()
// there are probably more of them
int next_start = fetched_end + 1;
_board->enqueueAction(new FetchTopicsAction(_forumId,
+ _type,
next_start,
FetchAllTopics,
_board));
@@ -204,9 +229,11 @@ QList<int> FetchTopicsAction::getCurrentDbTopics(int start, int end)
{
QSqlQuery query(_board->database());
query.prepare("SELECT topic_id FROM topics "
- "WHERE forum_id = :forum_id AND position BETWEEN :start AND :end "
+ "WHERE forum_id = :forum_id AND topic_type = :topic_type AND "
+ " position BETWEEN :start AND :end "
"ORDER by position ASC");
query.bindValue(":forum_id", _forumId);
+ query.bindValue(":topic_type", _type);
query.bindValue(":start", start);
query.bindValue(":end", end);
if (query.exec()) {