diff options
| author | 2023-04-12 20:20:46 +0200 | |
|---|---|---|
| committer | 2023-04-12 20:20:46 +0200 | |
| commit | e146c2afa8f29ce18313f6792f845f3613576699 (patch) | |
| tree | 3da381f1b5ec246e7fa8cdd089125e11f3e1f843 /mastoapi.c | |
| parent | Updated RELEASE_NOTES. (diff) | |
| download | snac2-e146c2afa8f29ce18313f6792f845f3613576699.tar.gz snac2-e146c2afa8f29ce18313f6792f845f3613576699.tar.xz snac2-e146c2afa8f29ce18313f6792f845f3613576699.zip | |
Also return (some) information for non-local users.
Diffstat (limited to 'mastoapi.c')
| -rw-r--r-- | mastoapi.c | 76 |
1 files changed, 47 insertions, 29 deletions
| @@ -412,7 +412,7 @@ xs_str *mastoapi_id(const xs_dict *msg) | |||
| 412 | #define MID_TO_MD5(id) (id + 10) | 412 | #define MID_TO_MD5(id) (id + 10) |
| 413 | 413 | ||
| 414 | 414 | ||
| 415 | xs_dict *mastoapi_account(snac *snac, const xs_dict *actor) | 415 | xs_dict *mastoapi_account(const xs_dict *actor) |
| 416 | /* converts an ActivityPub actor to a Mastodon account */ | 416 | /* converts an ActivityPub actor to a Mastodon account */ |
| 417 | { | 417 | { |
| 418 | xs_dict *acct = xs_dict_new(); | 418 | xs_dict *acct = xs_dict_new(); |
| @@ -459,7 +459,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) | |||
| 459 | if (actor == NULL) | 459 | if (actor == NULL) |
| 460 | return NULL; | 460 | return NULL; |
| 461 | 461 | ||
| 462 | xs *acct = mastoapi_account(snac, actor); | 462 | xs *acct = mastoapi_account(actor); |
| 463 | 463 | ||
| 464 | /** shave the yak converting an ActivityPub Note to a Mastodon status **/ | 464 | /** shave the yak converting an ActivityPub Note to a Mastodon status **/ |
| 465 | 465 | ||
| @@ -682,38 +682,58 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 682 | xs *l = xs_split(cmd, "/"); | 682 | xs *l = xs_split(cmd, "/"); |
| 683 | const char *uid = xs_list_get(l, 2); | 683 | const char *uid = xs_list_get(l, 2); |
| 684 | const char *opt = xs_list_get(l, 3); | 684 | const char *opt = xs_list_get(l, 3); |
| 685 | snac snac2; | ||
| 686 | 685 | ||
| 687 | if (uid != NULL && user_open(&snac2, uid)) { | 686 | if (uid != NULL) { |
| 688 | xs *out = NULL; | 687 | snac snac2; |
| 689 | 688 | xs *out = NULL; | |
| 690 | if (opt == NULL) { | 689 | xs *actor = NULL; |
| 691 | /* account information */ | 690 | |
| 692 | xs *actor = msg_actor(&snac2); | 691 | /* is it a local user? */ |
| 693 | out = mastoapi_account(&snac2, actor); | 692 | if (user_open(&snac2, uid)) { |
| 694 | } | 693 | if (opt == NULL) { |
| 695 | else | 694 | /* account information */ |
| 696 | if (strcmp(opt, "statuses") == 0) { | 695 | actor = msg_actor(&snac2); |
| 697 | /* the public list of posts of a user */ | 696 | out = mastoapi_account(actor); |
| 698 | xs *timeline = timeline_simple_list(&snac2, "public", 0, 256); | 697 | } |
| 699 | xs_list *p = timeline; | 698 | else |
| 700 | xs_str *v; | 699 | if (strcmp(opt, "statuses") == 0) { |
| 700 | /* the public list of posts of a user */ | ||
| 701 | xs *timeline = timeline_simple_list(&snac2, "public", 0, 256); | ||
| 702 | xs_list *p = timeline; | ||
| 703 | xs_str *v; | ||
| 701 | 704 | ||
| 702 | out = xs_list_new(); | 705 | out = xs_list_new(); |
| 703 | 706 | ||
| 704 | while (xs_list_iter(&p, &v)) { | 707 | while (xs_list_iter(&p, &v)) { |
| 705 | xs *msg = NULL; | 708 | xs *msg = NULL; |
| 706 | 709 | ||
| 707 | if (valid_status(timeline_get_by_md5(&snac2, v, &msg))) { | 710 | if (valid_status(timeline_get_by_md5(&snac2, v, &msg))) { |
| 708 | /* add only posts by the author */ | 711 | /* add only posts by the author */ |
| 709 | if (strcmp(xs_dict_get(msg, "type"), "Note") == 0 && | 712 | if (strcmp(xs_dict_get(msg, "type"), "Note") == 0 && |
| 710 | xs_startswith(xs_dict_get(msg, "id"), snac2.actor)) { | 713 | xs_startswith(xs_dict_get(msg, "id"), snac2.actor)) { |
| 711 | xs *st = mastoapi_status(&snac2, msg); | 714 | xs *st = mastoapi_status(&snac2, msg); |
| 712 | 715 | ||
| 713 | out = xs_list_append(out, st); | 716 | out = xs_list_append(out, st); |
| 717 | } | ||
| 714 | } | 718 | } |
| 715 | } | 719 | } |
| 716 | } | 720 | } |
| 721 | |||
| 722 | user_free(&snac2); | ||
| 723 | } | ||
| 724 | else { | ||
| 725 | /* try the uid as the md5 of a possibly loaded actor */ | ||
| 726 | if (logged_in && valid_status(object_get_by_md5(uid, &actor))) { | ||
| 727 | if (opt == NULL) { | ||
| 728 | /* account information */ | ||
| 729 | out = mastoapi_account(actor); | ||
| 730 | } | ||
| 731 | else | ||
| 732 | if (strcmp(opt, "statuses") == 0) { | ||
| 733 | /* we don't serve statuses of others; return the empty list */ | ||
| 734 | out = xs_list_new(); | ||
| 735 | } | ||
| 736 | } | ||
| 717 | } | 737 | } |
| 718 | 738 | ||
| 719 | if (out != NULL) { | 739 | if (out != NULL) { |
| @@ -721,8 +741,6 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 721 | *ctype = "application/json"; | 741 | *ctype = "application/json"; |
| 722 | status = 200; | 742 | status = 200; |
| 723 | } | 743 | } |
| 724 | |||
| 725 | user_free(&snac2); | ||
| 726 | } | 744 | } |
| 727 | } | 745 | } |
| 728 | else | 746 | else |
| @@ -993,7 +1011,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 993 | xs *actor2 = NULL; | 1011 | xs *actor2 = NULL; |
| 994 | 1012 | ||
| 995 | if (valid_status(object_get_by_md5(v, &actor2))) { | 1013 | if (valid_status(object_get_by_md5(v, &actor2))) { |
| 996 | xs *acct2 = mastoapi_account(&snac1, actor2); | 1014 | xs *acct2 = mastoapi_account(actor2); |
| 997 | 1015 | ||
| 998 | out = xs_list_append(out, acct2); | 1016 | out = xs_list_append(out, acct2); |
| 999 | } | 1017 | } |