From 5e0d1949a5244cf242a2cd405affa4ae778c3500 Mon Sep 17 00:00:00 2001 From: "me@ow.nekobit.net" Date: Thu, 5 May 2022 03:51:32 +0000 Subject: [PATCH] Search accounts progress FossilOrigin-Name: ce0ecdec72d0d86affd0367a0283d6176602f720822c37e90dfda1ef7cf3b9b8 --- src/account.h | 14 ++++++++++++++ src/search.c | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/account.h b/src/account.h index 776a89e..150ec6d 100644 --- a/src/account.h +++ b/src/account.h @@ -23,6 +23,10 @@ #include "session.h" #include "l10n.h" +#define ACCOUNT_NOP 0 +#define ACCOUNT_ACTION_BTNS (1<<0) +#define ACCOUNT_SUMMARY (1<<1) + enum account_tab { ACCT_TAB_STATUSES, @@ -49,6 +53,16 @@ struct account_page struct mstdnt_relationship* relationship; }; +char* construct_account(mastodont_t* api, + struct mstdnt_account* account, + int* size, + uint8_t flags); +char* construct_accounts(mastodont_t* api, + struct mstdnt_account* accounts, + size_t size, + uint8_t flags, + size_t* ret_size); + size_t construct_account_page(char** result, struct account_page* page, char* content); char* load_account_page(mastodont_t* api, diff --git a/src/search.c b/src/search.c index abfd1f8..55c20fc 100644 --- a/src/search.c +++ b/src/search.c @@ -100,7 +100,38 @@ void content_search_statuses(struct session* ssn, mastodont_t* api, char** data) void content_search_accounts(struct session* ssn, mastodont_t* api, char** data) { - search_page(ssn, api, SEARCH_ACCOUNTS, "accounts"); + char* accounts_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) + { + accounts_html = construct_accounts(api, results.accts, results.accts_len, 0, NULL); + if (!accounts_html) + accounts_html = construct_error("No accounts", E_ERROR, 1, NULL); + } + else + accounts_html = construct_error("An error occured.", E_ERROR, 1, NULL); + + search_page(ssn, api, SEARCH_ACCOUNTS, STR_NULL_EMPTY(accounts_html)); + + if (accounts_html) free(accounts_html); } void content_search_hashtags(struct session* ssn, mastodont_t* api, char** data)