Implemented 'Delete'.

This commit is contained in:
default 2022-10-01 19:37:47 +02:00
parent 450c0e7aad
commit 82e9a03925
3 changed files with 40 additions and 3 deletions

View File

@ -163,12 +163,16 @@ d_char *recipient_list(snac *snac, char *msg, int expand_public)
for (n = 0; lists[n]; n++) {
char *l = lists[n];
char *v;
xs *tl = NULL;
/* if it's a string, create a list with only one element */
if (xs_type(l) == XSTYPE_STRING) {
if (xs_list_in(list, l) == -1)
list = xs_list_append(list, l);
tl = xs_list_new();
tl = xs_list_append(tl, l);
l = tl;
}
else
while (xs_list_iter(&l, &v)) {
if (expand_public && strcmp(v, public_address) == 0) {
/* iterate the followers and add them */
@ -455,6 +459,25 @@ d_char *msg_undo(snac *snac, char *object)
}
d_char *msg_delete(snac *snac, char *id)
/* creates a 'Delete' + 'Tombstone' for a local entry */
{
xs *tomb = xs_dict_new();
d_char *msg = NULL;
/* sculpt the tombstone */
tomb = xs_dict_append(tomb, "type", "Tombstone");
tomb = xs_dict_append(tomb, "id", id);
/* now create the Delete */
msg = msg_base(snac, "Delete", "@object", snac->actor, "@now", tomb);
msg = xs_dict_append(msg, "to", public_address);
return msg;
}
d_char *msg_follow(snac *snac, char *actor)
/* creates a 'Follow' message */
{

13
html.c
View File

@ -930,6 +930,19 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size,
}
else
if (strcmp(action, L("Delete")) == 0) {
/* delete an entry */
if (xs_startswith(id, snac.actor)) {
/* it's a post by us: generate a delete */
xs *msg = msg_delete(&snac, id);
post(&snac, msg);
snac_log(&snac, xs_fmt("posted tombstone for %s", id));
}
timeline_del(&snac, id);
snac_log(&snac, xs_fmt("deleted entry %s", id));
}
else
status = 404;

1
snac.h
View File

@ -114,6 +114,7 @@ d_char *msg_create(snac *snac, char *object);
d_char *msg_follow(snac *snac, char *actor);
d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to);
d_char *msg_undo(snac *snac, char *object);
d_char *msg_delete(snac *snac, char *id);
int activitypub_request(snac *snac, char *url, d_char **data);
int actor_request(snac *snac, char *actor, d_char **data);