summaryrefslogtreecommitdiff
path: root/mastoapi.c
diff options
context:
space:
mode:
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,
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;