aboutsummaryrefslogtreecommitdiff
path: root/mastoapi.c
diff options
context:
space:
mode:
authordefault <nobody@localhost>2023-05-15 11:15:28 +0200
committerdefault <nobody@localhost>2023-05-15 11:15:28 +0200
commite9588a71ae67427d3ed0c50246f46724aa7611c3 (patch)
treeec503280ce297ee03ca7cd1fe3c0528284198a4d /mastoapi.c
parent59b049fe3b689eac6e028a9b5537bc593b9e3696 (diff)
Add /v1/account/search support.
Diffstat (limited to 'mastoapi.c')
-rw-r--r--mastoapi.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/mastoapi.c b/mastoapi.c
index 389088e..062fb7e 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -957,6 +957,38 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
xs *out = NULL;
xs *actor = NULL;
+ if (logged_in && strcmp(uid, "search") == 0) { /** **/
+ /* search for accounts starting with q */
+ const char *q = xs_dict_get(args, "q");
+
+ if (!xs_is_null(q)) {
+ out = xs_list_new();
+ xs *wing = following_list(&snac1);
+ xs *wers = follower_list(&snac1);
+ xs_list *p;
+
+ 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)) {
+ xs *actor = NULL;
+
+ if (valid_status(object_get(v, &actor))) {
+ const char *uname = xs_dict_get(actor, "preferredUsername");
+
+ if (!xs_is_null(uname) && xs_startswith(uname, q)) {
+ xs *acct = mastoapi_account(actor);
+
+ out = xs_list_append(out, acct);
+ }
+ }
+ }
+ }
+ }
+ }
+ else
/* is it a local user? */
if (user_open(&snac2, uid) || user_open_by_md5(&snac2, uid)) {
if (opt == NULL) {
@@ -965,7 +997,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
out = mastoapi_account(actor);
}
else
- if (strcmp(opt, "statuses") == 0) {
+ if (strcmp(opt, "statuses") == 0) { /** **/
/* the public list of posts of a user */
xs *timeline = timeline_simple_list(&snac2, "public", 0, 256);
xs_list *p = timeline;