mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-14 17:45:04 +00:00
Add /v1/account/search support.
This commit is contained in:
parent
59b049fe3b
commit
e9588a71ae
3 changed files with 38 additions and 5 deletions
7
data.c
7
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;
|
||||
|
|
34
mastoapi.c
34
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;
|
||||
|
|
2
snac.h
2
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);
|
||||
|
|
Loading…
Reference in a new issue