diff --git a/Makefile b/Makefile index abf3e89..347ff4b 100644 --- a/Makefile +++ b/Makefile @@ -117,6 +117,8 @@ $(PAGES_DIR)/emoji.chtml: $(PAGES_DIR)/emoji.html # Login panel $(PAGES_DIR)/quick_login.chtml: $(PAGES_DIR)/quick_login.html ./filec $< data_quick_login_html > $@ +$(PAGES_DIR)/account_sidebar.chtml: $(PAGES_DIR)/account_sidebar.html + ./filec $< data_account_sidebar_html > $@ $(MASTODONT_DIR): fossil clone $(MASTODONT_URL) || true diff --git a/src/account.c b/src/account.c index 99acf1b..a592b34 100644 --- a/src/account.c +++ b/src/account.c @@ -37,6 +37,7 @@ #include "../static/favourites_page.chtml" #include "../static/bookmarks_page.chtml" #include "../static/account_stub.chtml" +#include "../static/account_sidebar.chtml" #define FOLLOWS_YOU_HTML "%s" @@ -60,6 +61,25 @@ char* load_account_info(struct mstdnt_account* acct, return acct_info_html; } +char* construct_account_sidebar(struct mstdnt_account* acct, size_t* size) +{ + char* acct_sidebar_html; + size_t s; + + s = easprintf(&acct_sidebar_html, data_account_sidebar_html, + acct->avatar, + acct->display_name, + L10N[L10N_EN_US][L10N_TAB_STATUSES], + acct->statuses_count, + L10N[L10N_EN_US][L10N_TAB_FOLLOWING], + acct->following_count, + L10N[L10N_EN_US][L10N_TAB_FOLLOWERS], + acct->followers_count); + + if (size) *size = s; + return acct_sidebar_html; +} + static char* account_statuses_cb(struct session* ssn, mastodont_t* api, struct mstdnt_account* acct, diff --git a/src/account.h b/src/account.h index f6e7473..71eba04 100644 --- a/src/account.h +++ b/src/account.h @@ -53,6 +53,9 @@ struct account_page struct mstdnt_relationship* relationship; }; + +char* construct_account_sidebar(struct mstdnt_account* acct, size_t* size); + char* construct_account(mastodont_t* api, struct mstdnt_account* account, uint8_t flags, diff --git a/src/base_page.c b/src/base_page.c index c216042..5ca10f7 100644 --- a/src/base_page.c +++ b/src/base_page.c @@ -26,6 +26,7 @@ #include "string_helpers.h" #include "../config.h" #include "local_config_set.h" +#include "account.h" // Files #include "../static/index.chtml" @@ -39,8 +40,12 @@ void render_base_page(struct base_page* page, struct session* ssn, mastodont_t* enum l10n_locale locale = page->locale; char* login_string = "Login / Register"; char* background_url_css = NULL; - char* sidebar_str = NULL; + // Sidebar + char* sidebar_str, + * main_sidebar_str = NULL, + * account_sidebar_str = NULL; // Mastodont, used for notifications sidebar + struct mstdnt_account acct = { 0 }; struct mstdnt_storage storage = { 0 }; struct mstdnt_notification* notifs = NULL; size_t notifs_len = 0; @@ -58,6 +63,13 @@ void render_base_page(struct base_page* page, struct session* ssn, mastodont_t* // If user is logged in if (ssn->cookies.logged_in && ssn->cookies.access_token) { + if (mastodont_verify_credentials(api, &acct, &storage) == 0) + { + account_sidebar_str = construct_account_sidebar(&acct, NULL); + } + mstdnt_cleanup_account(&acct); + mastodont_storage_cleanup(&storage); // reuse it later + // Get / Show notifications on sidebar struct mstdnt_get_notifications_args args = { .exclude_types = 0, @@ -74,7 +86,7 @@ void render_base_page(struct base_page* page, struct session* ssn, mastodont_t* if (mastodont_get_notifications(api, &args, &storage, ¬ifs, ¬ifs_len) == 0) { - sidebar_str = construct_notifications_compact(ssn, api, notifs, notifs_len, NULL); + main_sidebar_str = construct_notifications_compact(ssn, api, notifs, notifs_len, NULL); } mstdnt_cleanup_notifications(notifs, notifs_len); @@ -82,13 +94,18 @@ void render_base_page(struct base_page* page, struct session* ssn, mastodont_t* } else { // Construct small login page - easprintf(&sidebar_str, data_quick_login_html, + easprintf(&main_sidebar_str, data_quick_login_html, config_url_prefix, L10N[L10N_EN_US][L10N_USERNAME], L10N[L10N_EN_US][L10N_PASSWORD], L10N[L10N_EN_US][L10N_LOGIN_BTN]); } + // Combine into sidebar + easprintf(&sidebar_str, "%s%s", + account_sidebar_str ? account_sidebar_str : "", + main_sidebar_str ? main_sidebar_str : ""); + char* data; int len = easprintf(&data, data_index_html, L10N[locale][L10N_APP_NAME], @@ -148,5 +165,7 @@ void render_base_page(struct base_page* page, struct session* ssn, mastodont_t* free(data); cleanup: if (sidebar_str) free(sidebar_str); + if (main_sidebar_str) free(main_sidebar_str); + if (account_sidebar_str) free(account_sidebar_str); if (background_url_css) free(background_url_css); } diff --git a/static/account_sidebar.html b/static/account_sidebar.html new file mode 100644 index 0000000..89fcd89 --- /dev/null +++ b/static/account_sidebar.html @@ -0,0 +1,22 @@ +
+
+ + %s +
+ + + + + + +
+ %s + %d + + %s + %d + + %s + %d +
+