New function deluser(), to delete a user.

Only unfollows by now.
This commit is contained in:
default 2023-10-22 09:00:37 +02:00
parent 575a152305
commit 0d78deef42
3 changed files with 33 additions and 1 deletions

7
main.c
View file

@ -19,6 +19,7 @@ int usage(void)
printf("init [{basedir}] Initializes the data storage\n"); printf("init [{basedir}] Initializes the data storage\n");
printf("upgrade {basedir} Upgrade to a new version\n"); printf("upgrade {basedir} Upgrade to a new version\n");
printf("adduser {basedir} [{uid}] Adds a new user\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("httpd {basedir} Starts the HTTPD daemon\n");
printf("purge {basedir} Purges old data\n"); printf("purge {basedir} Purges old data\n");
printf("webfinger {basedir} {actor} Queries about an actor (@user@host or actor url)\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)) { if (!user_open(&snac, user)) {
printf("error in user '%s'\n", user); printf("invalid user '%s'\n", user);
return 1; return 1;
} }
@ -179,6 +180,10 @@ int main(int argc, char *argv[])
return resetpwd(&snac); return resetpwd(&snac);
} }
if (strcmp(cmd, "deluser") == 0) { /** **/
return deluser(&snac);
}
if (strcmp(cmd, "queue") == 0) { /** **/ if (strcmp(cmd, "queue") == 0) { /** **/
process_user_queue(&snac); process_user_queue(&snac);
return 0; return 0;

1
snac.h
View file

@ -276,6 +276,7 @@ int html_post_handler(const xs_dict *req, const char *q_path,
int snac_init(const char *_basedir); int snac_init(const char *_basedir);
int adduser(const char *uid); int adduser(const char *uid);
int resetpwd(snac *snac); int resetpwd(snac *snac);
int deluser(snac *user);
extern const char *snac_blurb; extern const char *snac_blurb;

26
utils.c
View file

@ -337,3 +337,29 @@ int resetpwd(snac *snac)
return ret; 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;
}