From 06e86437ae5c3441dedc6ddba17e9d924959dbb9 Mon Sep 17 00:00:00 2001 From: "me@ow.nekobit.net" Date: Wed, 4 May 2022 03:04:00 +0000 Subject: [PATCH] Load search results FossilOrigin-Name: 82c46ced3ab0e254ba74c20aeddc5f9df26117f3b2e254f887d13ef77557d310 --- src/search.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/search.c b/src/search.c index d063eb4..1057476 100644 --- a/src/search.c +++ b/src/search.c @@ -22,6 +22,8 @@ #include "../config.h" #include "string_helpers.h" #include "base_page.h" +#include "status.h" +#include "error.h" // Pages #include "../static/search.chtml" @@ -59,7 +61,38 @@ void search_page(struct session* ssn, mastodont_t* api, enum search_tab tab, cha void content_search_statuses(struct session* ssn, mastodont_t* api, char** data) { - search_page(ssn, api, SEARCH_STATUSES, "statuses"); + char* statuses_html; + struct mstdnt_storage storage = { 0 }; + struct mstdnt_search_args args = { + .account_id = NULL, + .type = MSTDNT_SEARCH_STATUSES, + .resolve = 0, + .following = 0, + .with_relationships = 0, + .max_id = NULL, + .min_id = NULL, + .since_id = NULL, + .offset = 0, + .limit = 20, + }; + struct mstdnt_search_results results = { 0 }; + + if (mastodont_search(api, + ssn->query.query, + &storage, + &args, + &results) == 0) + { + statuses_html = construct_statuses(api, results.statuses, results.statuses_len, NULL); + if (!statuses_html) + statuses_html = construct_error("No statuses", E_ERROR, 1, NULL); + } + else + statuses_html = construct_error("An error occured.", E_ERROR, 1, NULL); + + search_page(ssn, api, SEARCH_STATUSES, STR_NULL_EMPTY(statuses_html)); + + if (statuses_html) free(statuses_html); } void content_search_accounts(struct session* ssn, mastodont_t* api, char** data)