diff options
Diffstat (limited to 'utils.c')
| -rw-r--r-- | utils.c | 114 |
1 files changed, 113 insertions, 1 deletions
| @@ -673,5 +673,117 @@ void export_csv(snac *user) | |||
| 673 | void import_csv(snac *user) | 673 | void import_csv(snac *user) |
| 674 | /* import CSV files from Mastodon */ | 674 | /* import CSV files from Mastodon */ |
| 675 | { | 675 | { |
| 676 | (void)user; | 676 | FILE *f; |
| 677 | const char *fn; | ||
| 678 | |||
| 679 | fn = "blocked_accounts.csv"; | ||
| 680 | if ((f = fopen(fn, "r")) != NULL) { | ||
| 681 | snac_log(user, xs_fmt("Importing from %s...", fn)); | ||
| 682 | |||
| 683 | while (!feof(f)) { | ||
| 684 | xs *l = xs_strip_i(xs_readline(f)); | ||
| 685 | |||
| 686 | if (*l) { | ||
| 687 | xs *url = NULL; | ||
| 688 | xs *uid = NULL; | ||
| 689 | |||
| 690 | if (valid_status(webfinger_request(l, &url, &uid))) { | ||
| 691 | if (is_muted(user, url)) | ||
| 692 | snac_log(user, xs_fmt("Actor %s already MUTEd", url)); | ||
| 693 | else { | ||
| 694 | mute(user, url); | ||
| 695 | snac_log(user, xs_fmt("MUTEd actor %s", url)); | ||
| 696 | } | ||
| 697 | } | ||
| 698 | else | ||
| 699 | snac_log(user, xs_fmt("Webfinger error for account %s", l)); | ||
| 700 | } | ||
| 701 | } | ||
| 702 | |||
| 703 | fclose(f); | ||
| 704 | } | ||
| 705 | else | ||
| 706 | snac_log(user, xs_fmt("Cannot open file %s", fn)); | ||
| 707 | |||
| 708 | fn = "following_accounts.csv"; | ||
| 709 | if ((f = fopen(fn, "r")) != NULL) { | ||
| 710 | snac_log(user, xs_fmt("Importing from %s...", fn)); | ||
| 711 | |||
| 712 | while (!feof(f)) { | ||
| 713 | xs *l = xs_strip_i(xs_readline(f)); | ||
| 714 | |||
| 715 | if (*l) { | ||
| 716 | xs *l2 = xs_split(l, ","); | ||
| 717 | const char *acct = xs_list_get(l2, 0); | ||
| 718 | const char *show = xs_list_get(l2, 1); | ||
| 719 | |||
| 720 | if (acct) { | ||
| 721 | /* not a valid account? skip (probably the CSV header) */ | ||
| 722 | if (strchr(acct, '@') == NULL) | ||
| 723 | continue; | ||
| 724 | |||
| 725 | xs *msg = msg_follow(user, acct); | ||
| 726 | |||
| 727 | if (msg == NULL) { | ||
| 728 | snac_log(user, xs_fmt("Cannot follow %s -- server down?", acct)); | ||
| 729 | continue; | ||
| 730 | } | ||
| 731 | |||
| 732 | const char *actor = xs_dict_get(msg, "object"); | ||
| 733 | |||
| 734 | if (following_check(user, actor)) | ||
| 735 | snac_log(user, xs_fmt("Actor %s already followed", actor)); | ||
| 736 | else { | ||
| 737 | following_add(user, actor, msg); | ||
| 738 | |||
| 739 | enqueue_output_by_actor(user, msg, actor, 0); | ||
| 740 | |||
| 741 | snac_log(user, xs_fmt("Following %s", actor)); | ||
| 742 | } | ||
| 743 | |||
| 744 | if (show && strcmp(show, "false") == 0) { | ||
| 745 | limit(user, actor); | ||
| 746 | snac_log(user, xs_fmt("Limiting boosts from actor %s", actor)); | ||
| 747 | } | ||
| 748 | } | ||
| 749 | } | ||
| 750 | } | ||
| 751 | |||
| 752 | fclose(f); | ||
| 753 | } | ||
| 754 | else | ||
| 755 | snac_log(user, xs_fmt("Cannot open file %s", fn)); | ||
| 756 | |||
| 757 | fn = "lists.csv"; | ||
| 758 | if ((f = fopen(fn, "r")) != NULL) { | ||
| 759 | snac_log(user, xs_fmt("Importing from %s...", fn)); | ||
| 760 | |||
| 761 | while (!feof(f)) { | ||
| 762 | xs *l = xs_strip_i(xs_readline(f)); | ||
| 763 | |||
| 764 | if (*l) { | ||
| 765 | } | ||
| 766 | } | ||
| 767 | |||
| 768 | fclose(f); | ||
| 769 | } | ||
| 770 | else | ||
| 771 | snac_log(user, xs_fmt("Cannot open file %s", fn)); | ||
| 772 | |||
| 773 | fn = "bookmarks.csv"; | ||
| 774 | if ((f = fopen(fn, "r")) != NULL) { | ||
| 775 | snac_log(user, xs_fmt("Importing from %s...", fn)); | ||
| 776 | |||
| 777 | while (!feof(f)) { | ||
| 778 | xs *l = xs_strip_i(xs_readline(f)); | ||
| 779 | |||
| 780 | if (*l) { | ||
| 781 | } | ||
| 782 | } | ||
| 783 | |||
| 784 | fclose(f); | ||
| 785 | } | ||
| 786 | else | ||
| 787 | snac_log(user, xs_fmt("Cannot open file %s", fn)); | ||
| 788 | |||
| 677 | } | 789 | } |