From eab9d27b0c21fd83c3b99c1d90e1a87aef20ec16 Mon Sep 17 00:00:00 2001 From: niansa Date: Tue, 25 Aug 2020 19:54:11 +0200 Subject: [PATCH] Show unread posts and bumped UI version --- libcommsy.hpp | 11 ++++++++++- main.cpp | 15 ++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/libcommsy.hpp b/libcommsy.hpp index 1a43e14..ea7df5c 100644 --- a/libcommsy.hpp +++ b/libcommsy.hpp @@ -228,6 +228,12 @@ std::string get_post_meta(GumboNode *node) { return clean_spaces(trim(gumbo_cleantext(metanodes[1]))); } +bool get_post_unread(GumboNode *node) { + std::vector elems; + gumbo_search_by_class(elems, node, "cs-comment-change-info", GUMBO_TAG_DIV); + return !elems.empty(); +} + std::string get_post_url(GumboNode *node) { std::vector titlenodes; gumbo_search_by_class(titlenodes, node, "uk-comment-title", GUMBO_TAG_H4); @@ -313,13 +319,14 @@ struct commsyPost { std::string id; std::string description; std::string meta; + bool unread; std::string url; std::vector files; }; #define libCommsy_NAME "libcommsy" -#define libCommsy_VERSION "1.1-stable" +#define libCommsy_VERSION "1.2-stable" class libCommsy { public: std::vector posts; @@ -402,6 +409,8 @@ public: thispost.id = get_post_id(*it); // Get posts meta string thispost.meta = get_post_meta(*it); + // Get if post is unread + thispost.unread = get_post_unread(*it); // Get posts URL thispost.url = get_post_url(*it); // Get posts files diff --git a/main.cpp b/main.cpp index 7d877d2..687c2e9 100644 --- a/main.cpp +++ b/main.cpp @@ -29,7 +29,7 @@ #include #define QCommsy_NAME "QCommsy" -#define QCommsy_VERSION "1.0-stable" +#define QCommsy_VERSION "1.1-dev" #define UPDATE_WINDOW(a) a->processEvents(); @@ -281,11 +281,13 @@ void _UILoader::overviewWindow(bool catchInvalidRoomError) { // Add button handlers w->connect(thisui->postList, &QListWidget::activated, [this, thisui] (QModelIndex index) { auto postID = static_cast(index.row()); + commsyPost *thispost = connector->getPost(postID); thisui->centralwidget->setDisabled(true); + thispost->unread = false; // Mark post as read locally // Run blocking code UPDATE_WINDOW(a) { - postViewWindow(connector->getPost(postID), QString::fromStdString(*connector->getDescription(postID))); + postViewWindow(thispost, QString::fromStdString(*connector->getDescription(postID))); } }); @@ -319,7 +321,14 @@ void _UILoader::overviewWindow(bool catchInvalidRoomError) { thisui->postCounter->setText(QString::number(connector->numposts) + " Einträge"); thisui->postList->clear(); for (const auto& thispost : connector->posts) { - thisui->postList->addItem(QString::fromStdString(thispost.name)); + QString displayName; + + if (thispost.unread) { + displayName.append("(NEU) "); + } + displayName.append(QString::fromStdString(thispost.name)); + + thisui->postList->addItem(displayName); } } }