From d11d03787fa5f45926859e780d9c8c0bf56bf5ee Mon Sep 17 00:00:00 2001 From: default Date: Fri, 18 Apr 2025 08:44:47 +0200 Subject: New command-line options 'lists' and 'list_members'. --- main.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'main.c') diff --git a/main.c b/main.c index 3cd4524..7632032 100644 --- a/main.c +++ b/main.c @@ -59,6 +59,8 @@ int usage(void) printf("import_csv {basedir} {uid} Imports data from CSV files\n"); printf("import_list {basedir} {uid} {file} Imports a Mastodon CSV list file\n"); 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"); return 1; } @@ -282,9 +284,41 @@ int main(int argc, char *argv[]) return migrate_account(&snac); } + if (strcmp(cmd, "lists") == 0) { /** **/ + xs *lol = list_maint(&snac, NULL, 0); + const xs_list *l; + + xs_list_foreach(lol, l) { + printf("%s (%s)\n", xs_list_get(l, 1), xs_list_get(l, 0)); + } + + return 0; + } + if ((url = GET_ARGV()) == NULL) return usage(); + if (strcmp(cmd, "list_members") == 0) { /** **/ + xs *lid = list_maint(&snac, url, 4); + + if (lid != NULL) { + xs *lcont = list_content(&snac, lid, NULL, 0); + const char *md5; + + xs_list_foreach(lcont, md5) { + xs *actor = NULL; + + if (valid_status(object_get_by_md5(md5, &actor))) { + printf("%s (%s)\n", xs_dict_get(actor, "id"), xs_dict_get_def(actor, "preferredUsername", "")); + } + } + } + else + fprintf(stderr, "Cannot find list named '%s'\n", url); + + return 0; + } + if (strcmp(cmd, "alias") == 0) { /** **/ xs *actor = NULL; xs *uid = NULL; -- cgit v1.2.3 From 99230ba053238d7ad80b7793c7a8a8752e7b7049 Mon Sep 17 00:00:00 2001 From: default Date: Fri, 18 Apr 2025 08:55:32 +0200 Subject: New command-line options 'create_list' and 'delete_list'. --- main.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'main.c') diff --git a/main.c b/main.c index 7632032..54da610 100644 --- a/main.c +++ b/main.c @@ -314,7 +314,33 @@ int main(int argc, char *argv[]) } } else - fprintf(stderr, "Cannot find list named '%s'\n", url); + fprintf(stderr, "Cannot find a list named '%s'\n", url); + + return 0; + } + + if (strcmp(cmd, "create_list") == 0) { /** **/ + xs *lid = list_maint(&snac, url, 4); + + if (lid == NULL) { + xs *n_lid = list_maint(&snac, url, 1); + printf("New list named '%s' created (%s)\n", url, n_lid); + } + else + fprintf(stderr, "A list named '%s' already exist\n", url); + + return 0; + } + + if (strcmp(cmd, "delete_list") == 0) { /** **/ + xs *lid = list_maint(&snac, url, 4); + + if (lid != NULL) { + list_maint(&snac, lid, 2); + printf("List '%s' (%s) deleted\n", url, lid); + } + else + fprintf(stderr, "Cannot find a list named '%s'\n", url); return 0; } -- cgit v1.2.3 From 1ebf2a2d874f3ee589785e8175abdcb33a963d72 Mon Sep 17 00:00:00 2001 From: default Date: Fri, 18 Apr 2025 09:08:48 +0200 Subject: New command-line option 'add_to_list'. --- main.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'main.c') diff --git a/main.c b/main.c index 54da610..8b8b209 100644 --- 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; -- cgit v1.2.3 From 9b863605f9b0e888986b01f07c634637b5186bb6 Mon Sep 17 00:00:00 2001 From: default Date: Fri, 18 Apr 2025 09:12:44 +0200 Subject: Renamed command-line option to 'list_add' and added new 'list_del'. --- main.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 8b8b209..de5921b 100644 --- a/main.c +++ b/main.c @@ -63,7 +63,8 @@ int usage(void) 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"); + printf("list_add {basedir} {uid} {name} {acct} Adds an account (@user@host or actor url) to a list\n"); + printf("list_del {basedir} {uid} {name} {acct} Deletes an account (@user@host or actor url) from a list\n"); return 1; } @@ -348,7 +349,7 @@ int main(int argc, char *argv[]) return 0; } - if (strcmp(cmd, "add_to_list") == 0) { /** **/ + if (strcmp(cmd, "list_add") == 0) { /** **/ const char *account = GET_ARGV(); if (account != NULL) { @@ -362,7 +363,34 @@ int main(int argc, char *argv[]) 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); + 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, "list_del") == 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, 2); + printf("Actor %s (%s) deleted from list '%s' (%s)\n", actor, uid, url, lid); } else fprintf(stderr, "Cannot resolve account '%s'\n", account); -- cgit v1.2.3 From 0263c87035712ff6bd7ef57354b6425803eefc1d Mon Sep 17 00:00:00 2001 From: default Date: Fri, 18 Apr 2025 09:20:15 +0200 Subject: Simplified 'list_del' to use the account the user said. --- main.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index de5921b..6cd1bc9 100644 --- a/main.c +++ b/main.c @@ -383,17 +383,10 @@ int main(int argc, char *argv[]) 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)); + xs *md5 = xs_md5_hex(account, strlen(account)); - list_content(&snac, lid, md5, 2); - printf("Actor %s (%s) deleted from list '%s' (%s)\n", actor, uid, url, lid); - } - else - fprintf(stderr, "Cannot resolve account '%s'\n", account); + list_content(&snac, lid, md5, 2); + printf("Actor %s deleted from list '%s' (%s)\n", account, url, lid); } else fprintf(stderr, "Cannot find a list named '%s'\n", url); -- cgit v1.2.3 From f8961e9590002263472c2e60132888e7ac23b3fa Mon Sep 17 00:00:00 2001 From: default Date: Fri, 18 Apr 2025 09:21:55 +0200 Subject: Minor tweak to usage help. --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'main.c') diff --git a/main.c b/main.c index 6cd1bc9..a6fb6fd 100644 --- a/main.c +++ b/main.c @@ -64,7 +64,7 @@ int usage(void) printf("create_list {basedir} {uid} {name} Creates a new list\n"); printf("delete_list {basedir} {uid} {name} Deletes an existing list\n"); printf("list_add {basedir} {uid} {name} {acct} Adds an account (@user@host or actor url) to a list\n"); - printf("list_del {basedir} {uid} {name} {acct} Deletes an account (@user@host or actor url) from a list\n"); + printf("list_del {basedir} {uid} {name} {actor} Deletes an actor URL from a list\n"); return 1; } -- cgit v1.2.3