aboutsummaryrefslogtreecommitdiffstats
path: root/src/archive
diff options
context:
space:
mode:
authorConfuSomu2024-03-20 13:28:19 -0400
committerConfuSomu2024-03-20 13:28:19 -0400
commit4e59eadba3b0d4586a9122e6a825ea030a139c9a (patch)
tree6674c2b23ef6295e7a8d60bb034c3321e7a5a996 /src/archive
parent0e32ef940e53c4f10d84762f2de6836025f87610 (diff)
downloadActorViewer-4e59eadba3b0d4586a9122e6a825ea030a139c9a.tar
ActorViewer-4e59eadba3b0d4586a9122e6a825ea030a139c9a.tar.gz
ActorViewer-4e59eadba3b0d4586a9122e6a825ea030a139c9a.zip
Use smart pointers with AP classes and Instance
Diffstat (limited to 'src/archive')
-rw-r--r--src/archive/base_archive.cpp2
-rw-r--r--src/archive/base_archive.h4
-rw-r--r--src/archive/mastodon.cpp15
-rw-r--r--src/archive/mastodon.h6
4 files changed, 14 insertions, 13 deletions
diff --git a/src/archive/base_archive.cpp b/src/archive/base_archive.cpp
index 472abb1..0e96c61 100644
--- a/src/archive/base_archive.cpp
+++ b/src/archive/base_archive.cpp
@@ -16,6 +16,6 @@ const QString Archive::get_instance_address() {
return "";
}
-APActor* Archive::get_main_actor() {
+APActorPtr Archive::get_main_actor() {
return nullptr;
}
diff --git a/src/archive/base_archive.h b/src/archive/base_archive.h
index 27259b3..c361fd5 100644
--- a/src/archive/base_archive.h
+++ b/src/archive/base_archive.h
@@ -34,10 +34,10 @@ public:
static Archive* create_archive(ArchiveType archive_type, const QString& main_filename);
virtual void update_status_list(ViewStatusTypes allowed_types, QListWidget *parent) = 0;
- virtual APActivity* get_activity(ArchiveItemRef index, Hinting_t hinting) = 0;
+ virtual APActivityPtr get_activity(ArchiveItemRef index, Hinting_t hinting) = 0;
// Get the Actor that represents the data export, the user who's account data has been exported.
// Return nullptr if the Actor cannot be retrieved
- virtual APActor* get_main_actor();
+ virtual APActorPtr get_main_actor();
virtual const QString get_html_status_text(ArchiveItemRef status_index) = 0;
virtual const QString get_instance_address();
diff --git a/src/archive/mastodon.cpp b/src/archive/mastodon.cpp
index 121c366..044056c 100644
--- a/src/archive/mastodon.cpp
+++ b/src/archive/mastodon.cpp
@@ -1,4 +1,5 @@
#include "mastodon.h"
+#include "src/activitypub/apactor.h"
#include "src/list_item.h"
#include "src/types.h"
#include "src/activitypub/apactivity.h"
@@ -237,7 +238,7 @@ std::vector<APAttachmentFields> MastodonArchive::get_status_attachments_list(QJs
return list;
}
-APActivity* MastodonArchive::get_activity(ArchiveItemRef index, Hinting_t hinting) {
+APActivityPtr MastodonArchive::get_activity(ArchiveItemRef index, Hinting_t hinting) {
// the JSON AP Activity
QJsonObject activity = outbox_items->at(index).toObject();
@@ -320,17 +321,17 @@ APActivity* MastodonArchive::get_activity(ArchiveItemRef index, Hinting_t hintin
obj_url = activity["object"].toString();
if (not obj_url.isNull())
- act_fields.object = new APReblog({obj_url, act_fields.visibility});
+ act_fields.object = std::make_shared<APReblog>(APReblogFields {obj_url, act_fields.visibility});
else switch(obj_type) {
case APObjectType::UNKNOWN:
case APObjectType::NOTE:
- act_fields.object = new APPost(obj_fields); break;
+ act_fields.object = std::make_shared<APPost>(obj_fields); break;
case APObjectType::QUESTION:
- act_fields.object = new APQuestion(obj_fields); break;
+ act_fields.object = std::make_shared<APQuestion>(obj_fields); break;
}
// 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 new APActivity(act_fields);
+ return std::make_shared<APActivity>(act_fields);
}
// TODO: make this use an APActivity object that will be present as an StatusListItem member.
@@ -355,7 +356,7 @@ const QString MastodonArchive::get_html_status_text(ArchiveItemRef index) {
return text;
}
-APActor* MastodonArchive::get_main_actor() {
+APActorPtr MastodonArchive::get_main_actor() {
// Avoid recreating the Actor each time by caching it
if (actor) return actor;
@@ -436,7 +437,7 @@ APActor* MastodonArchive::get_main_actor() {
obj_fields.header = new APAttachment(att_fields);
}
- actor = new APActor(obj_fields);
+ actor = std::make_shared<APActor>(obj_fields);
// TODO: query type. it seems to be always "Person", but maybe if the account is a bot, it changes?
// The code also currently ignores possible featured tags and users
diff --git a/src/archive/mastodon.h b/src/archive/mastodon.h
index f148047..355210c 100644
--- a/src/archive/mastodon.h
+++ b/src/archive/mastodon.h
@@ -19,8 +19,8 @@ public:
InitError init();
void update_status_list(ViewStatusTypes allowed_types, QListWidget *parent);
- APActivity* get_activity(ArchiveItemRef index, Hinting_t hinting = {});
- APActor* get_main_actor();
+ APActivityPtr get_activity(ArchiveItemRef index, Hinting_t hinting = {});
+ APActorPtr get_main_actor();
const QString get_html_status_text(ArchiveItemRef status_index);
const QString get_instance_address();
private:
@@ -30,7 +30,7 @@ private:
QJsonObject *outbox_json = nullptr;
QJsonArray *outbox_items = nullptr;
- APActor* actor = nullptr;
+ APActorPtr actor;
bool is_status_type_allowed(StatusType status_type, ViewStatusTypes allowed_types);
StatusType get_status_type(QJsonObject obj);