From ff3cd19926c5da85f4584a5e397c3a50320c7d38 Mon Sep 17 00:00:00 2001 From: "me@ow.nekobit.net" Date: Tue, 5 Apr 2022 16:18:44 +0000 Subject: [PATCH] Fix account page FossilOrigin-Name: e0fd2365447f86aa57fc204a248178d6a1c4c52c9241d25339d545f010dc3d10 --- dist/treebird20.css | 36 ++++++++++++++++++++++++++++- src/account.c | 55 +++++++++++++++++++++++++++++++++++++++++++-- src/account.h | 1 + src/main.c | 1 + static/account.html | 17 +++++++++++++- 5 files changed, 106 insertions(+), 4 deletions(-) diff --git a/dist/treebird20.css b/dist/treebird20.css index 2523fd6..a2d6617 100644 --- a/dist/treebird20.css +++ b/dist/treebird20.css @@ -657,6 +657,19 @@ svg.in-reply-to-icon position: relative; } +.acct-badge +{ + position: absolute; + left: 8px; + top: 8px; + font-size: 12px; + padding: 4px 8px; + color: #dadada; + text-transform: uppercase; + background-color: rgba(0, 0, 0, 0.7); + border-radius: 5px; +} + .account-note { word-break: break-all; @@ -997,7 +1010,8 @@ ul.large-list li a /* MENUS */ -.menu-container:hover .menu +.menu-container:hover .menu, +.menu-container:hover + .menu { position: absolute; display: block; @@ -1008,6 +1022,7 @@ ul.large-list li a z-index: 5; display: none; background: #fafafa; + color: #000; border-radius: 4px; box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.3); } @@ -1021,6 +1036,7 @@ ul.large-list li a .menu ul li { list-style-type: none; + display: block; } .menu .btn-menu @@ -1033,6 +1049,19 @@ ul.large-list li a border: 0; cursor: pointer; text-align: left; + box-sizing: border-box; +} + +.user-options-btn +{ + padding: 4px; + border-radius: 64px; + margin: 8px; + float: right; + font-size: 12px; + color: #dadada; + text-transform: uppercase; + background-color: rgba(0, 0, 0, .7); } .menu .btn-menu:hover @@ -1040,3 +1069,8 @@ ul.large-list li a background-color: #eaeaea; color: #000; } + +.nolink +{ + text-decoration: none; +} diff --git a/src/account.c b/src/account.c index 4ded627..3402393 100644 --- a/src/account.c +++ b/src/account.c @@ -24,12 +24,15 @@ #include "account.h" #include "easprintf.h" #include "status.h" +#include "http.h" // Files #include "../static/index.chtml" #include "../static/account.chtml" #include "../static/account_info.chtml" +#define FOLLOWS_YOU_HTML "%s" + char* construct_account_info(struct mstdnt_account* acct, size_t* size) { @@ -53,6 +56,7 @@ char* construct_account_page(mastodont_t* api, int cleanup = 0; int result_size; char* statuses_html; + char* follows_you = NULL; char* info_html = NULL; char* result; @@ -67,19 +71,37 @@ char* construct_account_page(mastodont_t* api, { info_html = construct_account_info(acct, NULL); } + + if (relationship) + if (MSTDNT_FLAG_ISSET(relationship->flags, MSTDNT_RELATIONSHIP_FOLLOWED_BY)) + easprintf(&follows_you, FOLLOWS_YOU_HTML, "Follows you"); result_size = easprintf(&result, data_account_html, + "", acct->header, + follows_you ? follows_you : "", acct->display_name, acct->acct, + config_url_prefix, + acct->acct, + !relationship ? "" : MSTDNT_FLAG_ISSET(relationship->flags, MSTDNT_RELATIONSHIP_NOTIFYING) ? "un" : "", + !relationship ? "" : MSTDNT_FLAG_ISSET(relationship->flags, MSTDNT_RELATIONSHIP_NOTIFYING) ? "Unsubscribe" : "Subscribe", + config_url_prefix, + acct->acct, + !relationship ? "" : MSTDNT_FLAG_ISSET(relationship->flags, MSTDNT_RELATIONSHIP_BLOCKING) ? "un" : "", + !relationship ? "" : MSTDNT_FLAG_ISSET(relationship->flags, MSTDNT_RELATIONSHIP_BLOCKING) ? "Unblock" : "Block", + config_url_prefix, + acct->acct, + !relationship ? "" : MSTDNT_FLAG_ISSET(relationship->flags, MSTDNT_RELATIONSHIP_MUTING) ? "un" : "", + !relationship ? "" : MSTDNT_FLAG_ISSET(relationship->flags, MSTDNT_RELATIONSHIP_MUTING) ? "Unmute" : "Mute", "Statuses", acct->statuses_count, "Following", acct->following_count, "Followers", acct->followers_count, - MSTDNT_FLAG_ISSET(relationship->flags, MSTDNT_RELATIONSHIP_FOLLOWING) ? "active" : "", - MSTDNT_FLAG_ISSET(relationship->flags, MSTDNT_RELATIONSHIP_FOLLOWING) ? "Following!" : "Follow", + !relationship ? "" : MSTDNT_FLAG_ISSET(relationship->flags, MSTDNT_RELATIONSHIP_FOLLOWING) ? "active" : "", + !relationship ? "" : MSTDNT_FLAG_ISSET(relationship->flags, MSTDNT_RELATIONSHIP_FOLLOWING) ? "Following!" : "Follow", acct->avatar, info_html ? info_html : "", statuses_html); @@ -90,6 +112,7 @@ char* construct_account_page(mastodont_t* api, if (res_size) *res_size = result_size; if (cleanup) free(statuses_html); if (info_html) free(info_html); + if (follows_you) free(follows_you); return result; } @@ -145,3 +168,31 @@ void content_account(struct session* ssn, mastodont_t* api, char** data) mstdnt_cleanup_relationships(relationships); free(account_page); } + +void content_account_action(struct session* ssn, mastodont_t* api, char** data) +{ + char* referer = getenv("HTTP_REFERER"); + struct mstdnt_storage storage = { 0 }; + struct mstdnt_account acct = { 0 }; + + if (strcmp(data[1], "follow") == 0) + mastodont_follow_account(api, data[0], &storage, &acct); + else if (strcmp(data[1], "unfollow") == 0) + mastodont_unfollow_account(api, data[0], &storage, &acct); + else if (strcmp(data[1], "mute") == 0) + mastodont_mute_account(api, data[0], &storage, &acct); + else if (strcmp(data[1], "unmute") == 0) + mastodont_unmute_account(api, data[0], &storage, &acct); + else if (strcmp(data[1], "block") == 0) + mastodont_block_account(api, data[0], &storage, &acct); + else if (strcmp(data[1], "unblock") == 0) + mastodont_unblock_account(api, data[0], &storage, &acct); + else if (strcmp(data[1], "subscribe") == 0) + mastodont_subscribe_account(api, data[0], &storage, &acct); + else if (strcmp(data[1], "unsubscribe") == 0) + mastodont_unsubscribe_account(api, data[0], &storage, &acct); + + mastodont_storage_cleanup(&storage); + + redirect(REDIRECT_303, referer); +} diff --git a/src/account.h b/src/account.h index 6ea1c8d..14e72e1 100644 --- a/src/account.h +++ b/src/account.h @@ -32,4 +32,5 @@ char* construct_account_page(mastodont_t* api, size_t* res_size); void content_account(struct session* ssn, mastodont_t* api, char** data); +void content_account_action(struct session* ssn, mastodont_t* api, char** data); #endif // ACCOUNT_H diff --git a/src/main.c b/src/main.c index f2ec039..0335d7b 100644 --- a/src/main.c +++ b/src/main.c @@ -83,6 +83,7 @@ int main(void) /* { "/config/account", content_config_account }, */ { "/login", content_login }, { "/test", content_test }, + { "/@:/action/:", content_account_action }, { "/@:", content_account }, { "/status/create", content_status_create }, { "/status/:/interact", status_interact }, diff --git a/static/account.html b/static/account.html index bb9ba4d..644a482 100644 --- a/static/account.html +++ b/static/account.html @@ -1,9 +1,22 @@
+ %s
+ %s
%s %s
+ + + Menu + +
@@ -22,7 +35,9 @@ %d - +