summaryrefslogtreecommitdiff
path: root/mastoapi.c
diff options
context:
space:
mode:
Diffstat (limited to 'mastoapi.c')
-rw-r--r--mastoapi.c52
1 files changed, 23 insertions, 29 deletions
diff --git a/mastoapi.c b/mastoapi.c
index 001c0bc..92acd41 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -1038,9 +1038,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
1038 if (strcmp(cmd, "/v1/timelines/public") == 0) { 1038 if (strcmp(cmd, "/v1/timelines/public") == 0) {
1039 /* the public timeline (public timelines for all users) */ 1039 /* the public timeline (public timelines for all users) */
1040 1040
1041 /* this is an ugly kludge: first users in the list get all the fame */ 1041 const char *limit_s = xs_dict_get(args, "limit");
1042
1043 const char *limit_s = xs_dict_get(args, "limit");
1044 int limit = 0; 1042 int limit = 0;
1045 int cnt = 0; 1043 int cnt = 0;
1046 1044
@@ -1050,44 +1048,40 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
1050 if (limit == 0) 1048 if (limit == 0)
1051 limit = 20; 1049 limit = 20;
1052 1050
1053 xs *out = xs_list_new(); 1051 xs *timeline = timeline_instance_list(0, limit);
1054 xs *users = user_list(); 1052 xs *out = xs_list_new();
1055 xs_list *p = users; 1053 xs_list *p = timeline;
1056 xs_str *uid; 1054 xs_str *md5;
1057
1058 while (xs_list_iter(&p, &uid) && cnt < limit) {
1059 snac user;
1060 1055
1061 if (user_open(&user, uid)) { 1056 while (xs_list_iter(&p, &md5) && cnt < limit) {
1062 xs *timeline = timeline_simple_list(&user, "public", 0, 4); 1057 xs *msg = NULL;
1063 xs_list *p2 = timeline;
1064 xs_str *v;
1065 1058
1066 while (xs_list_iter(&p2, &v) && cnt < limit) { 1059 /* get the entry */
1067 xs *msg = NULL; 1060 if (!valid_status(object_get_by_md5(md5, &msg)))
1061 continue;
1068 1062
1069 /* get the entry */ 1063 /* discard non-Notes */
1070 if (!valid_status(timeline_get_by_md5(&user, v, &msg))) 1064 if (strcmp(xs_dict_get(msg, "type"), "Note") != 0)
1071 continue; 1065 continue;
1072 1066
1073 /* discard non-Notes */ 1067 /* get the uid */
1074 if (strcmp(xs_dict_get(msg, "type"), "Note") != 0) 1068 xs *l = xs_split(xs_dict_get(msg, "attributedTo"), "/");
1075 continue; 1069 const char *uid = xs_list_get(l, -1);
1076 1070
1077 /* discard entries not by this user */ 1071 if (!xs_is_null(uid)) {
1078 if (!xs_startswith(xs_dict_get(msg, "id"), user.actor)) 1072 snac user;
1079 continue;
1080 1073
1074 if (user_open(&user, uid)) {
1081 /* convert the Note into a Mastodon status */ 1075 /* convert the Note into a Mastodon status */
1082 xs *st = mastoapi_status(&user, msg); 1076 xs *st = mastoapi_status(&user, msg);
1083 1077
1084 if (st != NULL) { 1078 if (st != NULL)
1085 out = xs_list_append(out, st); 1079 out = xs_list_append(out, st);
1086 cnt++; 1080
1087 } 1081 user_free(&user);
1088 } 1082 }
1089 1083
1090 user_free(&user); 1084 cnt++;
1091 } 1085 }
1092 } 1086 }
1093 1087