commit 0d4406e
default
·
2023-04-12 16:54:20 +0000 UTC
parent 668f69d
Added the mastodon account data.
1 files changed,
+21,
-11
+21,
-11
1@@ -677,20 +677,30 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
2 }
3 }
4 else
5- if (xs_startswith(cmd, "/accounts/") && xs_endswith(cmd, "/statuses")) {
6- /* the public list of posts of a user */
7+ if (xs_startswith(cmd, "/accounts/")) {
8+ /* account-related information */
9 xs *l = xs_split(cmd, "/");
10+ const char *uid = xs_list_get(l, 2);
11+ const char *opt = xs_list_get(l, 3);
12+ snac snac2;
13
14- if (xs_list_len(l) == 4) {
15- snac snac2;
16- const char *uid = xs_list_get(l, 2);
17+ if (uid != NULL && user_open(&snac2, uid)) {
18+ xs *out = NULL;
19
20- if (user_open(&snac2, uid)) {
21+ if (opt == NULL) {
22+ /* account information */
23+ xs *actor = msg_actor(&snac2);
24+ out = mastoapi_account(&snac2, actor);
25+ }
26+ else
27+ if (strcmp(opt, "statuses") == 0) {
28+ /* the public list of posts of a user */
29 xs *timeline = timeline_simple_list(&snac2, "public", 0, 256);
30- xs *out = xs_list_new();
31 xs_list *p = timeline;
32 xs_str *v;
33
34+ out = xs_list_new();
35+
36 while (xs_list_iter(&p, &v)) {
37 xs *msg = NULL;
38
39@@ -704,15 +714,15 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
40 }
41 }
42 }
43+ }
44
45+ if (out != NULL) {
46 *body = xs_json_dumps_pp(out, 4);
47 *ctype = "application/json";
48 status = 200;
49-
50- user_free(&snac2);
51 }
52- else
53- srv_debug(0, xs_fmt("mastoapi account statuses: bad user '%s'", uid));
54+
55+ user_free(&snac2);
56 }
57 }
58 else