commit 0bba515
default
·
2022-12-23 09:01:10 +0000 UTC
parent a24b27b
timeline_request() fixes the canonical id for the object.
2 files changed,
+20,
-13
M
html.c
+18,
-11
1@@ -78,22 +78,29 @@ int actor_request(snac *snac, char *actor, d_char **data)
2 }
3
4
5-int timeline_request(snac *snac, char *id, char *referrer)
6+int timeline_request(snac *snac, char **id, char *referrer)
7 /* ensures that an entry and its ancestors are in the timeline */
8 {
9 int status = 0;
10
11- if (!xs_is_null(id)) {
12+ if (!xs_is_null(*id)) {
13 /* is the admired object already there? */
14- if (!object_here(id)) {
15+ if (!object_here(*id)) {
16 xs *object = NULL;
17
18 /* no; download it */
19- status = activitypub_request(snac, id, &object);
20+ status = activitypub_request(snac, *id, &object);
21
22 if (valid_status(status)) {
23+ char *oid = *id;
24 char *type = xs_dict_get(object, "type");
25
26+ /* get the id again from the object, as it may be different */
27+ *id = xs_dict_get(object, "id");
28+
29+ if (strcmp(*id, oid) != 0)
30+ snac_debug(snac, 0, xs_fmt("canonic id for %s is %s", oid, *id));
31+
32 if (!xs_is_null(type) && strcmp(type, "Note") == 0) {
33 char *actor = xs_dict_get(object, "attributedTo");
34
35@@ -105,10 +112,10 @@ int timeline_request(snac *snac, char *id, char *referrer)
36 char *in_reply_to = xs_dict_get(object, "inReplyTo");
37
38 /* recurse! */
39- timeline_request(snac, in_reply_to, referrer);
40+ timeline_request(snac, &in_reply_to, referrer);
41
42 /* finally store */
43- timeline_add(snac, id, object, in_reply_to, referrer);
44+ timeline_add(snac, *id, object, in_reply_to, referrer);
45 }
46 }
47 }
48@@ -410,7 +417,7 @@ d_char *msg_admiration(snac *snac, char *object, char *type)
49 d_char *msg = NULL;
50
51 /* call the object */
52- timeline_request(snac, object, snac->actor);
53+ timeline_request(snac, &object, snac->actor);
54
55 if (valid_status(object_get(object, &a_msg, NULL))) {
56 xs *rcpts = xs_list_new();
57@@ -420,7 +427,7 @@ d_char *msg_admiration(snac *snac, char *object, char *type)
58 rcpts = xs_list_append(rcpts, public_address);
59 rcpts = xs_list_append(rcpts, xs_dict_get(a_msg, "attributedTo"));
60
61- msg = xs_dict_append(msg, "to", rcpts);
62+ msg = xs_dict_append(msg, "to", rcpts);
63 }
64 else
65 snac_log(snac, xs_fmt("msg_admiration cannot retrieve object %s", object));
66@@ -603,7 +610,7 @@ d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to, char
67 xs *p_msg = NULL;
68
69 /* demand this thing */
70- timeline_request(snac, in_reply_to, NULL);
71+ timeline_request(snac, &in_reply_to, NULL);
72
73 if (valid_status(object_get(in_reply_to, &p_msg, NULL))) {
74 /* add this author as recipient */
75@@ -876,7 +883,7 @@ int process_message(snac *snac, char *msg, char *req)
76 char *id = xs_dict_get(object, "id");
77 char *in_reply_to = xs_dict_get(object, "inReplyTo");
78
79- timeline_request(snac, in_reply_to, NULL);
80+ timeline_request(snac, &in_reply_to, NULL);
81
82 if (timeline_add(snac, id, object, in_reply_to, NULL)) {
83 snac_log(snac, xs_fmt("new 'Note' %s %s", actor, id));
84@@ -916,7 +923,7 @@ int process_message(snac *snac, char *msg, char *req)
85 if (xs_type(object) == XSTYPE_DICT)
86 object = xs_dict_get(object, "id");
87
88- timeline_request(snac, object, actor);
89+ timeline_request(snac, &object, actor);
90
91 if (valid_status(object_get(object, &a_msg, NULL))) {
92 char *who = xs_dict_get(a_msg, "attributedTo");
M
html.c
+2,
-2
1@@ -1358,7 +1358,7 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size,
2
3 if (msg != NULL) {
4 enqueue_message(&snac, msg);
5- timeline_admire(&snac, msg, id, snac.actor, 1);
6+ timeline_admire(&snac, msg, xs_dict_get(msg, "object"), snac.actor, 1);
7 }
8 }
9 else
10@@ -1367,7 +1367,7 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size,
11
12 if (msg != NULL) {
13 enqueue_message(&snac, msg);
14- timeline_admire(&snac, msg, id, snac.actor, 0);
15+ timeline_admire(&snac, msg, xs_dict_get(msg, "object"), snac.actor, 0);
16 }
17 }
18 else