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/activitypub/apactivity.cpp | 6 ------ src/activitypub/apactivity.h | 11 ++++++++--- src/activitypub/apactor.h | 5 +++++ src/activitypub/apobject.h | 5 +++++ src/activitypub/appost.h | 5 +++++ src/activitypub/apreblog.h | 5 +++++ 6 files changed, 28 insertions(+), 9 deletions(-) (limited to 'src/activitypub') diff --git a/src/activitypub/apactivity.cpp b/src/activitypub/apactivity.cpp index b44f87a..ebd9d18 100644 --- a/src/activitypub/apactivity.cpp +++ b/src/activitypub/apactivity.cpp @@ -2,8 +2,6 @@ #include "apactor.h" #include "src/settings_interface.h" -#include - APActivity::APActivity() {} APActivity::APActivity(APActivityFields fields) { @@ -22,10 +20,6 @@ APActivity::APActivity(APActivityFields fields) { object = fields.object; } -APActivity::~APActivity() { - delete object; -} - QString APActivity::get_html_render(HtmlRenderDetails render_info) { QString html(get_html_template(QStringLiteral("apactivity"))); diff --git a/src/activitypub/apactivity.h b/src/activitypub/apactivity.h index fcfb86c..dd6c09e 100644 --- a/src/activitypub/apactivity.h +++ b/src/activitypub/apactivity.h @@ -5,6 +5,8 @@ #include "apobject.h" #include "../types.h" #include +#include +#include enum struct APActivityType {CREATE, ANNOUNCE, UNKNOWN}; @@ -14,7 +16,7 @@ struct APActivityFields { QStringList cc_actors; QString object_url; // maps to "id", represents the Activity, *not* the URL of the object it contains QString published; - APObject* object; // will generally be a APPost or APReblog + APObjectPtr object; // will generally be a APPost or APReblog StatusType visibility; APActivityType type = APActivityType::UNKNOWN; }; @@ -25,9 +27,9 @@ public: // An Activity that can easily be constructed from an ActivityStreams JSON Activity. Make sure to pass the APObject. APActivity(APActivityFields fields); - ~APActivity(); + ~APActivity() {}; - APObject* object = nullptr; // the object that's manipulated by this Activity, use APPost for something useful and "manually" create it + APObjectPtr object; // the object that's manipulated by this Activity, use APPost for something useful and "manually" create it QString get_html_render(HtmlRenderDetails render_info); @@ -43,3 +45,6 @@ private: QDateTime published; }; + +typedef std::shared_ptr APActivityPtr; +Q_DECLARE_METATYPE(APActivityPtr); diff --git a/src/activitypub/apactor.h b/src/activitypub/apactor.h index ad8d689..70d80de 100644 --- a/src/activitypub/apactor.h +++ b/src/activitypub/apactor.h @@ -3,6 +3,8 @@ #include "apbase.h" #include "apattachment.h" #include +#include +#include #include struct APPropertyValue { @@ -57,6 +59,9 @@ private: // APActorList known_as; }; +typedef std::shared_ptr APActorPtr; +Q_DECLARE_METATYPE(APActorPtr); + class APActorList : public std::vector, APBase { public: QString get_html_render(HtmlRenderDetails render_info); diff --git a/src/activitypub/apobject.h b/src/activitypub/apobject.h index 62e60c8..5f17e80 100644 --- a/src/activitypub/apobject.h +++ b/src/activitypub/apobject.h @@ -5,6 +5,8 @@ #include "apattachment.h" #include "../types.h" #include +#include +#include class APObject : protected APBase { public: @@ -34,3 +36,6 @@ protected: APAttachmentList attachments; }; + +typedef std::shared_ptr APObjectPtr; +Q_DECLARE_METATYPE(APObjectPtr); diff --git a/src/activitypub/appost.h b/src/activitypub/appost.h index ccbedd9..8fe6430 100644 --- a/src/activitypub/appost.h +++ b/src/activitypub/appost.h @@ -3,6 +3,8 @@ #include "apobject.h" #include "apbase.h" #include "fields.h" +#include +#include #include // APPost represents an ActivityPub Note Object @@ -23,3 +25,6 @@ protected: QString get_html_status_languages(); }; + +typedef std::shared_ptr APPostPtr; +Q_DECLARE_METATYPE(APPostPtr); diff --git a/src/activitypub/apreblog.h b/src/activitypub/apreblog.h index cc340b8..66a6382 100644 --- a/src/activitypub/apreblog.h +++ b/src/activitypub/apreblog.h @@ -3,6 +3,8 @@ #include "apobject.h" #include "apobject.h" #include "src/types.h" +#include +#include #include struct APReblogFields { @@ -25,3 +27,6 @@ protected: APObject object; // the object that was reblogged (impossible to be an APReblog) StatusType visibility; }; + +typedef std::shared_ptr APReblogPtr; +Q_DECLARE_METATYPE(APReblogPtr); -- cgit v1.2.3-54-g00ecf