diff options
Diffstat (limited to 'mastoapi.c')
| -rw-r--r-- | mastoapi.c | 32 |
1 files changed, 21 insertions, 11 deletions
| @@ -677,20 +677,30 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 677 | } | 677 | } |
| 678 | } | 678 | } |
| 679 | else | 679 | else |
| 680 | if (xs_startswith(cmd, "/accounts/") && xs_endswith(cmd, "/statuses")) { | 680 | if (xs_startswith(cmd, "/accounts/")) { |
| 681 | /* the public list of posts of a user */ | 681 | /* account-related information */ |
| 682 | xs *l = xs_split(cmd, "/"); | 682 | xs *l = xs_split(cmd, "/"); |
| 683 | const char *uid = xs_list_get(l, 2); | ||
| 684 | const char *opt = xs_list_get(l, 3); | ||
| 685 | snac snac2; | ||
| 683 | 686 | ||
| 684 | if (xs_list_len(l) == 4) { | 687 | if (uid != NULL && user_open(&snac2, uid)) { |
| 685 | snac snac2; | 688 | xs *out = NULL; |
| 686 | const char *uid = xs_list_get(l, 2); | ||
| 687 | 689 | ||
| 688 | if (user_open(&snac2, uid)) { | 690 | if (opt == NULL) { |
| 691 | /* account information */ | ||
| 692 | xs *actor = msg_actor(&snac2); | ||
| 693 | out = mastoapi_account(&snac2, actor); | ||
| 694 | } | ||
| 695 | else | ||
| 696 | if (strcmp(opt, "statuses") == 0) { | ||
| 697 | /* the public list of posts of a user */ | ||
| 689 | xs *timeline = timeline_simple_list(&snac2, "public", 0, 256); | 698 | xs *timeline = timeline_simple_list(&snac2, "public", 0, 256); |
| 690 | xs *out = xs_list_new(); | ||
| 691 | xs_list *p = timeline; | 699 | xs_list *p = timeline; |
| 692 | xs_str *v; | 700 | xs_str *v; |
| 693 | 701 | ||
| 702 | out = xs_list_new(); | ||
| 703 | |||
| 694 | while (xs_list_iter(&p, &v)) { | 704 | while (xs_list_iter(&p, &v)) { |
| 695 | xs *msg = NULL; | 705 | xs *msg = NULL; |
| 696 | 706 | ||
| @@ -704,15 +714,15 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 704 | } | 714 | } |
| 705 | } | 715 | } |
| 706 | } | 716 | } |
| 717 | } | ||
| 707 | 718 | ||
| 719 | if (out != NULL) { | ||
| 708 | *body = xs_json_dumps_pp(out, 4); | 720 | *body = xs_json_dumps_pp(out, 4); |
| 709 | *ctype = "application/json"; | 721 | *ctype = "application/json"; |
| 710 | status = 200; | 722 | status = 200; |
| 711 | |||
| 712 | user_free(&snac2); | ||
| 713 | } | 723 | } |
| 714 | else | 724 | |
| 715 | srv_debug(0, xs_fmt("mastoapi account statuses: bad user '%s'", uid)); | 725 | user_free(&snac2); |
| 716 | } | 726 | } |
| 717 | } | 727 | } |
| 718 | else | 728 | else |