Account functions

FossilOrigin-Name: a32d953bdc2116c3fbf2b70648b91d2457091f23d1fb7193beeaace096fd0a1c
This commit is contained in:
me@ow.nekobit.net 2022-04-14 13:47:33 +00:00
parent ab365a3352
commit 99af4cd8b9
3 changed files with 189 additions and 3 deletions

View file

@ -191,6 +191,186 @@ void content_account_statuses(struct session* ssn, mastodont_t* api, char** data
free(account_page);
}
void content_account_scrobbles(struct session* ssn, mastodont_t* api, char** data)
{
char* account_page;
struct mstdnt_account acct = { 0 };
struct mstdnt_storage storage = { 0 }, status_storage = { 0 }, relations_storage = { 0 };
struct mstdnt_status* statuses = NULL;
struct mstdnt_relationship* relationships = { 0 };
size_t statuses_len = 0;
char* statuses_html = NULL;
size_t relationships_len = 0;
int lookup_type = config_experimental_lookup ? MSTDNT_LOOKUP_ACCT : MSTDNT_LOOKUP_ID;
if (mastodont_get_account(api, lookup_type, data[0],
&acct, &storage, NULL) ||
mastodont_get_account_statuses(api, acct.id, NULL,
&status_storage, &statuses, &statuses_len))
{
account_page = construct_error(status_storage.error, E_ERROR, 1, NULL);
}
else {
/* Not an error? */
mastodont_get_relationships(api, &(acct.id), 1, &relations_storage, &relationships, &relationships_len);
// Create statuses HTML
statuses_html = construct_statuses(api, statuses, statuses_len, NULL);
if (!statuses_html)
statuses_html = construct_error("No statuses", E_NOTICE, 1, NULL);
account_page = construct_account_page(api,
&acct,
relationships,
ACCT_TAB_SCROBBLES,
statuses_html,
NULL);
if (!account_page)
exit(EXIT_FAILURE);
}
struct base_page b = {
.category = BASE_CAT_NONE,
.locale = L10N_EN_US,
.content = account_page,
.sidebar_left = NULL
};
/* Output */
render_base_page(&b, ssn, api);
/* Cleanup */
mastodont_storage_cleanup(&storage);
mastodont_storage_cleanup(&status_storage);
mastodont_storage_cleanup(&relations_storage);
mstdnt_cleanup_statuses(statuses, statuses_len);
mstdnt_cleanup_relationships(relationships);
free(statuses_html);
free(account_page);
}
void content_account_pinned(struct session* ssn, mastodont_t* api, char** data)
{
char* account_page;
struct mstdnt_account acct = { 0 };
struct mstdnt_storage storage = { 0 }, status_storage = { 0 }, relations_storage = { 0 };
struct mstdnt_status* statuses = NULL;
struct mstdnt_relationship* relationships = { 0 };
size_t statuses_len = 0;
char* statuses_html = NULL;
size_t relationships_len = 0;
int lookup_type = config_experimental_lookup ? MSTDNT_LOOKUP_ACCT : MSTDNT_LOOKUP_ID;
if (mastodont_get_account(api, lookup_type, data[0],
&acct, &storage, NULL) ||
mastodont_get_account_statuses(api, acct.id, NULL,
&status_storage, &statuses, &statuses_len))
{
account_page = construct_error(status_storage.error, E_ERROR, 1, NULL);
}
else {
/* Not an error? */
mastodont_get_relationships(api, &(acct.id), 1, &relations_storage, &relationships, &relationships_len);
// Create statuses HTML
statuses_html = construct_statuses(api, statuses, statuses_len, NULL);
if (!statuses_html)
statuses_html = construct_error("No statuses", E_NOTICE, 1, NULL);
account_page = construct_account_page(api,
&acct,
relationships,
ACCT_TAB_PINNED,
statuses_html,
NULL);
if (!account_page)
exit(EXIT_FAILURE);
}
struct base_page b = {
.category = BASE_CAT_NONE,
.locale = L10N_EN_US,
.content = account_page,
.sidebar_left = NULL
};
/* Output */
render_base_page(&b, ssn, api);
/* Cleanup */
mastodont_storage_cleanup(&storage);
mastodont_storage_cleanup(&status_storage);
mastodont_storage_cleanup(&relations_storage);
mstdnt_cleanup_statuses(statuses, statuses_len);
mstdnt_cleanup_relationships(relationships);
free(statuses_html);
free(account_page);
}
void content_account_media(struct session* ssn, mastodont_t* api, char** data)
{
char* account_page;
struct mstdnt_account acct = { 0 };
struct mstdnt_storage storage = { 0 }, status_storage = { 0 }, relations_storage = { 0 };
struct mstdnt_status* statuses = NULL;
struct mstdnt_relationship* relationships = { 0 };
size_t statuses_len = 0;
char* statuses_html = NULL;
size_t relationships_len = 0;
int lookup_type = config_experimental_lookup ? MSTDNT_LOOKUP_ACCT : MSTDNT_LOOKUP_ID;
if (mastodont_get_account(api, lookup_type, data[0],
&acct, &storage, NULL) ||
mastodont_get_account_statuses(api, acct.id, NULL,
&status_storage, &statuses, &statuses_len))
{
account_page = construct_error(status_storage.error, E_ERROR, 1, NULL);
}
else {
/* Not an error? */
mastodont_get_relationships(api, &(acct.id), 1, &relations_storage, &relationships, &relationships_len);
// Create statuses HTML
statuses_html = construct_statuses(api, statuses, statuses_len, NULL);
if (!statuses_html)
statuses_html = construct_error("No statuses", E_NOTICE, 1, NULL);
account_page = construct_account_page(api,
&acct,
relationships,
ACCT_TAB_MEDIA,
statuses_html,
NULL);
if (!account_page)
exit(EXIT_FAILURE);
}
struct base_page b = {
.category = BASE_CAT_NONE,
.locale = L10N_EN_US,
.content = account_page,
.sidebar_left = NULL
};
/* Output */
render_base_page(&b, ssn, api);
/* Cleanup */
mastodont_storage_cleanup(&storage);
mastodont_storage_cleanup(&status_storage);
mastodont_storage_cleanup(&relations_storage);
mstdnt_cleanup_statuses(statuses, statuses_len);
mstdnt_cleanup_relationships(relationships);
free(statuses_html);
free(account_page);
}
void content_account_action(struct session* ssn, mastodont_t* api, char** data)
{
char* referer = getenv("HTTP_REFERER");

View file

@ -42,5 +42,11 @@ char* construct_account_info(struct mstdnt_account* acct,
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);
void content_account_media(struct session* ssn, mastodont_t* api, char** data);
void content_account_action(struct session* ssn, mastodont_t* api, char** data);
#endif // ACCOUNT_H

View file

@ -86,10 +86,10 @@ int main(void)
{ "/test", content_test },
{ "/user/:/action/:", content_account_action },
{ "/search", content_search },
{ "/@:/scrobbles", content_account_scrobbles },
{ "/@:/pinned", content_account_pinned },
{ "/@:/media", content_account_media },
{ "/@:", content_account_statuses },
/* { "/@:/scrobbles", content_account_scrobbles }, */
/* { "/@:/pinned", content_account_pinned }, */
/* { "/@:/media", content_account_media }, */
{ "/status/create", content_status_create },
{ "/status/:/interact", status_interact },
{ "/status/:/reply", status_reply },