forked from mirrors/treebird
Following/followers page and some links
FossilOrigin-Name: 413c0b46c82bbaf6f224063ffa0b221a7c7885f42b851798d29931143a6699d5
This commit is contained in:
parent
698bba32c6
commit
b22d2acf1d
5 changed files with 139 additions and 16 deletions
124
src/account.c
124
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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 },
|
||||
|
|
|
@ -21,17 +21,17 @@
|
|||
</div>
|
||||
|
||||
<div class="acct-header">
|
||||
<a href="#" class="header-btn btn">
|
||||
<a href="{{%s:prefix}}/@{{%s:acct}}" class="header-btn btn">
|
||||
<span class="btn-header">{{%s:tab_statuses_text}}</span>
|
||||
<span class="btn-content">{{%d:statuses_count}}</span>
|
||||
</a>
|
||||
|
||||
<a href="#" class="header-btn btn">
|
||||
<a href="{{%s:prefix}}/@{{%s:acct}}/following" class="header-btn btn">
|
||||
<span class="btn-header">{{%s:tab_following_text}}</span>
|
||||
<span class="btn-content">{{%d:following_count}}</span>
|
||||
</a>
|
||||
|
||||
<a href="#" class="header-btn btn">
|
||||
<a href="{{%s:prefix}}/@{{%s:acct}}/followers" class="header-btn btn">
|
||||
<span class="btn-header">{{%s:tab_followers_text}}</span>
|
||||
<span class="btn-content">{{%d:followers_count}}</span>
|
||||
</a>
|
||||
|
|
|
@ -6,16 +6,22 @@
|
|||
<table class="acct-stats">
|
||||
<tr>
|
||||
<td class="header-btn btn">
|
||||
<span class="btn-header">{{%s:statuses_text}}</span>
|
||||
<span class="btn-content">{{%d:statuses_count}}</span>
|
||||
<a href="{{%s:prefix}}/@{{%s:acct}}">
|
||||
<span class="btn-header">{{%s:statuses_text}}</span>
|
||||
<span class="btn-content">{{%d:statuses_count}}</span>
|
||||
</a>
|
||||
</td>
|
||||
<td class="header-btn btn">
|
||||
<span class="btn-header">{{%s:following_text}}</span>
|
||||
<span class="btn-content">{{%d:following_count}}</span>
|
||||
<a href="{{%s:prefix}}/@{{%s:acct}}/following">
|
||||
<span class="btn-header">{{%s:following_text}}</span>
|
||||
<span class="btn-content">{{%d:following_count}}</span>
|
||||
</a>
|
||||
</td>
|
||||
<td class="header-btn btn">
|
||||
<span class="btn-header">{{%s:followers_text}}</span>
|
||||
<span class="btn-content">{{%d:followers_count}}</span>
|
||||
<a href="{{%s:prefix}}/@{{%s:acct}}/followers">
|
||||
<span class="btn-header">{{%s:followers_text}}</span>
|
||||
<span class="btn-content">{{%d:followers_count}}</span>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
Loading…
Reference in a new issue