aboutsummaryrefslogtreecommitdiffstats
path: root/src/archive_parser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/archive_parser.cpp')
-rw-r--r--src/archive_parser.cpp76
1 files changed, 73 insertions, 3 deletions
diff --git a/src/archive_parser.cpp b/src/archive_parser.cpp
index 62edfd9..603ffa7 100644
--- a/src/archive_parser.cpp
+++ b/src/archive_parser.cpp
@@ -4,7 +4,6 @@
#include <QFile>
#include <QJsonParseError>
-#include <QDebug>
#include <QTextDocument>
Archive::Archive(QString outbox_filename, ArchiveType archive_type) :
@@ -48,14 +47,84 @@ Archive::~Archive() {
delete outbox_items; outbox_items = nullptr;
}
+bool is_status_type_allowed(StatusType status_type, ViewStatusTypes allowed_types) {
+ switch (status_type) {
+ case PUBLIC: return allowed_types.includePublic;
+ case UNLISTED: return allowed_types.includeUnlisted;
+ case PRIVATE: return allowed_types.includePrivate;
+ case DIRECT: return allowed_types.includeDirect;
+ default: return true;
+ }
+}
+
+StatusType get_status_type(QJsonObject obj) {
+ /*
+ * public:
+ * to: #Public
+ * unlisted:
+ * to: /followers
+ * cc: #Public
+ * followers:
+ * to: /followers
+ * direct:
+ * to: the Actors mentioned
+ */
+
+ StatusType status_type = UNKNOWN;
+ bool is_private_or_unlisted = false;
+
+ QJsonArray to;
+
+ if (obj.value("to").isArray()) {
+
+ to = obj.value("to").toArray();
+
+ // see https://www.w3.org/TR/activitypub/#public-addressing
+ for (auto collection : to) {
+ QString col = collection.toString();
+ if (col == "https://www.w3.org/ns/activitystreams#Public") {
+ return PUBLIC; // status' privacy can only be promoted to a higher level
+ }
+ else if (col.endsWith("/followers")) // at least for Mastodon…
+ is_private_or_unlisted = true; // private or unlisted
+ }
+ }
+
+ if (obj.value("cc").isArray()) {
+ QJsonArray cc = obj.value("cc").toArray();
+
+ for (auto collection : cc) {
+ QString col = collection.toString();
+ if (col == "https://www.w3.org/ns/activitystreams#Public" and is_private_or_unlisted) {
+ return UNLISTED; // status' privacy can only be promoted to a higher level
+ }
+ }
+ if (is_private_or_unlisted)
+ return PRIVATE;
+ else if (to.size() > 0)
+ return DIRECT;
+ else if (to.size() == 0 and cc.size() == 0) // sending a direct message to yourself or to another actor that doesn't exist anymore
+ return DIRECT;
+ }
+
+ return status_type;
+}
+
void Archive::update_status_list(ViewStatusTypes allowed_types, QListWidget *parent) {
int i = 0;
for (auto&& item : *outbox_items) {
if (item.isObject()){
QJsonObject obj = item.toObject();
- // TODO: check the status type by looking at cc field
- StatusType status_type = PUBLIC;
+ if (not obj.value("type").isString()) // this shouldn't happen, but you never know
+ goto next_item;
+ if (obj.value("type").toString() != "Create") // ignoring everything that isn't a Create activity for now
+ goto next_item;
+
+ // Determine the status' type
+ StatusType status_type = get_status_type(obj);
+ if (not is_status_type_allowed(status_type, allowed_types))
+ goto next_item;
if (obj.value("object").isObject()) {
QJsonObject activity = obj.value("object").toObject();
@@ -69,6 +138,7 @@ void Archive::update_status_list(ViewStatusTypes allowed_types, QListWidget *par
}
}
}
+ next_item:
++i;
}
}