commit 1ebf2a2

default  ·  2025-04-18 07:08:48 +0000 UTC
parent 99230ba
New command-line option 'add_to_list'.
2 files changed,  +32, -2
M data.c
M main.c
M data.c
+2, -2
 1@@ -2404,7 +2404,7 @@ xs_val *list_content(snac *user, const char *list, const char *actor_md5, int op
 2         break;
 3 
 4     case 1: /** append actor to list **/
 5-        if (actor_md5 != NULL) {
 6+        if (xs_is_string(actor_md5) && xs_is_hex(actor_md5)) {
 7             if (!index_in_md5(fn, actor_md5))
 8                 index_add_md5(fn, actor_md5);
 9         }
10@@ -2412,7 +2412,7 @@ xs_val *list_content(snac *user, const char *list, const char *actor_md5, int op
11         break;
12 
13     case 2: /** delete actor from list **/
14-        if (actor_md5 != NULL)
15+        if (xs_is_string(actor_md5) && xs_is_hex(actor_md5))
16             index_del_md5(fn, actor_md5);
17 
18         break;
M main.c
+30, -0
 1@@ -61,6 +61,9 @@ int usage(void)
 2     printf("import_block_list {basedir} {uid} {file} Imports a Mastodon CSV block list file\n");
 3     printf("lists {basedir} {uid}                Returns the names of the lists created by the user\n");
 4     printf("list_members {basedir} {uid} {name}  Returns the list of accounts inside a list\n");
 5+    printf("create_list {basedir} {uid} {name}   Creates a new list\n");
 6+    printf("delete_list {basedir} {uid} {name}   Deletes an existing list\n");
 7+    printf("add_to_list {basedir} {uid} {name} {acct} Adds an account (@user@host or actor url) to a list\n");
 8 
 9     return 1;
10 }
11@@ -345,6 +348,33 @@ int main(int argc, char *argv[])
12         return 0;
13     }
14 
15+    if (strcmp(cmd, "add_to_list") == 0) { /** **/
16+        const char *account = GET_ARGV();
17+
18+        if (account != NULL) {
19+            xs *lid = list_maint(&snac, url, 4);
20+
21+            if (lid != NULL) {
22+                xs *actor = NULL;
23+                xs *uid = NULL;
24+
25+                if (valid_status(webfinger_request(account, &actor, &uid))) {
26+                    xs *md5 = xs_md5_hex(actor, strlen(actor));
27+
28+                    list_content(&snac, lid, md5, 1);
29+                    printf("Actor %s (%s) added to list %s (%s)\n", actor, uid, url, lid);
30+                }
31+                else
32+                    fprintf(stderr, "Cannot resolve account '%s'\n", account);
33+            }
34+            else
35+                fprintf(stderr, "Cannot find a list named '%s'\n", url);
36+
37+        }
38+
39+        return 0;
40+    }
41+
42     if (strcmp(cmd, "alias") == 0) { /** **/
43         xs *actor = NULL;
44         xs *uid = NULL;