From bf48f29ce24e6105863f1aa0fcbdd4b7f1dcb36f Mon Sep 17 00:00:00 2001 From: "me@ow.nekobit.net" Date: Fri, 6 May 2022 06:04:02 +0000 Subject: [PATCH] Show hashtags Search is now complete FossilOrigin-Name: f179685db72b1e1cb6be3a9c450a83e717c18c4601a9d00be52bcbda46698e0f --- Makefile | 6 ++++ src/hashtag.c | 57 ++++++++++++++++++++++++++++++++++ src/hashtag.h | 27 ++++++++++++++++ src/search.c | 35 ++++++++++++++++++++- static/hashtag.html | 1 + static/hashtag_page.html | 8 +++++ static/hashtag_statistics.html | 1 + 7 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 src/hashtag.c create mode 100644 src/hashtag.h create mode 100644 static/hashtag.html create mode 100644 static/hashtag_page.html create mode 100644 static/hashtag_statistics.html diff --git a/Makefile b/Makefile index b9501a4..fec4ebd 100644 --- a/Makefile +++ b/Makefile @@ -102,6 +102,12 @@ $(PAGES_DIR)/favourites_page.chtml: $(PAGES_DIR)/favourites_page.html ./filec $< data_favourites_page_html > $@ $(PAGES_DIR)/account_stub.chtml: $(PAGES_DIR)/account_stub.html ./filec $< data_account_stub_html > $@ +$(PAGES_DIR)/hashtag.chtml: $(PAGES_DIR)/hashtag.html + ./filec $< data_hashtag_html > $@ +$(PAGES_DIR)/hashtag_page.chtml: $(PAGES_DIR)/hashtag_page.html + ./filec $< data_hashtag_page_html > $@ +$(PAGES_DIR)/hashtag_statistics.chtml: $(PAGES_DIR)/hashtag_statistics.html + ./filec $< data_hashtag_statistics_html > $@ $(MASTODONT_DIR): git clone $(MASTODONT_URL) || true diff --git a/src/hashtag.c b/src/hashtag.c new file mode 100644 index 0000000..f60490d --- /dev/null +++ b/src/hashtag.c @@ -0,0 +1,57 @@ +/* + * Treebird - Lightweight frontend for Pleroma + * Copyright (C) 2022 Nekobit + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "hashtag.h" +#include "string_helpers.h" +#include "easprintf.h" + +// Pages +#include "../static/hashtag.chtml" +#include "../static/hashtag_page.chtml" +#include "../static/hashtag_statistics.chtml" + +#define TAG_SIZE_INITIAL 12 + +char* construct_hashtag(struct mstdnt_tag* hashtag, int* size) +{ + char* hashtag_html; + + // Lol! + unsigned hash_size = TAG_SIZE_INITIAL + + ((unsigned)( + (hashtag->history && hashtag->history_len >= 1 ? + hashtag->history[0].uses : 0) + 4 + /4)*2); + + size_t s = easprintf(&hashtag_html, data_hashtag_html, + hash_size, hashtag->name); + + if (size) *size = s; + return hashtag_html; +} + +static char* construct_hashtag_voidwrap(void* passed, size_t index, int* res) +{ + return construct_hashtag((struct mstdnt_tag*)passed + index, res); +} +char* construct_hashtags(struct mstdnt_tag* hashtags, size_t size, size_t* ret_size) +{ + if (!(hashtags && size)) return NULL; + return construct_func_strings(construct_hashtag_voidwrap, hashtags, size, ret_size); +} + diff --git a/src/hashtag.h b/src/hashtag.h new file mode 100644 index 0000000..a655162 --- /dev/null +++ b/src/hashtag.h @@ -0,0 +1,27 @@ +/* + * Treebird - Lightweight frontend for Pleroma + * Copyright (C) 2022 Nekobit + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef HASHTAG_H +#define HASHTAG_H +#include +#include + +char* construct_hashtag(struct mstdnt_tag* hashtag, int* size); +char* construct_hashtags(struct mstdnt_tag* hashtags, size_t size, size_t* ret_size); + +#endif /* HASHTAG_H */ diff --git a/src/search.c b/src/search.c index 93973e1..d5ddf1b 100644 --- a/src/search.c +++ b/src/search.c @@ -23,6 +23,7 @@ #include "string_helpers.h" #include "base_page.h" #include "status.h" +#include "hashtag.h" #include "error.h" #include "account.h" @@ -137,5 +138,37 @@ void content_search_accounts(struct session* ssn, mastodont_t* api, char** data) void content_search_hashtags(struct session* ssn, mastodont_t* api, char** data) { - search_page(ssn, api, SEARCH_HASHTAGS, "hashtags"); + char* tags_html; + struct mstdnt_storage storage = { 0 }; + struct mstdnt_search_args args = { + .account_id = NULL, + .type = MSTDNT_SEARCH_HASHTAGS, + .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) + { + tags_html = construct_hashtags(results.tags, results.tags_len, NULL); + if (!tags_html) + tags_html = construct_error("No hashtags", E_ERROR, 1, NULL); + } + else + tags_html = construct_error("An error occured.", E_ERROR, 1, NULL); + + search_page(ssn, api, SEARCH_HASHTAGS, STR_NULL_EMPTY(tags_html)); + + if (tags_html) free(tags_html); + // TODO cleanup shit } diff --git a/static/hashtag.html b/static/hashtag.html new file mode 100644 index 0000000..c061630 --- /dev/null +++ b/static/hashtag.html @@ -0,0 +1 @@ +#%s diff --git a/static/hashtag_page.html b/static/hashtag_page.html new file mode 100644 index 0000000..5dec71a --- /dev/null +++ b/static/hashtag_page.html @@ -0,0 +1,8 @@ +
+

Hashtag - #%s

+
+%s +
+ %s +
+%s diff --git a/static/hashtag_statistics.html b/static/hashtag_statistics.html new file mode 100644 index 0000000..3624a7b --- /dev/null +++ b/static/hashtag_statistics.html @@ -0,0 +1 @@ +
[STATISTICS]