commit 3f8db42
default
·
2024-11-24 19:21:48 +0000 UTC
parent a5a7ab9
The search box also searches accounts (via webfinger).
1 files changed,
+42,
-0
M
html.c
M
html.c
+42,
-0
1@@ -2972,6 +2972,48 @@ int html_get_handler(const xs_dict *req, const char *q_path,
2 const char *q = xs_dict_get(q_vars, "q");
3
4 if (q && *q) {
5+ if (xs_regex_match(q, "^@?[a-zA-Z0-9_]+@[a-zA-Z0-9-]+\\.")) {
6+ /** search account **/
7+ xs *actor = NULL;
8+ xs *acct = NULL;
9+ xs *l = xs_list_new();
10+ xs_html *page = NULL;
11+
12+ if (valid_status(webfinger_request(q, &actor, &acct))) {
13+ xs *actor_obj = NULL;
14+
15+ if (valid_status(actor_request(&snac, actor, &actor_obj))) {
16+ actor_add(actor, actor_obj);
17+
18+ /* create a people list with only one element */
19+ l = xs_list_append(xs_list_new(), actor);
20+
21+ xs *title = xs_fmt(L("Search results for account %s"), q);
22+
23+ page = html_people_list(&snac, l, title, "wf", NULL);
24+ }
25+ }
26+
27+ if (page == NULL) {
28+ xs *title = xs_fmt(L("Account %s not found"), q);
29+
30+ page = xs_html_tag("div",
31+ xs_html_tag("h2",
32+ xs_html_attr("class", "snac-header"),
33+ xs_html_text(title)));
34+ }
35+
36+ xs_html *html = xs_html_tag("html",
37+ html_user_head(&snac, NULL, NULL),
38+ xs_html_add(html_user_body(&snac, 0),
39+ page,
40+ html_footer()));
41+
42+ *body = xs_html_render_s(html, "<!DOCTYPE html>\n");
43+ *b_size = strlen(*body);
44+ status = HTTP_STATUS_OK;
45+ }
46+ else
47 if (*q == '#') {
48 /** search by tag **/
49 xs *tl = tag_search(q, skip, show + 1);