From b22d2acf1db7fb6659a1dcff3bfccb3b400c3160 Mon Sep 17 00:00:00 2001 From: nekobit Date: Sat, 11 Jun 2022 05:50:36 +0000 Subject: [PATCH] Following/followers page and some links FossilOrigin-Name: 413c0b46c82bbaf6f224063ffa0b221a7c7885f42b851798d29931143a6699d5 --- src/account.c | 124 ++++++++++++++++++++++++++++++++++-- src/account.h | 5 +- src/main.c | 2 + static/account.tmpl | 6 +- static/account_sidebar.tmpl | 18 ++++-- 5 files changed, 139 insertions(+), 16 deletions(-) diff --git a/src/account.c b/src/account.c index 7ec38e4..9a475b7 100644 --- a/src/account.c +++ b/src/account.c @@ -69,6 +69,7 @@ char* load_account_info(struct mstdnt_account* acct, char* construct_account_sidebar(struct mstdnt_account* acct, size_t* size) { struct account_sidebar_template data = { + .prefix = config_url_prefix, .avatar = acct->avatar, .username = acct->display_name, .statuses_text = L10N[L10N_EN_US][L10N_TAB_STATUSES], @@ -76,11 +77,113 @@ char* construct_account_sidebar(struct mstdnt_account* acct, size_t* size) .followers_text = L10N[L10N_EN_US][L10N_TAB_FOLLOWERS], .statuses_count = acct->statuses_count, .following_count = acct->following_count, - .followers_count = acct->followers_count + .followers_count = acct->followers_count, + .acct = acct->acct, }; return tmpl_gen_account_sidebar(&data, size); } +// TODO put account stuff into one function to cleanup a bit +static char* account_followers_cb(struct session* ssn, + mastodont_t* api, + struct mstdnt_account* acct, + void* _args) +{ + 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 = 0, + .with_relationships = 0, + }; + char* accounts_html = NULL, *navigation_box = NULL; + char* output; + struct mstdnt_storage storage = { 0 }; + struct mstdnt_account* accounts = NULL; + size_t accts_len = 0; + char* start_id; + + if (mastodont_get_followers(api, acct->id, &args, &storage, &accounts, &accts_len)) + { + accounts_html = construct_error(storage.error, E_ERROR, 1, NULL); + } + else { + accounts_html = construct_accounts(api, accounts, accts_len, 0, NULL); + if (!accounts_html) + accounts_html = construct_error("No followers...", E_NOTICE, 1, NULL); + } + + if (accounts) + { + // If not set, set it + start_id = keystr(ssn->post.start_id) ? keystr(ssn->post.start_id) : accounts[0].id; + navigation_box = construct_navigation_box(start_id, + accounts[0].id, + accounts[accts_len-1].id, + NULL); + } + easprintf(&output, "%s%s", + STR_NULL_EMPTY(accounts_html), + STR_NULL_EMPTY(navigation_box)); + + mastodont_storage_cleanup(&storage); + mstdnt_cleanup_accounts(accounts, accts_len); + if (accounts_html) free(accounts_html); + if (navigation_box) free(navigation_box); + return output; +} + +static char* account_following_cb(struct session* ssn, + mastodont_t* api, + struct mstdnt_account* acct, + void* _args) +{ + 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, + }; + char* accounts_html = NULL, *navigation_box = NULL; + char* output; + struct mstdnt_storage storage = { 0 }; + struct mstdnt_account* accounts = NULL; + size_t accts_len = 0; + char* start_id; + + if (mastodont_get_following(api, acct->id, &args, &storage, &accounts, &accts_len)) + { + accounts_html = construct_error(storage.error, E_ERROR, 1, NULL); + } + else { + accounts_html = construct_accounts(api, accounts, accts_len, 0, NULL); + if (!accounts_html) + accounts_html = construct_error("Not following anyone", E_NOTICE, 1, NULL); + } + + if (accounts) + { + // If not set, set it + start_id = keystr(ssn->post.start_id) ? keystr(ssn->post.start_id) : accounts[0].id; + navigation_box = construct_navigation_box(start_id, + accounts[0].id, + accounts[accts_len-1].id, + NULL); + } + easprintf(&output, "%s%s", + STR_NULL_EMPTY(accounts_html), + STR_NULL_EMPTY(navigation_box)); + + mastodont_storage_cleanup(&storage); + mstdnt_cleanup_accounts(accounts, accts_len); + if (accounts_html) free(accounts_html); + if (navigation_box) free(navigation_box); + return output; +} + static char* account_statuses_cb(struct session* ssn, mastodont_t* api, struct mstdnt_account* acct, @@ -91,7 +194,7 @@ static char* account_statuses_cb(struct session* ssn, struct mstdnt_account_statuses_args* args = _args; char* statuses_html = NULL, *navigation_box = NULL; char* output; - struct mstdnt_storage storage; + struct mstdnt_storage storage = { 0 }; struct mstdnt_status* statuses = NULL; size_t statuses_len = 0; char* start_id; @@ -132,7 +235,7 @@ static char* account_scrobbles_cb(struct session* ssn, mastodont_t* api, struct (void)ssn; (void)_args; char* scrobbles_html = NULL; - struct mstdnt_storage storage; + struct mstdnt_storage storage = { 0 }; struct mstdnt_scrobble* scrobbles = NULL; size_t scrobbles_len = 0; struct mstdnt_get_scrobbles_args args = { @@ -287,6 +390,7 @@ size_t construct_account_page(struct session* ssn, if (is_same_user) { struct account_current_menubar_template acmdata = { + .prefix = config_url_prefix, .blocked_str = "Blocks", .muted_str = "Mutes", .favourited_str = "Favorites", @@ -422,11 +526,8 @@ char* load_account_page(struct session* ssn, return result; } - - void content_account_statuses(struct session* ssn, mastodont_t* api, char** data) { - struct mstdnt_account_statuses_args args = { .pinned = 0, .only_media = 0, @@ -440,9 +541,20 @@ void content_account_statuses(struct session* ssn, mastodont_t* api, char** data .offset = 0, .limit = 20, }; + fetch_account_page(ssn, api, data[0], &args, ACCT_TAB_STATUSES, account_statuses_cb); } +void content_account_followers(struct session* ssn, mastodont_t* api, char** data) +{ + fetch_account_page(ssn, api, data[0], NULL, ACCT_TAB_NONE, account_followers_cb); +} + +void content_account_following(struct session* ssn, mastodont_t* api, char** data) +{ + fetch_account_page(ssn, api, data[0], NULL, ACCT_TAB_NONE, account_following_cb); +} + void content_account_scrobbles(struct session* ssn, mastodont_t* api, char** data) { fetch_account_page(ssn, api, data[0], NULL, ACCT_TAB_SCROBBLES, account_scrobbles_cb); diff --git a/src/account.h b/src/account.h index ee4bab5..e0107db 100644 --- a/src/account.h +++ b/src/account.h @@ -29,10 +29,11 @@ enum account_tab { + ACCT_TAB_NONE, ACCT_TAB_STATUSES, ACCT_TAB_SCROBBLES, ACCT_TAB_PINNED, - ACCT_TAB_MEDIA + ACCT_TAB_MEDIA, }; struct account_page @@ -82,6 +83,8 @@ char* load_account_page(struct session* ssn, char* load_account_info(struct mstdnt_account* acct, size_t* size); +void content_account_followers(struct session* ssn, mastodont_t* api, char** data); +void content_account_following(struct session* ssn, mastodont_t* api, char** data); 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); diff --git a/src/main.c b/src/main.c index bc5e8d0..331710e 100644 --- a/src/main.c +++ b/src/main.c @@ -71,6 +71,8 @@ int main(void) { "/@:/scrobbles", content_account_scrobbles }, { "/@:/pinned", content_account_pinned }, { "/@:/media", content_account_media }, + { "/@:/following", content_account_following }, + { "/@:/followers", content_account_followers }, { "/@:", content_account_statuses }, { "/status/:/react/:", content_status_react }, { "/status/:/react", status_emoji }, diff --git a/static/account.tmpl b/static/account.tmpl index eb25a36..aad5b62 100644 --- a/static/account.tmpl +++ b/static/account.tmpl @@ -21,17 +21,17 @@
- + {{%s:tab_statuses_text}} {{%d:statuses_count}} - + {{%s:tab_following_text}} {{%d:following_count}} - + {{%s:tab_followers_text}} {{%d:followers_count}} diff --git a/static/account_sidebar.tmpl b/static/account_sidebar.tmpl index 51b0066..ad23367 100644 --- a/static/account_sidebar.tmpl +++ b/static/account_sidebar.tmpl @@ -6,16 +6,22 @@
- {{%s:statuses_text}} - {{%d:statuses_count}} + + {{%s:statuses_text}} + {{%d:statuses_count}} + - {{%s:following_text}} - {{%d:following_count}} + + {{%s:following_text}} + {{%d:following_count}} + - {{%s:followers_text}} - {{%d:followers_count}} + + {{%s:followers_text}} + {{%d:followers_count}} +