From 4e59eadba3b0d4586a9122e6a825ea030a139c9a Mon Sep 17 00:00:00 2001 From: ConfuSomu Date: Wed, 20 Mar 2024 13:28:19 -0400 Subject: Use smart pointers with AP classes and Instance --- src/archive/mastodon.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/archive/mastodon.cpp') 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 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(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(obj_fields); break; case APObjectType::QUESTION: - act_fields.object = new APQuestion(obj_fields); break; + act_fields.object = std::make_shared(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(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(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 -- cgit v1.2.3-54-g00ecf