1
0
Fork 0
mirror of https://gitlab.com/niansa/qcommsy.git synced 2025-03-06 20:53:33 +01:00

Show unread posts and bumped UI version

This commit is contained in:
niansa 2020-08-25 19:54:11 +02:00
parent 2236997dba
commit eab9d27b0c
2 changed files with 22 additions and 4 deletions

View file

@ -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<GumboNode *> 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<GumboNode *> 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<commsyFile> files;
};
#define libCommsy_NAME "libcommsy"
#define libCommsy_VERSION "1.1-stable"
#define libCommsy_VERSION "1.2-stable"
class libCommsy {
public:
std::vector<commsyPost> 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

View file

@ -29,7 +29,7 @@
#include <QNetworkRequest>
#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<unsigned long>(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);
}
}
}