aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorConfuSomu2022-12-28 19:28:01 -0500
committerConfuSomu2022-12-28 19:28:01 -0500
commit1b201ea3a4821a44887202692e9c77961c163a57 (patch)
treefda563859174d5a35560b5fdb2d217cc09911fc3 /src
parentc0cf3a1d0b4ff74ad43d0489631d4b9582b72d81 (diff)
downloadActorViewer-1b201ea3a4821a44887202692e9c77961c163a57.tar
ActorViewer-1b201ea3a4821a44887202692e9c77961c163a57.tar.gz
ActorViewer-1b201ea3a4821a44887202692e9c77961c163a57.zip
Determine status type
Diffstat (limited to 'src')
-rw-r--r--src/archive_parser.cpp76
-rw-r--r--src/list_item.cpp13
-rw-r--r--src/types.h4
3 files changed, 88 insertions, 5 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;
}
}
diff --git a/src/list_item.cpp b/src/list_item.cpp
index a7fde7e..ce7c86e 100644
--- a/src/list_item.cpp
+++ b/src/list_item.cpp
@@ -15,5 +15,16 @@ QIcon* choose_icon(StatusType status_type) {
ListItem::ListItem(const QString &text, StatusType status_type, QListWidget *parent, int index) :
QListWidgetItem(*choose_icon(status_type), text, parent, ArchiveListItemType), status_index(index)
{
-
+#ifndef NDEBUG
+ QString tool_tip;
+ switch (status_type) {
+ case PUBLIC: tool_tip = "Public"; break;
+ case UNLISTED: tool_tip = "Unlisted"; break;
+ case PRIVATE: tool_tip = "Private"; break;
+ case DIRECT: tool_tip = "Direct"; break;
+ case UNKNOWN: tool_tip = "Unknown"; break;
+ case REBLOG: tool_tip = "Reblog"; break;
+ }
+ setToolTip(tool_tip);
+#endif
}
diff --git a/src/types.h b/src/types.h
index b78c564..15c3f08 100644
--- a/src/types.h
+++ b/src/types.h
@@ -9,8 +9,10 @@ struct ViewStatusTypes {
};
enum StatusType {
+ UNKNOWN = 0,
PUBLIC,
UNLISTED,
PRIVATE,
- DIRECT
+ DIRECT,
+ REBLOG
};