diff options
| author | 2023-05-17 08:03:46 +0200 | |
|---|---|---|
| committer | 2023-05-17 08:03:46 +0200 | |
| commit | 81cec4ab27045a4e0a85d0104df5096be6c54dc3 (patch) | |
| tree | 2840f565219bf9ce630046ea8a62c0ab176b58cf /mastoapi.c | |
| parent | In mastoapi account search, return local users at the end. (diff) | |
| download | snac2-81cec4ab27045a4e0a85d0104df5096be6c54dc3.tar.gz snac2-81cec4ab27045a4e0a85d0104df5096be6c54dc3.tar.xz snac2-81cec4ab27045a4e0a85d0104df5096be6c54dc3.zip | |
Don't autocomplete local users if they are already added.
Diffstat (limited to 'mastoapi.c')
| -rw-r--r-- | mastoapi.c | 13 |
1 files changed, 8 insertions, 5 deletions
| @@ -1014,21 +1014,24 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 1014 | while (xs_list_iter(&p, &v)) { | 1014 | while (xs_list_iter(&p, &v)) { |
| 1015 | snac user; | 1015 | snac user; |
| 1016 | 1016 | ||
| 1017 | /* skip this same user */ | ||
| 1017 | if (strcmp(v, xs_dict_get(snac1.config, "uid")) == 0) | 1018 | if (strcmp(v, xs_dict_get(snac1.config, "uid")) == 0) |
| 1018 | continue; | 1019 | continue; |
| 1019 | 1020 | ||
| 1020 | if (user_open(&user, v)) { | 1021 | /* skip if the uid does not start with the query */ |
| 1021 | xs *v2 = xs_tolower_i(xs_dup(v)); | 1022 | xs *v2 = xs_tolower_i(xs_dup(v)); |
| 1023 | if (!xs_startswith(v2, q)) | ||
| 1024 | continue; | ||
| 1022 | 1025 | ||
| 1023 | if (xs_startswith(v2, q)) { | 1026 | if (user_open(&user, v)) { |
| 1027 | /* if it's not already seen, add it */ | ||
| 1028 | if (xs_set_add(&seen, user.actor) == 1) { | ||
| 1024 | xs *actor = msg_actor(&user); | 1029 | xs *actor = msg_actor(&user); |
| 1025 | xs *acct = mastoapi_account(actor); | 1030 | xs *acct = mastoapi_account(actor); |
| 1026 | 1031 | ||
| 1027 | out = xs_list_append(out, acct); | 1032 | out = xs_list_append(out, acct); |
| 1028 | } | 1033 | } |
| 1029 | 1034 | ||
| 1030 | xs_set_add(&seen, user.actor); | ||
| 1031 | |||
| 1032 | user_free(&user); | 1035 | user_free(&user); |
| 1033 | } | 1036 | } |
| 1034 | } | 1037 | } |