Show statuses on account

FossilOrigin-Name: fb3e19202252a211b3da878dca69e486359e98c1021746e45c09ef3de14588fa
This commit is contained in:
me@ow.nekobit.net 2022-02-11 04:24:11 +00:00
parent 8dbeb095f1
commit dc7694ee74
4 changed files with 52 additions and 10 deletions

View file

@ -33,4 +33,17 @@ static char* const config_canonical_name = "RatFE";
*/
static char* const config_instance_url = "https://desuposter.club/";
/*
* Bool: experimental_lookup
*
* Uses experimental acct lookup (@user@domain)
* This allows for the new lookup feature, which can get
* information for local and federated accounts regardless if signed in.
*
* This feature is new and was introduced in the develop branch in 2022.
* Keep this disabled if running an older pleroma build, or because you just
* don't want it.
*/
static const int config_experimental_lookup = FALSE;
#endif // CONFIG_H

View file

@ -22,15 +22,29 @@
#include "../config.h"
#include "account.h"
#include "easprintf.h"
#include "status.h"
// Files
#include "../static/index.chtml"
#include "../static/account.chtml"
char* construct_account_page(struct mstdnt_account* acct, size_t* res_size)
char* construct_account_page(struct mstdnt_account* acct,
struct mstdnt_status* statuses,
size_t statuses_len,
size_t* res_size)
{
int cleanup = 0;
int result_size;
char* statuses_html;
char* result;
// Load statuses html
statuses_html = construct_statuses(statuses, statuses_len, NULL);
if (!statuses_html)
statuses_html = "Error in malloc!";
else
cleanup = 1;
result_size = easprintf(&result, data_account_html,
acct->header,
acct->display_name,
@ -42,11 +56,13 @@ char* construct_account_page(struct mstdnt_account* acct, size_t* res_size)
0,
"Followers",
0,
"Content");
statuses_html);
if (result_size == -1)
result = NULL;
if (res_size) *res_size = result_size;
if (cleanup) free(statuses_html);
return result;
}
@ -55,15 +71,24 @@ void content_account(mastodont_t* api, char** data, size_t size)
int cleanup = 0;
char* account_page;
struct mstdnt_account acct;
struct mstdnt_storage storage;
struct mstdnt_storage storage, status_storage;
struct mstdnt_status* statuses;
size_t status_len;
int lookup_type = config_experimental_lookup ? MSTDNT_LOOKUP_ACCT : MSTDNT_LOOKUP_ID;
if (mastodont_account(api, MSTDNT_LOOKUP_ACCT, data[0],
&acct, &storage, NULL))
account_page = "Couldn't load account info";
else
if (mastodont_account(api, lookup_type, data[0],
&acct, &storage, NULL) ||
mastodont_account_statuses(api, acct.id, NULL,
&status_storage, &statuses, &status_len))
{
account_page = "Couldn't load account info";
}
else {
cleanup = 1;
account_page = construct_account_page(&acct, NULL);
account_page = construct_account_page(&acct,
statuses,
status_len,
NULL);
if (!account_page)
account_page = "Malloc error";
}
@ -79,5 +104,6 @@ void content_account(mastodont_t* api, char** data, size_t size)
/* Cleanup */
mastodont_storage_cleanup(&storage);
mastodont_storage_cleanup(&status_storage);
if (cleanup) free(account_page);
}

View file

@ -21,7 +21,10 @@
#include <stddef.h>
#include <mastodont.h>
char* construct_account_page(struct mstdnt_account* acct, size_t* res_size);
char* construct_account_page(struct mstdnt_account* acct,
struct mstdnt_status* statuses,
size_t statuses_len,
size_t* res_size);
void content_account(mastodont_t* api, char** data, size_t data_size);
#endif // ACCOUNT_H

View file

@ -41,7 +41,7 @@ void content_index(mastodont_t* api)
{
/* Construct statuses into HTML */
status_format = construct_statuses(statuses, status_count, &statuses_html_count);
if (status_format == NULL)
if (!status_format)
status_format = "Error in malloc!";
cleanup = 1;
}