summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2022-09-25 18:28:15 +0200
committerGravatar default2022-09-25 18:28:15 +0200
commit6169932733a2fdc7d00a29669960770c4fbaf5d3 (patch)
tree17ffceb40a8652c448160d7d091cfb5b7ad2f357
parentNew function timeline_admire(). (diff)
downloadsnac2-6169932733a2fdc7d00a29669960770c4fbaf5d3.tar.gz
snac2-6169932733a2fdc7d00a29669960770c4fbaf5d3.tar.xz
snac2-6169932733a2fdc7d00a29669960770c4fbaf5d3.zip
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)
75} 75}
76 76
77 77
78void timeline_request(snac *snac, char *id)
79/* ensures that an entry and its ancestors are in the timeline */
80{
81 if (!xs_is_null(id)) {
82 /* is the admired object already there? */
83 if (!timeline_here(snac, id)) {
84 int status;
85 xs *object = NULL;
86
87 /* no; download it */
88 status = activitypub_request(snac, id, &object);
89
90 if (valid_status(status)) {
91 /* does it have an ancestor? */
92 char *in_reply_to = xs_dict_get(object, "inReplyTo");
93
94 /* recurse! */
95 timeline_request(snac, in_reply_to);
96
97 /* finally store */
98 timeline_add(snac, id, object, in_reply_to);
99 }
100 }
101 }
102}
103
104
78int send_to_inbox(snac *snac, char *inbox, char *msg, d_char **payload, int *p_size) 105int send_to_inbox(snac *snac, char *inbox, char *msg, d_char **payload, int *p_size)
79/* sends a message to an Inbox */ 106/* sends a message to an Inbox */
80{ 107{
@@ -204,10 +231,7 @@ void process_message(snac *snac, char *msg, char *req)
204 char *id = xs_dict_get(object, "id"); 231 char *id = xs_dict_get(object, "id");
205 char *in_reply_to = xs_dict_get(object, "inReplyTo"); 232 char *in_reply_to = xs_dict_get(object, "inReplyTo");
206 233
207 if (xs_is_null(in_reply_to)) { 234 timeline_request(snac, in_reply_to);
208 /* recursively download ancestors */
209 /* ... */
210 }
211 235
212 snac_log(snac, xs_fmt("new 'Note' %s %s", actor, id)); 236 snac_log(snac, xs_fmt("new 'Note' %s %s", actor, id));
213 timeline_add(snac, id, msg, in_reply_to); 237 timeline_add(snac, id, msg, in_reply_to);
@@ -229,17 +253,24 @@ void process_message(snac *snac, char *msg, char *req)
229 snac_debug(snac, 2, xs_fmt("xs_type for 'Like' object not string")); 253 snac_debug(snac, 2, xs_fmt("xs_type for 'Like' object not string"));
230 } 254 }
231 else 255 else
232/* 256 if (strcmp(type, "Announce") == 0) {
233 || strcmp(type, "Announce") == 0) { 257 if (xs_type(object) == XSTYPE_STRING) {
258 timeline_request(snac, object);
259
260 timeline_admire(snac, object, actor, 0);
261 }
262 else
263 snac_debug(snac, 2, xs_fmt("xs_type for 'Announce' object not string"));
234 } 264 }
265/*
235 else 266 else
236 if (strcmp(type, "Update") == 0) { 267 if (strcmp(type, "Update") == 0) {
237 } 268 }
238 else 269 else
239 if (strcmp(type, "Delete") == 0) { 270 if (strcmp(type, "Delete") == 0) {
240 } 271 }
241 else
242*/ 272*/
273 else
243 snac_debug(snac, 1, xs_fmt("process_message type '%s' ignored", type)); 274 snac_debug(snac, 1, xs_fmt("process_message type '%s' ignored", type));
244} 275}
245 276
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)
290} 290}
291 291
292 292
293int timeline_here(snac *snac, char *id)
294/* checks if an object is already downloaded */
295{
296 xs *fn = _timeline_find_fn(snac, id);
297
298 return fn != NULL;
299}
300
301
293d_char *timeline_find(snac *snac, char *id) 302d_char *timeline_find(snac *snac, char *id)
294/* gets a message from the timeline by id */ 303/* gets a message from the timeline by id */
295{ 304{
@@ -549,6 +558,8 @@ void timeline_add(snac *snac, char *id, char *o_msg, char *parent)
549 msg = xs_dict_set(msg, "_snac", md); 558 msg = xs_dict_set(msg, "_snac", md);
550 559
551 _timeline_write(snac, id, msg, parent); 560 _timeline_write(snac, id, msg, parent);
561
562 snac_log(snac, xs_fmt("timeline_add %s", id));
552} 563}
553 564
554 565
@@ -593,6 +604,9 @@ void timeline_admire(snac *snac, char *id, char *admirer, int like)
593 unlink(ofn); 604 unlink(ofn);
594 605
595 _timeline_write(snac, id, msg, xs_dict_get(meta, "parent")); 606 _timeline_write(snac, id, msg, xs_dict_get(meta, "parent"));
607
608 snac_log(snac, xs_fmt("timeline_admire (%s) %s %s",
609 like ? "Like" : "Announce", id, admirer));
596 } 610 }
597 } 611 }
598} 612}
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);
51int follower_check(snac *snac, char *actor); 51int follower_check(snac *snac, char *actor);
52d_char *follower_list(snac *snac); 52d_char *follower_list(snac *snac);
53 53
54int timeline_here(snac *snac, char *id);
54d_char *timeline_find(snac *snac, char *id); 55d_char *timeline_find(snac *snac, char *id);
55void timeline_del(snac *snac, char *id); 56void timeline_del(snac *snac, char *id);
56d_char *timeline_get(snac *snac, char *fn); 57d_char *timeline_get(snac *snac, char *fn);