aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorConfuSomu2023-09-12 09:38:16 -0400
committerConfuSomu2023-09-12 09:38:16 -0400
commit40fd76d5b992fb868b44a6f76152655a0408e37b (patch)
tree6e7997fa25d0dfa12831fbed7577d6d7b1d81fdc
parent9c60bc8ce4a0990c228d2cd746791b88c41532b8 (diff)
downloadActorViewer-40fd76d5b992fb868b44a6f76152655a0408e37b.tar
ActorViewer-40fd76d5b992fb868b44a6f76152655a0408e37b.tar.gz
ActorViewer-40fd76d5b992fb868b44a6f76152655a0408e37b.zip
Implement archive method for getting APActivity
This replaces the existing method that returns HTML with a method that gives us an APActivity object, which is more precise and allows more extension in the future.
-rw-r--r--src/archive/base_archive.h8
-rw-r--r--src/archive/mastodon.cpp7
-rw-r--r--src/archive/mastodon.h3
-rw-r--r--src/list_item.cpp6
4 files changed, 17 insertions, 7 deletions
diff --git a/src/archive/base_archive.h b/src/archive/base_archive.h
index 4fdf08c..a6bf98f 100644
--- a/src/archive/base_archive.h
+++ b/src/archive/base_archive.h
@@ -3,6 +3,7 @@
#include <QString>
#include <QListWidget>
#include <variant>
+#include "src/activitypub/apactivity.h"
#include "src/types.h"
enum ArchiveType {
@@ -21,13 +22,18 @@ public:
JsonNotActivityStream // for ActivityPub archives
};
+ struct Hinting_t {
+ StatusType status_type = UNKNOWN;
+ };
+
virtual ~Archive() {};
virtual std::variant<QString, InitError> init() = 0;
static Archive* create_archive(ArchiveType archive_type, const QString& main_filename);
virtual void update_status_list(ViewStatusTypes allowed_types, QListWidget *parent) = 0;
- virtual const QString get_html_status_info(int status_index, int text_zone_width, StatusType status_type, QLocale* locale) = 0;
+ // TODO: use a index type instead of a bare int as the former can be extended
+ virtual APActivity* get_activity(int index, Hinting_t hinting) = 0;
virtual const QString get_html_status_text(int status_index) = 0;
virtual const QString get_instance_address();
diff --git a/src/archive/mastodon.cpp b/src/archive/mastodon.cpp
index 01d476d..238b861 100644
--- a/src/archive/mastodon.cpp
+++ b/src/archive/mastodon.cpp
@@ -237,13 +237,12 @@ std::vector<APAttachmentFields> MastodonArchive::get_status_attachments_list(QJs
return list;
}
-// status_index is assumed to be a valid index
-const QString MastodonArchive::get_html_status_info(int status_index, int text_zone_width, StatusType status_type, QLocale* locale) {
+APActivity* MastodonArchive::get_activity(int status_index, Hinting_t hinting) {
// the JSON AP Activity
QJsonObject activity = outbox_items->at(status_index).toObject();
APActivityFields act_fields = {
- .visibility = status_type
+ .visibility = hinting.status_type
};
QString obj_url;
@@ -331,7 +330,7 @@ const QString MastodonArchive::get_html_status_info(int status_index, int text_z
}
// TODO: it is currently a waste to create this APActivity object that will be immediately destroyed but it allows us to extend archive parsing to something that will become abstract (and an abstract base class) and separate from display (the final goal) which will allow us to add other sources that feed us with posts, reblogs and Actor information. furthermore, these objects can be cached for reuse in a session.
- return APActivity(act_fields).get_html_render({text_zone_width, locale});
+ return new APActivity(act_fields);
}
// TODO: make this use an APActivity object that will be present as an StatusListItem member.
diff --git a/src/archive/mastodon.h b/src/archive/mastodon.h
index 15a89f2..bc9da3e 100644
--- a/src/archive/mastodon.h
+++ b/src/archive/mastodon.h
@@ -2,6 +2,7 @@
#include "src/archive/base_archive.h"
#include "src/activitypub/fields.h"
+#include "src/activitypub/apactivity.h"
#include "src/types.h"
#include <QJsonDocument>
@@ -17,7 +18,7 @@ public:
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);
+ APActivity* get_activity(int index, Hinting_t hinting = {});
const QString get_html_status_text(int status_index);
const QString get_instance_address();
private:
diff --git a/src/list_item.cpp b/src/list_item.cpp
index b235d2b..deead65 100644
--- a/src/list_item.cpp
+++ b/src/list_item.cpp
@@ -1,4 +1,5 @@
#include "list_item.h"
+#include "src/activitypub/apactivity.h"
#include "src/types.h"
#define ICON_PATH_PREFIX "res/icons"
@@ -50,5 +51,8 @@ StatusType StatusListItem::get_status_type() {
}
const QString StatusListItem::get_info_html(int text_zone_width, QLocale* locale) {
- return data_archive->get_html_status_info(status_index, text_zone_width, status_type, locale);
+ APActivity* activity = data_archive->get_activity(status_index, {status_type});
+ QString html = activity->get_html_render({text_zone_width, locale});
+ delete activity; activity = nullptr;
+ return html;
}