diff options
author | Javier S. Pedro <maemo@javispedro.com> | 2013-04-04 15:49:31 +0200 |
---|---|---|
committer | Javier S. Pedro <maemo@javispedro.com> | 2013-04-04 15:49:31 +0200 |
commit | d8fcff1a2d6eb61c97c44790dbdb920ba9f52980 (patch) | |
tree | 49df7f1e07e34061301ad5944a1807feba24b526 /fetchpostsaction.cpp | |
parent | 11b4152301b408c7a4f02a8b202fed9f5e1ee1e7 (diff) | |
download | tapasboard-d8fcff1a2d6eb61c97c44790dbdb920ba9f52980.tar.gz tapasboard-d8fcff1a2d6eb61c97c44790dbdb920ba9f52980.zip |
add showing unread posts
Diffstat (limited to 'fetchpostsaction.cpp')
-rw-r--r-- | fetchpostsaction.cpp | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/fetchpostsaction.cpp b/fetchpostsaction.cpp index 2493aa3..714718c 100644 --- a/fetchpostsaction.cpp +++ b/fetchpostsaction.cpp @@ -59,6 +59,16 @@ void FetchPostsAction::handleFinishedCall() QSqlDatabase db = _board->database(); db.transaction(); + bool ok = false; + int topic_id = map["topic_id"].toInt(&ok); + if (!ok) { + // Not fatal, just assume it's the one we requested + topic_id = _topicId; + } + QString topic_title = map["topic_title"].toString(); + int unread_position = map["position"].toInt(); + qDebug() << "unread_position" << unread_position; + QSqlQuery query(db); query.prepare("INSERT OR REPLACE INTO posts (topic_id, post_id, post_title, post_content, post_author_id, post_author_name, can_edit, icon_url, post_time, last_update_time) " "VALUES (:topic_id, :post_id, :post_title, :post_content, :post_author_id, :post_author_name, :can_edit, :icon_url, :post_time, :last_update_time)"); @@ -66,11 +76,6 @@ void FetchPostsAction::handleFinishedCall() foreach (const QVariant& post_v, posts) { QVariantMap post = post_v.toMap(); bool ok = false; - int topic_id = post["topic_id"].toInt(&ok); - if (!ok) { - // Not fatal, just assume it's the one we requested - topic_id = _topicId; - } int post_id = post["post_id"].toInt(&ok); if (!ok) { qWarning() << "No post_id in" << post; @@ -79,7 +84,7 @@ void FetchPostsAction::handleFinishedCall() query.bindValue(":topic_id", topic_id); query.bindValue(":post_id", post_id); - query.bindValue(":post_title", unencodePostText(post["post_title"])); + query.bindValue(":post_title", unencodePostTitle(post["post_title"], topic_title)); query.bindValue(":post_content", unencodePostContent(post["post_content"])); query.bindValue(":post_author_id", post["post_author_id"].toInt()); query.bindValue(":post_author_name", unencodePostText(post["post_author_name"])); @@ -100,6 +105,10 @@ void FetchPostsAction::handleFinishedCall() _board->notifyTopicPostsChanged(_topicId, _start, _start + posts.size() - 1); } + if (unread_position > 0) { + // API says this is 1-indexed instead of 0-indexed. + _board->notifyTopicPostsUnread(_topicId, unread_position - 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 @@ -120,6 +129,15 @@ QString FetchPostsAction::unencodePostText(const QVariant &v) return QString::fromUtf8(ba.constData(), ba.length()); } +QString FetchPostsAction::unencodePostTitle(const QVariant &v, const QString &topicTitle) +{ + QString title = unencodePostText(v); + if (QString::compare(title, "Re: " + topicTitle, Qt::CaseInsensitive)) { + return QString(); + } + return title; +} + QString FetchPostsAction::unencodePostContent(const QVariant &v) { QString richText = _board->bbcodeToRichText(unencodePostText(v)); |