From bf73a19e11e5cccd22f58a5c97e1346dab5587c8 Mon Sep 17 00:00:00 2001 From: ConfuSomu Date: Thu, 3 Aug 2023 17:23:33 +0200 Subject: Create an Archive base class This class is inherited by MastodonArchive to provide Mastodon (and compatible) archive reading support. A base Archive class allows implementing reading support of other archive formats that are from other services. --- src/archive/mastodon.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/archive/mastodon.h (limited to 'src/archive/mastodon.h') diff --git a/src/archive/mastodon.h b/src/archive/mastodon.h new file mode 100644 index 0000000..48be1f3 --- /dev/null +++ b/src/archive/mastodon.h @@ -0,0 +1,40 @@ +#pragma once + +#include "src/archive/base_archive.h" +#include "src/activitypub/fields.h" +#include "src/types.h" + +#include +#include +#include +#include +#include + +class MastodonArchive : public Archive { +public: + MastodonArchive(const QString& filename); + ~MastodonArchive(); + std::variant init(); + + void update_status_list(ViewStatusTypes allowed_types, QListWidget *parent); + const QString get_html_status_info(int status_index, int text_zone_width, StatusType status_type, QLocale* locale); + const QString get_html_status_text(int status_index); +private: + QDir archive_root_dir; + QDir attachment_dir; + bool attachment_dir_have_to_find = true; + + QJsonObject *outbox_json = nullptr; + QJsonArray *outbox_items = nullptr; + + bool is_status_type_allowed(StatusType status_type, ViewStatusTypes allowed_types); + StatusType get_status_type(QJsonObject obj); + QStringList get_status_object_list(QJsonObject obj, QString element_name) ; + QStringList get_status_object_language_list(QJsonObject obj, QString element_name); + std::vector get_status_attachments_list(QJsonValueRef attachments_ref); + void find_attachment_dir(QString example_attachment); + + // Check the `object`, which may be a simple string or a QJsonArray, for the existance of a string `item`. + // Returns true if the `item` exists, else false. + bool json_check_item(const QJsonValue& object, const QString& item); +}; -- cgit v1.2.3-54-g00ecf