From 4579089fde7d3c64ed98767714700f30e243e7ae Mon Sep 17 00:00:00 2001 From: ConfuSomu Date: Sat, 25 Feb 2023 15:58:21 -0500 Subject: Implement Announce activity support This commit adds support for listing Announce activities/reblogs in the status list. These can be hidden using the new "Show reblogs" action in the "View" menu. --- src/archive_parser.cpp | 30 ++++++++++++++++++++++++++---- src/archive_parser.h | 2 +- src/list_item.cpp | 6 +++++- src/list_item.h | 1 + src/mainwindow.cpp | 11 ++++++++--- src/mainwindow.h | 1 + src/mainwindow.ui | 12 ++++++++++++ src/types.h | 1 + 8 files changed, 55 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/archive_parser.cpp b/src/archive_parser.cpp index 0ace163..d677f84 100644 --- a/src/archive_parser.cpp +++ b/src/archive_parser.cpp @@ -54,6 +54,7 @@ bool is_status_type_allowed(StatusType status_type, ViewStatusTypes allowed_type case UNLISTED: return allowed_types.includeUnlisted; case PRIVATE: return allowed_types.includePrivate; case DIRECT: return allowed_types.includeDirect; + case REBLOG: return allowed_types.includeReblogs; default: return true; } } @@ -119,15 +120,20 @@ void Archive::update_status_list(ViewStatusTypes allowed_types, QListWidget *par if (not obj.value("type").isString()) // this shouldn't happen, but you never know goto next_item; - if (obj.value("type").toString() != "Create") // ignoring everything that isn't a Create activity for now + + QString activity_type = obj.value("type").toString(); + if (not (activity_type == "Create" or activity_type == "Announce")) // ignoring everything that isn't a Create or Announce activity for now goto next_item; // Determine the status' type - StatusType status_type = get_status_type(obj); + StatusType status_type; + if (activity_type == "Announce") status_type = REBLOG; + else status_type = get_status_type(obj); + if (not is_status_type_allowed(status_type, allowed_types)) goto next_item; - if (obj.value("object").isObject()) { + if (activity_type == "Create" and obj.value("object").isObject()) { QJsonObject activity = obj.value("object").toObject(); bool has_attachment = false; @@ -144,6 +150,8 @@ void Archive::update_status_list(ViewStatusTypes allowed_types, QListWidget *par ListItem *item = new ListItem(strip_html.toPlainText(), status_type, has_attachment, parent, i); } + } else if (activity_type == "Announce" and obj["object"].isString()) { + ListItem *item = new ListItem(activity_type, REBLOG, false, parent, i); } } next_item: @@ -237,7 +245,7 @@ QString Archive::get_html_status_attachments(QJsonValueRef attachments_ref, int } // status_index is assumed to be a valid index -QString Archive::get_html_status_info(int status_index, int text_zone_width) { +QString Archive::get_html_status_info(int status_index, int text_zone_width, StatusType status_type) { QString info_text(*get_html_status_info_template()); QJsonObject obj = outbox_items->at(status_index).toObject(); @@ -271,6 +279,20 @@ QString Archive::get_html_status_info(int status_index, int text_zone_width) { if (activity["content"].isString()) { info_text.replace("{{content}}", activity["content"].toString()); } + } else if (obj["object"].isString()) { + QString text = obj["object"].toString(); + QString content_text; + + if (status_type == REBLOG) { + content_text = "Reblog of this object: {{url}}"; + content_text.replace("{{url}}", text); + info_text.replace("{{url-status}}", text); + } else + content_text = text; + + info_text.replace("{{content}}", content_text); + info_text.replace("{{summary}}", "(empty)"); + info_text.replace("{{attachment-div}}", ""); } return info_text; diff --git a/src/archive_parser.h b/src/archive_parser.h index fba97cd..5d45812 100644 --- a/src/archive_parser.h +++ b/src/archive_parser.h @@ -30,7 +30,7 @@ public: InitError init(); void update_status_list(ViewStatusTypes allowed_types, QListWidget *parent); - QString get_html_status_info(int status_index, int text_zone_width); + QString get_html_status_info(int status_index, int text_zone_width, StatusType status_type); QString get_html_status_text(int status_index); private: QString outbox_filename; diff --git a/src/list_item.cpp b/src/list_item.cpp index 7ecbe57..b7ee578 100644 --- a/src/list_item.cpp +++ b/src/list_item.cpp @@ -13,7 +13,7 @@ QIcon* choose_icon(StatusType status_type) { } ListItem::ListItem(const QString &text, StatusType status_type, bool has_attachement, QListWidget *parent, int index) : - status_index(index), has_attachement(has_attachement) + status_index(index), has_attachement(has_attachement), status_type(status_type) { setText(text); setIcon(*choose_icon(status_type)); @@ -35,3 +35,7 @@ ListItem::ListItem(const QString &text, StatusType status_type, bool has_attache int ListItem::get_status_index() { return status_index; } + +StatusType ListItem::get_status_type() { + return status_type; +} diff --git a/src/list_item.h b/src/list_item.h index 866a98f..c722a72 100644 --- a/src/list_item.h +++ b/src/list_item.h @@ -11,6 +11,7 @@ public: ListItem(const QString &text, StatusType status_type, bool has_attachement, QListWidget *parent = nullptr, int index = 0); int get_status_index(); + StatusType get_status_type(); private: int status_index; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 3a2c5d2..26df799 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -75,7 +75,7 @@ void MainWindow::on_actionAbout_triggered(bool checked) { void MainWindow::on_listWidget_itemActivated(QListWidgetItem *item) { ListItem* casted = dynamic_cast(item); if (casted != nullptr) { - QString status_info = data_archive->get_html_status_info(casted->get_status_index(), ui->statusInfoText->width()); + QString status_info = data_archive->get_html_status_info(casted->get_status_index(), ui->statusInfoText->width(), casted->get_status_type()); ui->statusInfoText->setHtml(status_info); } } @@ -133,9 +133,9 @@ void MainWindow::relist_statuses() { void MainWindow::reset_view_filters() { if (ui->actionAll_toots->isChecked()) - view_filters = {true, true, true, true, view_filters.onlyWithAttachment}; + view_filters = {true, true, true, true, true, view_filters.onlyWithAttachment}; else - view_filters = {false, false, false, false, view_filters.onlyWithAttachment}; + view_filters = {false, false, false, false, view_filters.includeReblogs, view_filters.onlyWithAttachment}; } void MainWindow::on_actionAll_toots_triggered(bool checked) { @@ -191,6 +191,11 @@ void MainWindow::on_actionOnly_with_attachment_triggered(bool checked) { view_filters_changed = true; } +void MainWindow::on_actionReblogs_triggered(bool checked) { + view_filters.includeReblogs = checked; + view_filters_changed = true; +} + void MainWindow::on_menuView_aboutToHide() { if (view_filters_changed) relist_statuses(); diff --git a/src/mainwindow.h b/src/mainwindow.h index a0640de..c37ce28 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -30,6 +30,7 @@ private slots: void on_actionPrivate_toots_triggered(bool checked); void on_actionDirect_messages_triggered(bool checked); void on_actionOnly_with_attachment_triggered(bool checked); + void on_actionReblogs_triggered(bool checked); void on_buttonRandom_clicked(); void on_buttonCopy_clicked(); diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 9a21968..4019896 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -108,6 +108,7 @@ p, li { white-space: pre-wrap; } + @@ -207,6 +208,17 @@ p, li { white-space: pre-wrap; } Only list toots that have an attachment + + + true + + + true + + + Show reblogs + + listWidget diff --git a/src/types.h b/src/types.h index 15c3f08..6cef8aa 100644 --- a/src/types.h +++ b/src/types.h @@ -5,6 +5,7 @@ struct ViewStatusTypes { bool includeUnlisted = true; bool includePrivate = true; bool includeDirect = true; + bool includeReblogs = true; bool onlyWithAttachment = false; }; -- cgit v1.2.3-54-g00ecf