forked from mirrors/treebird
Create sidebar
FossilOrigin-Name: 867d2d317849fbb7cba4005a76dce17822afbd603e8205e2da705381299d40bc
This commit is contained in:
parent
9a2baf0430
commit
b677ba4b52
5 changed files with 69 additions and 3 deletions
2
Makefile
2
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
|
||||
|
|
|
@ -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 "<span class=\"acct-badge\">%s</span>"
|
||||
|
||||
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 = "<a href=\"login\" id=\"login-header\">Login / Register</a>";
|
||||
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);
|
||||
}
|
||||
|
|
22
static/account_sidebar.html
Normal file
22
static/account_sidebar.html
Normal file
|
@ -0,0 +1,22 @@
|
|||
<div class="account-sidebar">
|
||||
<div class="acct-info">
|
||||
<img src="%s" class="acct-pfp">
|
||||
<span class="username">%s</span>
|
||||
</div>
|
||||
<table class="acct-stats">
|
||||
<tr>
|
||||
<td class="header-btn btn">
|
||||
<span class="btn-header">%s</span>
|
||||
<span class="btn-content">%d</span>
|
||||
</td>
|
||||
<td class="header-btn btn">
|
||||
<span class="btn-header">%s</span>
|
||||
<span class="btn-content">%d</span>
|
||||
</td>
|
||||
<td class="header-btn btn">
|
||||
<span class="btn-header">%s</span>
|
||||
<span class="btn-content">%d</span>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
Loading…
Reference in a new issue