commit e6eb1ad
default
·
2023-05-15 11:04:30 +0000 UTC
parent 32b53e8
Also find local users in /api/v1/search.
3 files changed,
+29,
-3
M
data.c
+1,
-1
1@@ -224,7 +224,7 @@ int user_open(snac *snac, const char *uid)
2 }
3
4
5-d_char *user_list(void)
6+xs_list *user_list(void)
7 /* returns the list of user ids */
8 {
9 xs *spec = xs_fmt("%s/user/" "*", srv_basedir);
+27,
-1
1@@ -974,15 +974,41 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
2 out = xs_list_new();
3 xs *wing = following_list(&snac1);
4 xs *wers = follower_list(&snac1);
5+ xs *ulst = user_list();
6 xs_list *p;
7+ xs_str *v;
8 xs_set seen;
9
10 xs_set_init(&seen);
11
12+ /* local users */
13+ p = ulst;
14+ while (xs_list_iter(&p, &v)) {
15+ snac user;
16+
17+ if (strcmp(v, xs_dict_get(snac1.config, "uid")) == 0)
18+ continue;
19+
20+ if (user_open(&user, v)) {
21+ xs *v2 = xs_tolower_i(xs_dup(v));
22+
23+ if (xs_startswith(v2, q)) {
24+ xs *actor = msg_actor(&user);
25+ xs *acct = mastoapi_account(actor);
26+
27+ out = xs_list_append(out, acct);
28+ }
29+
30+ xs_set_add(&seen, user.actor);
31+
32+ user_free(&user);
33+ }
34+ }
35+
36+ /* user relations */
37 xs_list *lsts[] = { wing, wers, NULL };
38 int n;
39 for (n = 0; (p = lsts[n]) != NULL; n++) {
40- xs_str *v;
41
42 while (xs_list_iter(&p, &v)) {
43 /* already seen? skip */
M
snac.h
+1,
-1
1@@ -43,7 +43,7 @@ typedef struct _snac {
2
3 int user_open(snac *snac, const char *uid);
4 void user_free(snac *snac);
5-d_char *user_list(void);
6+xs_list *user_list(void);
7 int user_open_by_md5(snac *snac, const char *md5);
8
9 void snac_debug(snac *snac, int level, d_char *str);