commit 1ebf2a2d874f3ee589785e8175abdcb33a963d72
parent 99230ba053238d7ad80b7793c7a8a8752e7b7049
Author: default <nobody@localhost>
Date: Fri, 18 Apr 2025 09:08:48 +0200
New command-line option 'add_to_list'.
Diffstat:
2 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/data.c b/data.c
@@ -2404,7 +2404,7 @@ xs_val *list_content(snac *user, const char *list, const char *actor_md5, int op
break;
case 1: /** append actor to list **/
- if (actor_md5 != NULL) {
+ if (xs_is_string(actor_md5) && xs_is_hex(actor_md5)) {
if (!index_in_md5(fn, actor_md5))
index_add_md5(fn, actor_md5);
}
@@ -2412,7 +2412,7 @@ xs_val *list_content(snac *user, const char *list, const char *actor_md5, int op
break;
case 2: /** delete actor from list **/
- if (actor_md5 != NULL)
+ if (xs_is_string(actor_md5) && xs_is_hex(actor_md5))
index_del_md5(fn, actor_md5);
break;
diff --git a/main.c b/main.c
@@ -61,6 +61,9 @@ int usage(void)
printf("import_block_list {basedir} {uid} {file} Imports a Mastodon CSV block list file\n");
printf("lists {basedir} {uid} Returns the names of the lists created by the user\n");
printf("list_members {basedir} {uid} {name} Returns the list of accounts inside a list\n");
+ printf("create_list {basedir} {uid} {name} Creates a new list\n");
+ printf("delete_list {basedir} {uid} {name} Deletes an existing list\n");
+ printf("add_to_list {basedir} {uid} {name} {acct} Adds an account (@user@host or actor url) to a list\n");
return 1;
}
@@ -345,6 +348,33 @@ int main(int argc, char *argv[])
return 0;
}
+ if (strcmp(cmd, "add_to_list") == 0) { /** **/
+ const char *account = GET_ARGV();
+
+ if (account != NULL) {
+ xs *lid = list_maint(&snac, url, 4);
+
+ if (lid != NULL) {
+ xs *actor = NULL;
+ xs *uid = NULL;
+
+ if (valid_status(webfinger_request(account, &actor, &uid))) {
+ xs *md5 = xs_md5_hex(actor, strlen(actor));
+
+ list_content(&snac, lid, md5, 1);
+ printf("Actor %s (%s) added to list %s (%s)\n", actor, uid, url, lid);
+ }
+ else
+ fprintf(stderr, "Cannot resolve account '%s'\n", account);
+ }
+ else
+ fprintf(stderr, "Cannot find a list named '%s'\n", url);
+
+ }
+
+ return 0;
+ }
+
if (strcmp(cmd, "alias") == 0) { /** **/
xs *actor = NULL;
xs *uid = NULL;