summaryrefslogtreecommitdiff
path: root/forummodel.cpp
diff options
context:
space:
mode:
authorJavier S. Pedro <maemo@javispedro.com>2013-04-04 15:49:31 +0200
committerJavier S. Pedro <maemo@javispedro.com>2013-04-04 15:49:31 +0200
commitd8fcff1a2d6eb61c97c44790dbdb920ba9f52980 (patch)
tree49df7f1e07e34061301ad5944a1807feba24b526 /forummodel.cpp
parent11b4152301b408c7a4f02a8b202fed9f5e1ee1e7 (diff)
downloadtapasboard-d8fcff1a2d6eb61c97c44790dbdb920ba9f52980.tar.gz
tapasboard-d8fcff1a2d6eb61c97c44790dbdb920ba9f52980.zip
add showing unread posts
Diffstat (limited to 'forummodel.cpp')
-rw-r--r--forummodel.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/forummodel.cpp b/forummodel.cpp
index 63fb0b8..faf0b75 100644
--- a/forummodel.cpp
+++ b/forummodel.cpp
@@ -15,6 +15,7 @@ ForumModel::ForumModel(QObject *parent) :
roles[IconRole] = QByteArray("icon");
roles[TopicIdRole] = QByteArray("topicId");
roles[NumRepliesRole] = QByteArray("numReplies");
+ roles[UnreadRole] = QByteArray("unread");
setRoleNames(roles);
}
@@ -84,6 +85,8 @@ QVariant ForumModel::data(const QModelIndex &index, int role) const
return _data[row].topic_id;
case NumRepliesRole:
return _data[row].num_replies;
+ case UnreadRole:
+ return _data[row].unread;
}
return QVariant();
@@ -103,7 +106,7 @@ void ForumModel::fetchMore(const QModelIndex &parent)
const int start = _data.size();
QList<Topic> topics = loadTopics(start, start + FORUM_PAGE_SIZE - 1);
- const int new_end = start + _data.size() - 1;
+ const int new_end = start + topics.size() - 1;
if (topics.empty()) {
// We could not load anything more from DB!
@@ -116,11 +119,12 @@ void ForumModel::fetchMore(const QModelIndex &parent)
}
if (_board->service()->isAccessible()) {
- if (!_data.empty()) {
+ if (!topics.empty()) {
QDateTime last = oldestPostUpdate(topics);
// If the topics we got from DB are too old, refresh online.
if (last.secsTo(QDateTime::currentDateTime()) > FORUM_TOPICS_TLL) {
qDebug() << "Fetching topics because of old";
+ Q_ASSERT(new_end > 0);
_board->enqueueAction(new FetchTopicsAction(_forumId,
start,
new_end,
@@ -190,7 +194,7 @@ QList<ForumModel::Topic> ForumModel::loadTopics(int start, int end)
const int rows = end - start + 1;
QList<Topic> topics;
QSqlQuery query(_board->database());
- query.prepare("SELECT topic_id, topic_title, reply_number, last_reply_time, last_update_time FROM topics "
+ query.prepare("SELECT topic_id, topic_title, reply_number, new_post, last_reply_time, last_update_time FROM topics "
"WHERE forum_id = :forum_id "
"ORDER by last_reply_time DESC "
"LIMIT :start, :limit");
@@ -204,8 +208,9 @@ QList<ForumModel::Topic> ForumModel::loadTopics(int start, int end)
topic.topic_id = query.value(0).toInt();
topic.title = query.value(1).toString();
topic.num_replies = query.value(2).toInt();
- topic.last_reply_time = parseDateTime(query.value(3));
- topic.last_update_time = parseDateTime(query.value(4));
+ topic.unread = query.value(3).toBool();
+ topic.last_reply_time = parseDateTime(query.value(4));
+ topic.last_update_time = parseDateTime(query.value(5));
topics.append(topic);
}
} else {