From 0d78deef42cd1e5d461d98d2acefd4266d323046 Mon Sep 17 00:00:00 2001 From: default Date: Sun, 22 Oct 2023 09:00:37 +0200 Subject: [PATCH] New function deluser(), to delete a user. Only unfollows by now. --- main.c | 7 ++++++- snac.h | 1 + utils.c | 26 ++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index bce8198..003ad34 100644 --- a/main.c +++ b/main.c @@ -19,6 +19,7 @@ int usage(void) printf("init [{basedir}] Initializes the data storage\n"); printf("upgrade {basedir} Upgrade to a new version\n"); printf("adduser {basedir} [{uid}] Adds a new user\n"); + printf("deluser {basedir} {uid} Deletes a user\n"); printf("httpd {basedir} Starts the HTTPD daemon\n"); printf("purge {basedir} Purges old data\n"); printf("webfinger {basedir} {actor} Queries about an actor (@user@host or actor url)\n"); @@ -169,7 +170,7 @@ int main(int argc, char *argv[]) } if (!user_open(&snac, user)) { - printf("error in user '%s'\n", user); + printf("invalid user '%s'\n", user); return 1; } @@ -179,6 +180,10 @@ int main(int argc, char *argv[]) return resetpwd(&snac); } + if (strcmp(cmd, "deluser") == 0) { /** **/ + return deluser(&snac); + } + if (strcmp(cmd, "queue") == 0) { /** **/ process_user_queue(&snac); return 0; diff --git a/snac.h b/snac.h index 4d103d1..ed0f94d 100644 --- a/snac.h +++ b/snac.h @@ -276,6 +276,7 @@ int html_post_handler(const xs_dict *req, const char *q_path, int snac_init(const char *_basedir); int adduser(const char *uid); int resetpwd(snac *snac); +int deluser(snac *user); extern const char *snac_blurb; diff --git a/utils.c b/utils.c index 21922d1..74058aa 100644 --- a/utils.c +++ b/utils.c @@ -337,3 +337,29 @@ int resetpwd(snac *snac) return ret; } + + +int deluser(snac *user) +/* deletes a user */ +{ + int ret = 0; + xs *fwers = following_list(user); + xs_list *p = fwers; + xs_str *v; + + while (xs_list_iter(&p, &v)) { + xs *object = NULL; + + if (valid_status(following_get(user, v, &object))) { + xs *msg = msg_undo(user, xs_dict_get(object, "object")); + + following_del(user, v); + + enqueue_output_by_actor(user, msg, v, 0); + + printf("Unfollowing actor %s\n", v); + } + } + + return ret; +}