From 8d153983d6abbf0b8c1803e3477a49f169519f32 Mon Sep 17 00:00:00 2001 From: nekobit Date: Sun, 12 Jun 2022 05:44:45 +0000 Subject: [PATCH] Mute and block pages FossilOrigin-Name: 0fa2aeb7c66595fade365d8c4ea7d027b83657aa9679223b13ee6844f7b7ae32 --- src/account.c | 80 +++++++++++++++++++-- src/account.h | 2 + src/main.c | 2 + static/{block_page.tmpl => basic_page.tmpl} | 4 +- static/mute_page.tmpl | 4 -- 5 files changed, 82 insertions(+), 10 deletions(-) rename static/{block_page.tmpl => basic_page.tmpl} (64%) delete mode 100644 static/mute_page.tmpl diff --git a/src/account.c b/src/account.c index e443786..677c1c8 100644 --- a/src/account.c +++ b/src/account.c @@ -40,6 +40,7 @@ #include "../static/account_stub.ctmpl" #include "../static/account_sidebar.ctmpl" #include "../static/account_current_menubar.ctmpl" +#include "../static/basic_page.ctmpl" #define FOLLOWS_YOU_HTML "%s" @@ -174,7 +175,6 @@ static char* account_following_cb(struct session* ssn, NULL); } easprintf(&output, "%s%s", - STR_NULL_EMPTY(navigation_box), STR_NULL_EMPTY(accounts_html), STR_NULL_EMPTY(navigation_box)); @@ -684,9 +684,81 @@ void content_account_bookmarks(struct session* ssn, mastodont_t* api, char** dat // Cleanup mastodont_storage_cleanup(&storage); mstdnt_cleanup_statuses(statuses, status_count); - if (status_format) free(status_format); - if (navigation_box) free(navigation_box); - if (output) free(output); + free(status_format); + free(navigation_box); + free(output); +} + +static void accounts_page(mastodont_t* api, + struct session* ssn, + struct mstdnt_storage* storage, + char* header, + struct mstdnt_account* accts, + size_t accts_len) +{ + char* output; + char* content = construct_accounts(api, accts, accts_len, 0, NULL); + if (!content) + content = construct_error("No accounts here!", E_NOTICE, 1, NULL); + + struct basic_page_template tdata = { + .back_ref = getenv("HTTP_REFERER"), + .page_title = header, + .page_content = content, + }; + output = tmpl_gen_basic_page(&tdata, NULL); + + struct base_page b = { + .category = BASE_CAT_NONE, + .content = output, + .sidebar_left = NULL + }; + + // Output + render_base_page(&b, ssn, api); + + mastodont_storage_cleanup(storage); + free(output); + free(content); +} + + +void content_account_blocked(struct session* ssn, mastodont_t* api, char** data) +{ + struct mstdnt_account_args args = { + .max_id = keystr(ssn->post.max_id), + .since_id = NULL, + .min_id = keystr(ssn->post.min_id), + .offset = 0, + .limit = 20, + .with_relationships = 0, + }; + struct mstdnt_storage storage = { 0 }; + struct mstdnt_account* accts = NULL; + size_t accts_len = 0; + + mastodont_get_blocks(api, &args, &storage, &accts, &accts_len); + + accounts_page(api, ssn, &storage, "Blocked users", accts, accts_len); +} + +void content_account_muted(struct session* ssn, mastodont_t* api, char** data) +{ + struct mstdnt_account_args args = { + .max_id = keystr(ssn->post.max_id), + .since_id = NULL, + .min_id = keystr(ssn->post.min_id), + .offset = 0, + .limit = 20, + .with_relationships = 0, + }; + struct mstdnt_storage storage = { 0 }; + struct mstdnt_account* accts = NULL; + size_t accts_len = 0; + + mastodont_get_mutes(api, &args, &storage, &accts, &accts_len); + + accounts_page(api, ssn, &storage, "Muted users", accts, accts_len); } void content_account_favourites(struct session* ssn, mastodont_t* api, char** data) diff --git a/src/account.h b/src/account.h index e0107db..a1671c8 100644 --- a/src/account.h +++ b/src/account.h @@ -88,6 +88,8 @@ void content_account_following(struct session* ssn, mastodont_t* api, char** dat void content_account_statuses(struct session* ssn, mastodont_t* api, char** data); void content_account_scrobbles(struct session* ssn, mastodont_t* api, char** data); void content_account_pinned(struct session* ssn, mastodont_t* api, char** data); +void content_account_blocked(struct session* ssn, mastodont_t* api, char** data); +void content_account_muted(struct session* ssn, mastodont_t* api, char** data); void content_account_media(struct session* ssn, mastodont_t* api, char** data); void content_account_action(struct session* ssn, mastodont_t* api, char** data); void content_account_favourites(struct session* ssn, mastodont_t* api, char** data); diff --git a/src/main.c b/src/main.c index 331710e..e758804 100644 --- a/src/main.c +++ b/src/main.c @@ -97,6 +97,8 @@ int main(void) { "/local", content_tl_local }, { "/bookmarks", content_account_bookmarks }, { "/favourites", content_account_favourites }, + { "/blocked", content_account_blocked }, + { "/muted", content_account_muted }, { "/notifications_compact", content_notifications_compact }, { "/notifications", content_notifications }, { "/tag/:", content_tl_tag }, diff --git a/static/block_page.tmpl b/static/basic_page.tmpl similarity index 64% rename from static/block_page.tmpl rename to static/basic_page.tmpl index f782ca5..d7f455b 100644 --- a/static/block_page.tmpl +++ b/static/basic_page.tmpl @@ -1,4 +1,4 @@
-

< {{ %s : blocks_str }}

+

< {{ %s : page_title }}

-{{%s : blocks}} +{{%s : page_content}} diff --git a/static/mute_page.tmpl b/static/mute_page.tmpl deleted file mode 100644 index 9b20c86..0000000 --- a/static/mute_page.tmpl +++ /dev/null @@ -1,4 +0,0 @@ -
-

< {{ %s : mutes_str }}

-
-{{%s : mutes}}