From d8fcff1a2d6eb61c97c44790dbdb920ba9f52980 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Thu, 4 Apr 2013 15:49:31 +0200 Subject: add showing unread posts --- forummodel.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'forummodel.cpp') 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 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::loadTopics(int start, int end) const int rows = end - start + 1; QList 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::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 { -- cgit v1.2.3