Also find local users in /api/v1/search.

This commit is contained in:
default 2023-05-15 13:04:30 +02:00
parent 32b53e8db5
commit e6eb1adc65
3 changed files with 29 additions and 3 deletions

2
data.c
View File

@ -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 */ /* returns the list of user ids */
{ {
xs *spec = xs_fmt("%s/user/" "*", srv_basedir); xs *spec = xs_fmt("%s/user/" "*", srv_basedir);

View File

@ -974,15 +974,41 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
out = xs_list_new(); out = xs_list_new();
xs *wing = following_list(&snac1); xs *wing = following_list(&snac1);
xs *wers = follower_list(&snac1); xs *wers = follower_list(&snac1);
xs *ulst = user_list();
xs_list *p; xs_list *p;
xs_str *v;
xs_set seen; xs_set seen;
xs_set_init(&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 }; xs_list *lsts[] = { wing, wers, NULL };
int n; int n;
for (n = 0; (p = lsts[n]) != NULL; n++) { for (n = 0; (p = lsts[n]) != NULL; n++) {
xs_str *v;
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
/* already seen? skip */ /* already seen? skip */

2
snac.h
View File

@ -43,7 +43,7 @@ typedef struct _snac {
int user_open(snac *snac, const char *uid); int user_open(snac *snac, const char *uid);
void user_free(snac *snac); 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); int user_open_by_md5(snac *snac, const char *md5);
void snac_debug(snac *snac, int level, d_char *str); void snac_debug(snac *snac, int level, d_char *str);