aboutsummaryrefslogtreecommitdiffstats
path: root/src/activitypub
diff options
context:
space:
mode:
Diffstat (limited to 'src/activitypub')
-rw-r--r--src/activitypub/apactor.cpp25
-rw-r--r--src/activitypub/apactor.h42
-rw-r--r--src/activitypub/apattachment.cpp26
-rw-r--r--src/activitypub/apattachment.h4
4 files changed, 94 insertions, 3 deletions
diff --git a/src/activitypub/apactor.cpp b/src/activitypub/apactor.cpp
index 6731dd3..78ed9a3 100644
--- a/src/activitypub/apactor.cpp
+++ b/src/activitypub/apactor.cpp
@@ -1,11 +1,34 @@
#include "apactor.h"
+#include <QDebug>
APActor::APActor() {}
-APActor::APActor(const QString url) {
+APActor::APActor(const QString& url) {
object_url = url;
}
+APActor::APActor(APActorFields& fields) {
+ object_url = fields.url;
+ username = fields.username;
+ name = fields.display_name;
+ summary = fields.summary;
+ manuallyApprovesFollowers = fields.manuallyApprovesFollowers;
+ discoverable = fields.discoverable;
+ joined = QDateTime::fromString(fields.joined_date, Qt::ISODate);
+ avatar = fields.avatar;
+ header = fields.header;
+
+ if (fields.keys.length() == fields.values.length())
+ for (int i = 0; i < fields.keys.length(); ++i)
+ table.push_back({fields.keys[i], fields.values[i]});
+ else qDebug() << "key and value vectors don't have the same lenght!";
+}
+
+APActor::~APActor() {
+ if (avatar) delete avatar;
+ if (header) delete header;
+}
+
const QString APActor::get_url() {
return object_url;
}
diff --git a/src/activitypub/apactor.h b/src/activitypub/apactor.h
index 60ef0bf..ad8d689 100644
--- a/src/activitypub/apactor.h
+++ b/src/activitypub/apactor.h
@@ -1,22 +1,60 @@
#pragma once
#include "apbase.h"
+#include "apattachment.h"
+#include <QDateTime>
#include <vector>
+struct APPropertyValue {
+ QString key;
+ QString value;
+};
+
+struct APActorFields {
+ QString url;
+ QString username; // without the leading '@'
+ QString display_name;
+ QString summary; // Profile biography/description (bio)
+ QStringList keys;
+ QStringList values;
+ APAttachment* avatar = nullptr;
+ APAttachment* header = nullptr;
+ bool manuallyApprovesFollowers = false;
+ bool discoverable = true; // is discoverable or indexable
+ QString joined_date;
+ QStringList also_known_as; // other Actors representing the same user
+};
+
// APActors will have an avatar, display name, username and more that will be fetched using the remote instance
+// Currently missing: featured tags and featured posts
class APActor : APBase {
public:
// Empty actor
APActor();
- APActor(const QString url);
- ~APActor() {};
+ APActor(const QString& url);
+ APActor(APActorFields& fields);
+ ~APActor();
const QString get_url();
QString get_html_render(HtmlRenderDetails render_info);
const QString get_plain_render();
private:
+ friend class TabActorInfo;
+
QString object_url;
+ QString username;
+ QString name; // Display name
+ QString summary; // Profile biography/description (bio)
+ typedef std::vector<APPropertyValue> APPropertyValueList; // Key/value table in profile (example: "web site | http://example.com/")
+ APPropertyValueList table;
+ APAttachment* avatar = nullptr;
+ APAttachment* header = nullptr;
+ bool manuallyApprovesFollowers = false;
+ bool discoverable = true; // is discoverable or indexable
+ QDateTime joined;
+ // TODO: parse the also_known_as field
+ // APActorList known_as;
};
class APActorList : public std::vector<APActor>, APBase {
diff --git a/src/activitypub/apattachment.cpp b/src/activitypub/apattachment.cpp
index 0589291..342ea21 100644
--- a/src/activitypub/apattachment.cpp
+++ b/src/activitypub/apattachment.cpp
@@ -1,5 +1,6 @@
#include "apattachment.h"
#include <QFileInfo>
+#include <QDebug>
APAttachment::APAttachment() {}
@@ -28,6 +29,31 @@ QString APAttachment::get_html_render(HtmlRenderDetails info) {
return html;
}
+const QPixmap& APAttachment::get_pixmap(int width, int height) {
+ if (pixmap) return *pixmap;
+
+ if (width > 0 or height > 0) {
+ QPixmap image(path_url);
+
+ /* proportionality rule:
+ * width image width
+ * ----- = -----------
+ * height image height
+ */
+ if (height == 0)
+ height = (width * image.height()) / image.width();
+ else if (width == 0)
+ width = (height * image.width()) / image.height();
+
+ pixmap = new QPixmap(image.scaled(QSize(width, height)));
+ } else {
+ pixmap = new QPixmap;
+ if (not pixmap->load(path_url))
+ qDebug() << "failed to load" << path_url;
+ }
+ return *pixmap;
+}
+
QString APAttachmentList::get_html_render(HtmlRenderDetails render_info) {
QString html;
diff --git a/src/activitypub/apattachment.h b/src/activitypub/apattachment.h
index ff40dc3..f4e620b 100644
--- a/src/activitypub/apattachment.h
+++ b/src/activitypub/apattachment.h
@@ -2,6 +2,7 @@
#include "apbase.h"
#include "fields.h"
+#include <QPixmap>
#include <array>
#include <vector>
@@ -11,6 +12,7 @@ public:
APAttachment(APAttachmentFields fields);
~APAttachment() {};
QString get_html_render(HtmlRenderDetails render_info);
+ const QPixmap& get_pixmap(int width = 0, int height = 0);
private:
QString blurhash;
@@ -19,6 +21,8 @@ private:
QString description; // alt text, maps to "name"
QString path_url; // attachment URL, might be file on filesystem (make sure that the attachment dir has been found and that the path is correct)
QString filename; // nicer descriptor of the attachment's path
+
+ QPixmap* pixmap = nullptr;
};
class APAttachmentList : public std::vector<APAttachment>, APBase {