snac2

Fork of https://codeberg.org/grunfink/snac2
git clone https://git.inz.fi/snac2
Log | Files | Refs | README | LICENSE

commit 0db1cf05d1013f9b1e972ae79822f9eda4dede59
parent 0ddbe7e53b8331d2de42ad29ceca35b715f1c121
Author: default <nobody@localhost>
Date:   Sun, 24 Nov 2024 09:14:59 +0100

New web actions "Approve" and "Discard".

Diffstat:
Mhtml.c | 28++++++++++++++++++++++++++++
Msnac.h | 1+
2 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/html.c b/html.c @@ -3700,6 +3700,34 @@ int html_post_handler(const xs_dict *req, const char *q_path, timeline_touch(&snac); } else + if (strcmp(action, L("Approve")) == 0) { /** **/ + xs *fwreq = pending_get(&snac, actor); + + if (fwreq != NULL) { + xs *reply = msg_accept(&snac, fwreq, actor); + + enqueue_message(&snac, reply); + + if (xs_is_null(xs_dict_get(fwreq, "published"))) { + /* add a date if it doesn't include one (Mastodon) */ + xs *date = xs_str_utctime(0, ISO_DATE_SPEC); + fwreq = xs_dict_set(fwreq, "published", date); + } + + timeline_add(&snac, xs_dict_get(fwreq, "id"), fwreq); + + follower_add(&snac, actor); + + pending_del(&snac, actor); + + snac_log(&snac, xs_fmt("new follower %s", actor)); + } + } + else + if (strcmp(action, L("Discard")) == 0) { /** **/ + pending_del(&snac, actor); + } + else status = HTTP_STATUS_NOT_FOUND; /* delete the cached timeline */ diff --git a/snac.h b/snac.h @@ -320,6 +320,7 @@ xs_dict *msg_update(snac *snac, const xs_dict *object); xs_dict *msg_ping(snac *user, const char *rcpt); xs_dict *msg_pong(snac *user, const char *rcpt, const char *object); xs_dict *msg_move(snac *user, const char *new_account); +xs_dict *msg_accept(snac *snac, const xs_val *object, const char *to); xs_dict *msg_question(snac *user, const char *content, xs_list *attach, const xs_list *opts, int multiple, int end_secs);