diff --git a/data.c b/data.c index 7a7adb0..db0d3aa 100644 --- a/data.c +++ b/data.c @@ -224,7 +224,7 @@ int user_open(snac *snac, const char *uid) } -d_char *user_list(void) +xs_list *user_list(void) /* returns the list of user ids */ { xs *spec = xs_fmt("%s/user/" "*", srv_basedir); diff --git a/mastoapi.c b/mastoapi.c index 51578ad..047e4bd 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -974,15 +974,41 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, out = xs_list_new(); xs *wing = following_list(&snac1); xs *wers = follower_list(&snac1); + xs *ulst = user_list(); xs_list *p; + xs_str *v; xs_set seen; xs_set_init(&seen); + /* local users */ + p = ulst; + while (xs_list_iter(&p, &v)) { + snac user; + + if (strcmp(v, xs_dict_get(snac1.config, "uid")) == 0) + continue; + + if (user_open(&user, v)) { + xs *v2 = xs_tolower_i(xs_dup(v)); + + if (xs_startswith(v2, q)) { + xs *actor = msg_actor(&user); + xs *acct = mastoapi_account(actor); + + out = xs_list_append(out, acct); + } + + xs_set_add(&seen, user.actor); + + user_free(&user); + } + } + + /* user relations */ xs_list *lsts[] = { wing, wers, NULL }; int n; for (n = 0; (p = lsts[n]) != NULL; n++) { - xs_str *v; while (xs_list_iter(&p, &v)) { /* already seen? skip */ diff --git a/snac.h b/snac.h index 3939cc9..8629ab0 100644 --- a/snac.h +++ b/snac.h @@ -43,7 +43,7 @@ typedef struct _snac { int user_open(snac *snac, const char *uid); void user_free(snac *snac); -d_char *user_list(void); +xs_list *user_list(void); int user_open_by_md5(snac *snac, const char *md5); void snac_debug(snac *snac, int level, d_char *str);