summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data.c7
-rw-r--r--mastoapi.c34
-rw-r--r--snac.h2
3 files changed, 38 insertions, 5 deletions
diff --git a/data.c b/data.c
index 92574c2..7a7adb0 100644
--- a/data.c
+++ b/data.c
@@ -1222,13 +1222,14 @@ int following_get(snac *snac, const char *actor, d_char **data)
}
-d_char *following_list(snac *snac)
+xs_list *following_list(snac *snac)
/* returns the list of people being followed */
{
xs *spec = xs_fmt("%s/following/" "*.json", snac->basedir);
xs *glist = xs_glob(spec, 0, 0);
- char *p, *v;
- d_char *list = xs_list_new();
+ xs_list *p;
+ xs_str *v;
+ xs_list *list = xs_list_new();
/* iterate the list of files */
p = glist;
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;
diff --git a/snac.h b/snac.h
index 95bbfd7..d0e8d49 100644
--- a/snac.h
+++ b/snac.h
@@ -119,7 +119,7 @@ int following_add(snac *snac, const char *actor, const xs_dict *msg);
int following_del(snac *snac, const char *actor);
int following_check(snac *snac, const char *actor);
int following_get(snac *snac, const char *actor, d_char **data);
-d_char *following_list(snac *snac);
+xs_list *following_list(snac *snac);
void mute(snac *snac, const char *actor);
void unmute(snac *snac, const char *actor);