summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordefault <nobody@localhost>2022-09-25 18:28:15 +0200
committerdefault <nobody@localhost>2022-09-25 18:28:15 +0200
commit6169932733a2fdc7d00a29669960770c4fbaf5d3 (patch)
tree17ffceb40a8652c448160d7d091cfb5b7ad2f357
parentbb70101feca64224759581d73404240bb4d35f5b (diff)
New function timeline_request().
-rw-r--r--activitypub.c45
-rw-r--r--data.c14
-rw-r--r--snac.h1
3 files changed, 53 insertions, 7 deletions
diff --git a/activitypub.c b/activitypub.c
index 07cf5d7..7c93ca5 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -75,6 +75,33 @@ int actor_request(snac *snac, char *actor, d_char **data)
}
+void timeline_request(snac *snac, char *id)
+/* ensures that an entry and its ancestors are in the timeline */
+{
+ if (!xs_is_null(id)) {
+ /* is the admired object already there? */
+ if (!timeline_here(snac, id)) {
+ int status;
+ xs *object = NULL;
+
+ /* no; download it */
+ status = activitypub_request(snac, id, &object);
+
+ if (valid_status(status)) {
+ /* does it have an ancestor? */
+ char *in_reply_to = xs_dict_get(object, "inReplyTo");
+
+ /* recurse! */
+ timeline_request(snac, in_reply_to);
+
+ /* finally store */
+ timeline_add(snac, id, object, in_reply_to);
+ }
+ }
+ }
+}
+
+
int send_to_inbox(snac *snac, char *inbox, char *msg, d_char **payload, int *p_size)
/* sends a message to an Inbox */
{
@@ -204,10 +231,7 @@ void process_message(snac *snac, char *msg, char *req)
char *id = xs_dict_get(object, "id");
char *in_reply_to = xs_dict_get(object, "inReplyTo");
- if (xs_is_null(in_reply_to)) {
- /* recursively download ancestors */
- /* ... */
- }
+ timeline_request(snac, in_reply_to);
snac_log(snac, xs_fmt("new 'Note' %s %s", actor, id));
timeline_add(snac, id, msg, in_reply_to);
@@ -229,17 +253,24 @@ void process_message(snac *snac, char *msg, char *req)
snac_debug(snac, 2, xs_fmt("xs_type for 'Like' object not string"));
}
else
-/*
- || strcmp(type, "Announce") == 0) {
+ if (strcmp(type, "Announce") == 0) {
+ if (xs_type(object) == XSTYPE_STRING) {
+ timeline_request(snac, object);
+
+ timeline_admire(snac, object, actor, 0);
+ }
+ else
+ snac_debug(snac, 2, xs_fmt("xs_type for 'Announce' object not string"));
}
+/*
else
if (strcmp(type, "Update") == 0) {
}
else
if (strcmp(type, "Delete") == 0) {
}
- else
*/
+ else
snac_debug(snac, 1, xs_fmt("process_message type '%s' ignored", type));
}
diff --git a/data.c b/data.c
index 7aab0e6..9fa06ae 100644
--- a/data.c
+++ b/data.c
@@ -290,6 +290,15 @@ d_char *_timeline_find_fn(snac *snac, char *id)
}
+int timeline_here(snac *snac, char *id)
+/* checks if an object is already downloaded */
+{
+ xs *fn = _timeline_find_fn(snac, id);
+
+ return fn != NULL;
+}
+
+
d_char *timeline_find(snac *snac, char *id)
/* gets a message from the timeline by id */
{
@@ -549,6 +558,8 @@ void timeline_add(snac *snac, char *id, char *o_msg, char *parent)
msg = xs_dict_set(msg, "_snac", md);
_timeline_write(snac, id, msg, parent);
+
+ snac_log(snac, xs_fmt("timeline_add %s", id));
}
@@ -593,6 +604,9 @@ void timeline_admire(snac *snac, char *id, char *admirer, int like)
unlink(ofn);
_timeline_write(snac, id, msg, xs_dict_get(meta, "parent"));
+
+ snac_log(snac, xs_fmt("timeline_admire (%s) %s %s",
+ like ? "Like" : "Announce", id, admirer));
}
}
}
diff --git a/snac.h b/snac.h
index 3fde037..82e2c2f 100644
--- a/snac.h
+++ b/snac.h
@@ -51,6 +51,7 @@ int follower_del(snac *snac, char *actor);
int follower_check(snac *snac, char *actor);
d_char *follower_list(snac *snac);
+int timeline_here(snac *snac, char *id);
d_char *timeline_find(snac *snac, char *id);
void timeline_del(snac *snac, char *id);
d_char *timeline_get(snac *snac, char *fn);