From a962b2d93227557c68a719b2401f8d6bb3969899 Mon Sep 17 00:00:00 2001 From: ConfuSomu Date: Thu, 5 Jan 2023 15:26:28 -0500 Subject: Allow only listing statuses which have attachments --- src/archive_parser.cpp | 9 ++++++++- src/list_item.cpp | 4 ++-- src/list_item.h | 4 ++-- 3 files changed, 12 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/archive_parser.cpp b/src/archive_parser.cpp index d3b9197..d9d4cf1 100644 --- a/src/archive_parser.cpp +++ b/src/archive_parser.cpp @@ -129,12 +129,19 @@ void Archive::update_status_list(ViewStatusTypes allowed_types, QListWidget *par if (obj.value("object").isObject()) { QJsonObject activity = obj.value("object").toObject(); + bool has_attachment = false; + if (activity.contains("attachment") and not activity["attachment"].toArray().isEmpty()) + has_attachment = true; + + if (allowed_types.onlyWithAttachment and not has_attachment) + goto next_item; + if (activity.value("content").isString()) { // Strip HTML for display in list, according to https://stackoverflow.com/a/12157835 QTextDocument strip_html; strip_html.setHtml(activity.value("content").toString()); - ListItem *item = new ListItem(strip_html.toPlainText(), status_type, parent, i); + ListItem *item = new ListItem(strip_html.toPlainText(), status_type, has_attachment, parent, i); } } } diff --git a/src/list_item.cpp b/src/list_item.cpp index b84f147..7ecbe57 100644 --- a/src/list_item.cpp +++ b/src/list_item.cpp @@ -12,8 +12,8 @@ QIcon* choose_icon(StatusType status_type) { } } -ListItem::ListItem(const QString &text, StatusType status_type, QListWidget *parent, int index) : - status_index(index) +ListItem::ListItem(const QString &text, StatusType status_type, bool has_attachement, QListWidget *parent, int index) : + status_index(index), has_attachement(has_attachement) { setText(text); setIcon(*choose_icon(status_type)); diff --git a/src/list_item.h b/src/list_item.h index ce5b6b2..866a98f 100644 --- a/src/list_item.h +++ b/src/list_item.h @@ -9,11 +9,11 @@ public: ArchiveListItemType = QListWidgetItem::UserType }; - ListItem(const QString &text, StatusType status_type, QListWidget *parent = nullptr, int index = 0); + ListItem(const QString &text, StatusType status_type, bool has_attachement, QListWidget *parent = nullptr, int index = 0); int get_status_index(); private: int status_index; StatusType status_type; - bool has_attachement; + bool has_attachement = false; }; -- cgit v1.2.3-54-g00ecf