aboutsummaryrefslogtreecommitdiffstats
path: root/src/archive_parser.h
blob: 162787e2568f79c113a7d417baa24d503ba17f0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#pragma once

#include <QString>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QListWidget>
#include <QDir>

#include "types.h"
#include "activitypub/fields.h"

enum ArchiveType {
    MASTODON
};

class Archive {
public:
    enum InitError {
        NoError = 0,
        FailedOpeningFile,
        JsonParseError,
        JsonEmpty,
        JsonNull,
        JsonNotObject,
        JsonNotActivityStream // for ActivityPub archives
    };

    Archive(QString outbox_filename, ArchiveType archive_type);
    ~Archive();
    std::variant<QString, InitError> 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:
    QString outbox_filename;
    QDir archive_root_dir;
    ArchiveType archive_type;
    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<APAttachmentFields> 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);
};