diff options
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 112 |
1 files changed, 112 insertions, 0 deletions
| @@ -59,6 +59,12 @@ int usage(void) | |||
| 59 | printf("import_csv {basedir} {uid} Imports data from CSV files\n"); | 59 | printf("import_csv {basedir} {uid} Imports data from CSV files\n"); |
| 60 | printf("import_list {basedir} {uid} {file} Imports a Mastodon CSV list file\n"); | 60 | printf("import_list {basedir} {uid} {file} Imports a Mastodon CSV list file\n"); |
| 61 | printf("import_block_list {basedir} {uid} {file} Imports a Mastodon CSV block list file\n"); | 61 | printf("import_block_list {basedir} {uid} {file} Imports a Mastodon CSV block list file\n"); |
| 62 | printf("lists {basedir} {uid} Returns the names of the lists created by the user\n"); | ||
| 63 | printf("list_members {basedir} {uid} {name} Returns the list of accounts inside a list\n"); | ||
| 64 | printf("create_list {basedir} {uid} {name} Creates a new list\n"); | ||
| 65 | printf("delete_list {basedir} {uid} {name} Deletes an existing list\n"); | ||
| 66 | printf("list_add {basedir} {uid} {name} {acct} Adds an account (@user@host or actor url) to a list\n"); | ||
| 67 | printf("list_del {basedir} {uid} {name} {actor} Deletes an actor URL from a list\n"); | ||
| 62 | 68 | ||
| 63 | return 1; | 69 | return 1; |
| 64 | } | 70 | } |
| @@ -282,9 +288,114 @@ int main(int argc, char *argv[]) | |||
| 282 | return migrate_account(&snac); | 288 | return migrate_account(&snac); |
| 283 | } | 289 | } |
| 284 | 290 | ||
| 291 | if (strcmp(cmd, "lists") == 0) { /** **/ | ||
| 292 | xs *lol = list_maint(&snac, NULL, 0); | ||
| 293 | const xs_list *l; | ||
| 294 | |||
| 295 | xs_list_foreach(lol, l) { | ||
| 296 | printf("%s (%s)\n", xs_list_get(l, 1), xs_list_get(l, 0)); | ||
| 297 | } | ||
| 298 | |||
| 299 | return 0; | ||
| 300 | } | ||
| 301 | |||
| 285 | if ((url = GET_ARGV()) == NULL) | 302 | if ((url = GET_ARGV()) == NULL) |
| 286 | return usage(); | 303 | return usage(); |
| 287 | 304 | ||
| 305 | if (strcmp(cmd, "list_members") == 0) { /** **/ | ||
| 306 | xs *lid = list_maint(&snac, url, 4); | ||
| 307 | |||
| 308 | if (lid != NULL) { | ||
| 309 | xs *lcont = list_content(&snac, lid, NULL, 0); | ||
| 310 | const char *md5; | ||
| 311 | |||
| 312 | xs_list_foreach(lcont, md5) { | ||
| 313 | xs *actor = NULL; | ||
| 314 | |||
| 315 | if (valid_status(object_get_by_md5(md5, &actor))) { | ||
| 316 | printf("%s (%s)\n", xs_dict_get(actor, "id"), xs_dict_get_def(actor, "preferredUsername", "")); | ||
| 317 | } | ||
| 318 | } | ||
| 319 | } | ||
| 320 | else | ||
| 321 | fprintf(stderr, "Cannot find a list named '%s'\n", url); | ||
| 322 | |||
| 323 | return 0; | ||
| 324 | } | ||
| 325 | |||
| 326 | if (strcmp(cmd, "create_list") == 0) { /** **/ | ||
| 327 | xs *lid = list_maint(&snac, url, 4); | ||
| 328 | |||
| 329 | if (lid == NULL) { | ||
| 330 | xs *n_lid = list_maint(&snac, url, 1); | ||
| 331 | printf("New list named '%s' created (%s)\n", url, n_lid); | ||
| 332 | } | ||
| 333 | else | ||
| 334 | fprintf(stderr, "A list named '%s' already exist\n", url); | ||
| 335 | |||
| 336 | return 0; | ||
| 337 | } | ||
| 338 | |||
| 339 | if (strcmp(cmd, "delete_list") == 0) { /** **/ | ||
| 340 | xs *lid = list_maint(&snac, url, 4); | ||
| 341 | |||
| 342 | if (lid != NULL) { | ||
| 343 | list_maint(&snac, lid, 2); | ||
| 344 | printf("List '%s' (%s) deleted\n", url, lid); | ||
| 345 | } | ||
| 346 | else | ||
| 347 | fprintf(stderr, "Cannot find a list named '%s'\n", url); | ||
| 348 | |||
| 349 | return 0; | ||
| 350 | } | ||
| 351 | |||
| 352 | if (strcmp(cmd, "list_add") == 0) { /** **/ | ||
| 353 | const char *account = GET_ARGV(); | ||
| 354 | |||
| 355 | if (account != NULL) { | ||
| 356 | xs *lid = list_maint(&snac, url, 4); | ||
| 357 | |||
| 358 | if (lid != NULL) { | ||
| 359 | xs *actor = NULL; | ||
| 360 | xs *uid = NULL; | ||
| 361 | |||
| 362 | if (valid_status(webfinger_request(account, &actor, &uid))) { | ||
| 363 | xs *md5 = xs_md5_hex(actor, strlen(actor)); | ||
| 364 | |||
| 365 | list_content(&snac, lid, md5, 1); | ||
| 366 | printf("Actor %s (%s) added to list '%s' (%s)\n", actor, uid, url, lid); | ||
| 367 | } | ||
| 368 | else | ||
| 369 | fprintf(stderr, "Cannot resolve account '%s'\n", account); | ||
| 370 | } | ||
| 371 | else | ||
| 372 | fprintf(stderr, "Cannot find a list named '%s'\n", url); | ||
| 373 | |||
| 374 | } | ||
| 375 | |||
| 376 | return 0; | ||
| 377 | } | ||
| 378 | |||
| 379 | if (strcmp(cmd, "list_del") == 0) { /** **/ | ||
| 380 | const char *account = GET_ARGV(); | ||
| 381 | |||
| 382 | if (account != NULL) { | ||
| 383 | xs *lid = list_maint(&snac, url, 4); | ||
| 384 | |||
| 385 | if (lid != NULL) { | ||
| 386 | xs *md5 = xs_md5_hex(account, strlen(account)); | ||
| 387 | |||
| 388 | list_content(&snac, lid, md5, 2); | ||
| 389 | printf("Actor %s deleted from list '%s' (%s)\n", account, url, lid); | ||
| 390 | } | ||
| 391 | else | ||
| 392 | fprintf(stderr, "Cannot find a list named '%s'\n", url); | ||
| 393 | |||
| 394 | } | ||
| 395 | |||
| 396 | return 0; | ||
| 397 | } | ||
| 398 | |||
| 288 | if (strcmp(cmd, "alias") == 0) { /** **/ | 399 | if (strcmp(cmd, "alias") == 0) { /** **/ |
| 289 | xs *actor = NULL; | 400 | xs *actor = NULL; |
| 290 | xs *uid = NULL; | 401 | xs *uid = NULL; |
| @@ -719,6 +830,7 @@ int main(int argc, char *argv[]) | |||
| 719 | } | 830 | } |
| 720 | 831 | ||
| 721 | enqueue_message(&snac, c_msg); | 832 | enqueue_message(&snac, c_msg); |
| 833 | enqueue_webmention(msg); | ||
| 722 | 834 | ||
| 723 | timeline_add(&snac, xs_dict_get(msg, "id"), msg); | 835 | timeline_add(&snac, xs_dict_get(msg, "id"), msg); |
| 724 | 836 | ||