diff options
Diffstat (limited to 'activitypub.c')
| -rw-r--r-- | activitypub.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/activitypub.c b/activitypub.c index 7a24a69..dcefa87 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -78,22 +78,29 @@ int actor_request(snac *snac, char *actor, d_char **data) | |||
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | 80 | ||
| 81 | int timeline_request(snac *snac, char *id, char *referrer) | 81 | int timeline_request(snac *snac, char **id, char *referrer) |
| 82 | /* ensures that an entry and its ancestors are in the timeline */ | 82 | /* ensures that an entry and its ancestors are in the timeline */ |
| 83 | { | 83 | { |
| 84 | int status = 0; | 84 | int status = 0; |
| 85 | 85 | ||
| 86 | if (!xs_is_null(id)) { | 86 | if (!xs_is_null(*id)) { |
| 87 | /* is the admired object already there? */ | 87 | /* is the admired object already there? */ |
| 88 | if (!object_here(id)) { | 88 | if (!object_here(*id)) { |
| 89 | xs *object = NULL; | 89 | xs *object = NULL; |
| 90 | 90 | ||
| 91 | /* no; download it */ | 91 | /* no; download it */ |
| 92 | status = activitypub_request(snac, id, &object); | 92 | status = activitypub_request(snac, *id, &object); |
| 93 | 93 | ||
| 94 | if (valid_status(status)) { | 94 | if (valid_status(status)) { |
| 95 | char *oid = *id; | ||
| 95 | char *type = xs_dict_get(object, "type"); | 96 | char *type = xs_dict_get(object, "type"); |
| 96 | 97 | ||
| 98 | /* get the id again from the object, as it may be different */ | ||
| 99 | *id = xs_dict_get(object, "id"); | ||
| 100 | |||
| 101 | if (strcmp(*id, oid) != 0) | ||
| 102 | snac_debug(snac, 0, xs_fmt("canonic id for %s is %s", oid, *id)); | ||
| 103 | |||
| 97 | if (!xs_is_null(type) && strcmp(type, "Note") == 0) { | 104 | if (!xs_is_null(type) && strcmp(type, "Note") == 0) { |
| 98 | char *actor = xs_dict_get(object, "attributedTo"); | 105 | char *actor = xs_dict_get(object, "attributedTo"); |
| 99 | 106 | ||
| @@ -105,10 +112,10 @@ int timeline_request(snac *snac, char *id, char *referrer) | |||
| 105 | char *in_reply_to = xs_dict_get(object, "inReplyTo"); | 112 | char *in_reply_to = xs_dict_get(object, "inReplyTo"); |
| 106 | 113 | ||
| 107 | /* recurse! */ | 114 | /* recurse! */ |
| 108 | timeline_request(snac, in_reply_to, referrer); | 115 | timeline_request(snac, &in_reply_to, referrer); |
| 109 | 116 | ||
| 110 | /* finally store */ | 117 | /* finally store */ |
| 111 | timeline_add(snac, id, object, in_reply_to, referrer); | 118 | timeline_add(snac, *id, object, in_reply_to, referrer); |
| 112 | } | 119 | } |
| 113 | } | 120 | } |
| 114 | } | 121 | } |
| @@ -410,7 +417,7 @@ d_char *msg_admiration(snac *snac, char *object, char *type) | |||
| 410 | d_char *msg = NULL; | 417 | d_char *msg = NULL; |
| 411 | 418 | ||
| 412 | /* call the object */ | 419 | /* call the object */ |
| 413 | timeline_request(snac, object, snac->actor); | 420 | timeline_request(snac, &object, snac->actor); |
| 414 | 421 | ||
| 415 | if (valid_status(object_get(object, &a_msg, NULL))) { | 422 | if (valid_status(object_get(object, &a_msg, NULL))) { |
| 416 | xs *rcpts = xs_list_new(); | 423 | xs *rcpts = xs_list_new(); |
| @@ -420,7 +427,7 @@ d_char *msg_admiration(snac *snac, char *object, char *type) | |||
| 420 | rcpts = xs_list_append(rcpts, public_address); | 427 | rcpts = xs_list_append(rcpts, public_address); |
| 421 | rcpts = xs_list_append(rcpts, xs_dict_get(a_msg, "attributedTo")); | 428 | rcpts = xs_list_append(rcpts, xs_dict_get(a_msg, "attributedTo")); |
| 422 | 429 | ||
| 423 | msg = xs_dict_append(msg, "to", rcpts); | 430 | msg = xs_dict_append(msg, "to", rcpts); |
| 424 | } | 431 | } |
| 425 | else | 432 | else |
| 426 | snac_log(snac, xs_fmt("msg_admiration cannot retrieve object %s", object)); | 433 | snac_log(snac, xs_fmt("msg_admiration cannot retrieve object %s", object)); |
| @@ -603,7 +610,7 @@ d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to, char | |||
| 603 | xs *p_msg = NULL; | 610 | xs *p_msg = NULL; |
| 604 | 611 | ||
| 605 | /* demand this thing */ | 612 | /* demand this thing */ |
| 606 | timeline_request(snac, in_reply_to, NULL); | 613 | timeline_request(snac, &in_reply_to, NULL); |
| 607 | 614 | ||
| 608 | if (valid_status(object_get(in_reply_to, &p_msg, NULL))) { | 615 | if (valid_status(object_get(in_reply_to, &p_msg, NULL))) { |
| 609 | /* add this author as recipient */ | 616 | /* add this author as recipient */ |
| @@ -876,7 +883,7 @@ int process_message(snac *snac, char *msg, char *req) | |||
| 876 | char *id = xs_dict_get(object, "id"); | 883 | char *id = xs_dict_get(object, "id"); |
| 877 | char *in_reply_to = xs_dict_get(object, "inReplyTo"); | 884 | char *in_reply_to = xs_dict_get(object, "inReplyTo"); |
| 878 | 885 | ||
| 879 | timeline_request(snac, in_reply_to, NULL); | 886 | timeline_request(snac, &in_reply_to, NULL); |
| 880 | 887 | ||
| 881 | if (timeline_add(snac, id, object, in_reply_to, NULL)) { | 888 | if (timeline_add(snac, id, object, in_reply_to, NULL)) { |
| 882 | snac_log(snac, xs_fmt("new 'Note' %s %s", actor, id)); | 889 | snac_log(snac, xs_fmt("new 'Note' %s %s", actor, id)); |
| @@ -916,7 +923,7 @@ int process_message(snac *snac, char *msg, char *req) | |||
| 916 | if (xs_type(object) == XSTYPE_DICT) | 923 | if (xs_type(object) == XSTYPE_DICT) |
| 917 | object = xs_dict_get(object, "id"); | 924 | object = xs_dict_get(object, "id"); |
| 918 | 925 | ||
| 919 | timeline_request(snac, object, actor); | 926 | timeline_request(snac, &object, actor); |
| 920 | 927 | ||
| 921 | if (valid_status(object_get(object, &a_msg, NULL))) { | 928 | if (valid_status(object_get(object, &a_msg, NULL))) { |
| 922 | char *who = xs_dict_get(a_msg, "attributedTo"); | 929 | char *who = xs_dict_get(a_msg, "attributedTo"); |