diff options
| author | 2023-05-15 11:15:28 +0200 | |
|---|---|---|
| committer | 2023-05-15 11:15:28 +0200 | |
| commit | e9588a71ae67427d3ed0c50246f46724aa7611c3 (patch) | |
| tree | ec503280ce297ee03ca7cd1fe3c0528284198a4d | |
| parent | Backport from xs. (diff) | |
| download | snac2-e9588a71ae67427d3ed0c50246f46724aa7611c3.tar.gz snac2-e9588a71ae67427d3ed0c50246f46724aa7611c3.tar.xz snac2-e9588a71ae67427d3ed0c50246f46724aa7611c3.zip | |
Add /v1/account/search support.
| -rw-r--r-- | data.c | 7 | ||||
| -rw-r--r-- | mastoapi.c | 34 | ||||
| -rw-r--r-- | snac.h | 2 |
3 files changed, 38 insertions, 5 deletions
| @@ -1222,13 +1222,14 @@ int following_get(snac *snac, const char *actor, d_char **data) | |||
| 1222 | } | 1222 | } |
| 1223 | 1223 | ||
| 1224 | 1224 | ||
| 1225 | d_char *following_list(snac *snac) | 1225 | xs_list *following_list(snac *snac) |
| 1226 | /* returns the list of people being followed */ | 1226 | /* returns the list of people being followed */ |
| 1227 | { | 1227 | { |
| 1228 | xs *spec = xs_fmt("%s/following/" "*.json", snac->basedir); | 1228 | xs *spec = xs_fmt("%s/following/" "*.json", snac->basedir); |
| 1229 | xs *glist = xs_glob(spec, 0, 0); | 1229 | xs *glist = xs_glob(spec, 0, 0); |
| 1230 | char *p, *v; | 1230 | xs_list *p; |
| 1231 | d_char *list = xs_list_new(); | 1231 | xs_str *v; |
| 1232 | xs_list *list = xs_list_new(); | ||
| 1232 | 1233 | ||
| 1233 | /* iterate the list of files */ | 1234 | /* iterate the list of files */ |
| 1234 | p = glist; | 1235 | p = glist; |
| @@ -957,6 +957,38 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 957 | xs *out = NULL; | 957 | xs *out = NULL; |
| 958 | xs *actor = NULL; | 958 | xs *actor = NULL; |
| 959 | 959 | ||
| 960 | if (logged_in && strcmp(uid, "search") == 0) { /** **/ | ||
| 961 | /* search for accounts starting with q */ | ||
| 962 | const char *q = xs_dict_get(args, "q"); | ||
| 963 | |||
| 964 | if (!xs_is_null(q)) { | ||
| 965 | out = xs_list_new(); | ||
| 966 | xs *wing = following_list(&snac1); | ||
| 967 | xs *wers = follower_list(&snac1); | ||
| 968 | xs_list *p; | ||
| 969 | |||
| 970 | xs_list *lsts[] = { wing, wers, NULL }; | ||
| 971 | int n; | ||
| 972 | for (n = 0; (p = lsts[n]) != NULL; n++) { | ||
| 973 | xs_str *v; | ||
| 974 | |||
| 975 | while (xs_list_iter(&p, &v)) { | ||
| 976 | xs *actor = NULL; | ||
| 977 | |||
| 978 | if (valid_status(object_get(v, &actor))) { | ||
| 979 | const char *uname = xs_dict_get(actor, "preferredUsername"); | ||
| 980 | |||
| 981 | if (!xs_is_null(uname) && xs_startswith(uname, q)) { | ||
| 982 | xs *acct = mastoapi_account(actor); | ||
| 983 | |||
| 984 | out = xs_list_append(out, acct); | ||
| 985 | } | ||
| 986 | } | ||
| 987 | } | ||
| 988 | } | ||
| 989 | } | ||
| 990 | } | ||
| 991 | else | ||
| 960 | /* is it a local user? */ | 992 | /* is it a local user? */ |
| 961 | if (user_open(&snac2, uid) || user_open_by_md5(&snac2, uid)) { | 993 | if (user_open(&snac2, uid) || user_open_by_md5(&snac2, uid)) { |
| 962 | if (opt == NULL) { | 994 | if (opt == NULL) { |
| @@ -965,7 +997,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 965 | out = mastoapi_account(actor); | 997 | out = mastoapi_account(actor); |
| 966 | } | 998 | } |
| 967 | else | 999 | else |
| 968 | if (strcmp(opt, "statuses") == 0) { | 1000 | if (strcmp(opt, "statuses") == 0) { /** **/ |
| 969 | /* the public list of posts of a user */ | 1001 | /* the public list of posts of a user */ |
| 970 | xs *timeline = timeline_simple_list(&snac2, "public", 0, 256); | 1002 | xs *timeline = timeline_simple_list(&snac2, "public", 0, 256); |
| 971 | xs_list *p = timeline; | 1003 | xs_list *p = timeline; |
| @@ -119,7 +119,7 @@ int following_add(snac *snac, const char *actor, const xs_dict *msg); | |||
| 119 | int following_del(snac *snac, const char *actor); | 119 | int following_del(snac *snac, const char *actor); |
| 120 | int following_check(snac *snac, const char *actor); | 120 | int following_check(snac *snac, const char *actor); |
| 121 | int following_get(snac *snac, const char *actor, d_char **data); | 121 | int following_get(snac *snac, const char *actor, d_char **data); |
| 122 | d_char *following_list(snac *snac); | 122 | xs_list *following_list(snac *snac); |
| 123 | 123 | ||
| 124 | void mute(snac *snac, const char *actor); | 124 | void mute(snac *snac, const char *actor); |
| 125 | void unmute(snac *snac, const char *actor); | 125 | void unmute(snac *snac, const char *actor); |