diff options
| author | 2023-04-23 09:41:43 +0200 | |
|---|---|---|
| committer | 2023-04-23 09:41:43 +0200 | |
| commit | 8d4d702da98f777235cf921fc461c2f71271fd52 (patch) | |
| tree | 47fd9e350cdec9cd4814e18875d88dd897b313fb /mastoapi.c | |
| parent | Don't return that much entries in the mastoapi timeline. (diff) | |
| download | snac2-8d4d702da98f777235cf921fc461c2f71271fd52.tar.gz snac2-8d4d702da98f777235cf921fc461c2f71271fd52.tar.xz snac2-8d4d702da98f777235cf921fc461c2f71271fd52.zip | |
Added an instance timeline.
Diffstat (limited to 'mastoapi.c')
| -rw-r--r-- | mastoapi.c | 57 |
1 files changed, 55 insertions, 2 deletions
| @@ -912,8 +912,61 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 912 | else | 912 | else |
| 913 | if (strcmp(cmd, "/v1/timelines/public") == 0) { | 913 | if (strcmp(cmd, "/v1/timelines/public") == 0) { |
| 914 | /* the public timeline (public timelines for all users) */ | 914 | /* the public timeline (public timelines for all users) */ |
| 915 | /* TBD */ | 915 | |
| 916 | *body = xs_dup("[]"); | 916 | /* this is a kludge: first users in the list get all the fame */ |
| 917 | |||
| 918 | const char *limit_s = xs_dict_get(args, "limit"); | ||
| 919 | int limit = 0; | ||
| 920 | int cnt = 0; | ||
| 921 | |||
| 922 | if (!xs_is_null(limit_s)) | ||
| 923 | limit = atoi(limit_s); | ||
| 924 | |||
| 925 | if (limit == 0) | ||
| 926 | limit = 20; | ||
| 927 | |||
| 928 | xs *out = xs_list_new(); | ||
| 929 | xs *users = user_list(); | ||
| 930 | xs_list *p = users; | ||
| 931 | xs_str *uid; | ||
| 932 | |||
| 933 | while (xs_list_iter(&p, &uid) && cnt < limit) { | ||
| 934 | snac user; | ||
| 935 | |||
| 936 | if (user_open(&user, uid)) { | ||
| 937 | xs *timeline = timeline_simple_list(&snac1, "public", 0, 4); | ||
| 938 | xs_list *p2 = timeline; | ||
| 939 | xs_str *v; | ||
| 940 | |||
| 941 | while (xs_list_iter(&p2, &v) && cnt < limit) { | ||
| 942 | xs *msg = NULL; | ||
| 943 | |||
| 944 | /* get the entry */ | ||
| 945 | if (!valid_status(timeline_get_by_md5(&user, v, &msg))) | ||
| 946 | continue; | ||
| 947 | |||
| 948 | /* discard non-Notes */ | ||
| 949 | if (strcmp(xs_dict_get(msg, "type"), "Note") != 0) | ||
| 950 | continue; | ||
| 951 | |||
| 952 | /* discard entries not by this user */ | ||
| 953 | if (!xs_startswith(xs_dict_get(msg, "id"), user.actor)) | ||
| 954 | continue; | ||
| 955 | |||
| 956 | /* convert the Note into a Mastodon status */ | ||
| 957 | xs *st = mastoapi_status(&snac1, msg); | ||
| 958 | |||
| 959 | if (st != NULL) { | ||
| 960 | out = xs_list_append(out, st); | ||
| 961 | cnt++; | ||
| 962 | } | ||
| 963 | } | ||
| 964 | |||
| 965 | user_free(&user); | ||
| 966 | } | ||
| 967 | } | ||
| 968 | |||
| 969 | *body = xs_json_dumps_pp(out, 4); | ||
| 917 | *ctype = "application/json"; | 970 | *ctype = "application/json"; |
| 918 | status = 200; | 971 | status = 200; |
| 919 | } | 972 | } |