diff options
| author | 2022-10-01 19:37:47 +0200 | |
|---|---|---|
| committer | 2022-10-01 19:37:47 +0200 | |
| commit | 82e9a03925d27d9228ac5a20445b02902a70d0ca (patch) | |
| tree | 61fc680d00bfbfa02fdc77d7a85030187187323f | |
| parent | More snac-origin work. (diff) | |
| download | snac2-82e9a03925d27d9228ac5a20445b02902a70d0ca.tar.gz snac2-82e9a03925d27d9228ac5a20445b02902a70d0ca.tar.xz snac2-82e9a03925d27d9228ac5a20445b02902a70d0ca.zip | |
Implemented 'Delete'.
| -rw-r--r-- | activitypub.c | 29 | ||||
| -rw-r--r-- | html.c | 13 | ||||
| -rw-r--r-- | snac.h | 1 |
3 files changed, 40 insertions, 3 deletions
diff --git a/activitypub.c b/activitypub.c index 99fe498..21316c0 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -163,12 +163,16 @@ d_char *recipient_list(snac *snac, char *msg, int expand_public) | |||
| 163 | for (n = 0; lists[n]; n++) { | 163 | for (n = 0; lists[n]; n++) { |
| 164 | char *l = lists[n]; | 164 | char *l = lists[n]; |
| 165 | char *v; | 165 | char *v; |
| 166 | xs *tl = NULL; | ||
| 166 | 167 | ||
| 168 | /* if it's a string, create a list with only one element */ | ||
| 167 | if (xs_type(l) == XSTYPE_STRING) { | 169 | if (xs_type(l) == XSTYPE_STRING) { |
| 168 | if (xs_list_in(list, l) == -1) | 170 | tl = xs_list_new(); |
| 169 | list = xs_list_append(list, l); | 171 | tl = xs_list_append(tl, l); |
| 172 | |||
| 173 | l = tl; | ||
| 170 | } | 174 | } |
| 171 | else | 175 | |
| 172 | while (xs_list_iter(&l, &v)) { | 176 | while (xs_list_iter(&l, &v)) { |
| 173 | if (expand_public && strcmp(v, public_address) == 0) { | 177 | if (expand_public && strcmp(v, public_address) == 0) { |
| 174 | /* iterate the followers and add them */ | 178 | /* iterate the followers and add them */ |
| @@ -455,6 +459,25 @@ d_char *msg_undo(snac *snac, char *object) | |||
| 455 | } | 459 | } |
| 456 | 460 | ||
| 457 | 461 | ||
| 462 | d_char *msg_delete(snac *snac, char *id) | ||
| 463 | /* creates a 'Delete' + 'Tombstone' for a local entry */ | ||
| 464 | { | ||
| 465 | xs *tomb = xs_dict_new(); | ||
| 466 | d_char *msg = NULL; | ||
| 467 | |||
| 468 | /* sculpt the tombstone */ | ||
| 469 | tomb = xs_dict_append(tomb, "type", "Tombstone"); | ||
| 470 | tomb = xs_dict_append(tomb, "id", id); | ||
| 471 | |||
| 472 | /* now create the Delete */ | ||
| 473 | msg = msg_base(snac, "Delete", "@object", snac->actor, "@now", tomb); | ||
| 474 | |||
| 475 | msg = xs_dict_append(msg, "to", public_address); | ||
| 476 | |||
| 477 | return msg; | ||
| 478 | } | ||
| 479 | |||
| 480 | |||
| 458 | d_char *msg_follow(snac *snac, char *actor) | 481 | d_char *msg_follow(snac *snac, char *actor) |
| 459 | /* creates a 'Follow' message */ | 482 | /* creates a 'Follow' message */ |
| 460 | { | 483 | { |
| @@ -930,6 +930,19 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size, | |||
| 930 | } | 930 | } |
| 931 | else | 931 | else |
| 932 | if (strcmp(action, L("Delete")) == 0) { | 932 | if (strcmp(action, L("Delete")) == 0) { |
| 933 | /* delete an entry */ | ||
| 934 | if (xs_startswith(id, snac.actor)) { | ||
| 935 | /* it's a post by us: generate a delete */ | ||
| 936 | xs *msg = msg_delete(&snac, id); | ||
| 937 | |||
| 938 | post(&snac, msg); | ||
| 939 | |||
| 940 | snac_log(&snac, xs_fmt("posted tombstone for %s", id)); | ||
| 941 | } | ||
| 942 | |||
| 943 | timeline_del(&snac, id); | ||
| 944 | |||
| 945 | snac_log(&snac, xs_fmt("deleted entry %s", id)); | ||
| 933 | } | 946 | } |
| 934 | else | 947 | else |
| 935 | status = 404; | 948 | status = 404; |
| @@ -114,6 +114,7 @@ d_char *msg_create(snac *snac, char *object); | |||
| 114 | d_char *msg_follow(snac *snac, char *actor); | 114 | d_char *msg_follow(snac *snac, char *actor); |
| 115 | d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to); | 115 | d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to); |
| 116 | d_char *msg_undo(snac *snac, char *object); | 116 | d_char *msg_undo(snac *snac, char *object); |
| 117 | d_char *msg_delete(snac *snac, char *id); | ||
| 117 | 118 | ||
| 118 | int activitypub_request(snac *snac, char *url, d_char **data); | 119 | int activitypub_request(snac *snac, char *url, d_char **data); |
| 119 | int actor_request(snac *snac, char *actor, d_char **data); | 120 | int actor_request(snac *snac, char *actor, d_char **data); |